78 righe
6 KiB
MQL5
78 righe
6 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| MAsimples.mq5 |
|
|
//| Copyright 2025, MetaQuotes Ltd. |
|
|
//| https://www.mql5.com |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2025, MetaQuotes Ltd."
|
|
#property link "https://www.mql5.com"
|
|
#property version "1.00"
|
|
|
|
#property strict
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
|
|
#include "acm_common.mqh"
|
|
|
|
double atr = 0.0;
|
|
double media = 0.0;
|
|
double mediaAtr = 0.0;
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Expert initialization function |
|
|
//+------------------------------------------------------------------+
|
|
int OnInit()
|
|
{
|
|
SetChartProperties();
|
|
// ArraySetAsSeries(dMA, true);
|
|
EventSetTimer(1); // Definir o timer para 5 segundos
|
|
return (INIT_SUCCEEDED);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Expert deinitialization function |
|
|
|
|
//+------------------------------------------------------------------+
|
|
void OnDeinit(const int reason)
|
|
{
|
|
Comment("");
|
|
Print("Finalizando - ", MQL5InfoString(MQL5_PROGRAM_NAME));
|
|
EventKillTimer();
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Expert tick function |
|
|
//+------------------------------------------------------------------+
|
|
void OnTick()
|
|
{
|
|
// Comment("Preço da MA[0]: ", dMA[0], "\nPreço da MA[1]: ", dMA[1], "\nPreço da MA[2]: ", dMA[2]);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
void OnTimer()
|
|
{
|
|
media = Media();
|
|
atr = Atr();
|
|
mediaAtr = nAtr();
|
|
Comment("Preço da MA[0]: ", media, "\nPreço da Atr[0]: ", atr, "\nPreço da MediaAtr[0]: ", mediaAtr, "\n\nPressione 'X' para remover o EA do gráfico.");
|
|
ChartRedraw();
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| ChartEvent function |
|
|
//+------------------------------------------------------------------+
|
|
void OnChartEvent(const int id, // Event identifier
|
|
const long &lparam, // Event parameter of long type
|
|
const double &dparam, // Event parameter of double type
|
|
const string &sparam) // Event parameter of string type
|
|
{
|
|
if (id == CHARTEVENT_KEYDOWN)
|
|
{
|
|
// Fechar todas as ordens abertas e remover o EA do gráfico
|
|
if ((char)lparam == 'x' || (char)lparam == 'X')
|
|
{
|
|
ExpertRemove();
|
|
}
|
|
}
|
|
}
|