ola a todos

 
Rodrigo Pereiraestou tentando desenvolver um robo, com a entrada sendo feita quando o candle é fechado, mas nao estou conseguindo , sou iniciante...gostaria de saber se alguem pode me ajudar.


Olá, segue um exemplo da documentação (OnTick - Manipulação de eventos - Referência MQL5 - Referência sobre algorítimo/automatização de negociação na linguagem para MetaTrader 5):

//+------------------------------------------------------------------+
//|  Retornando true quando aparece uma nova barra                   |
//+------------------------------------------------------------------+
bool isNewBar(const bool print_log=true)
  {
   static datetime bartime=0; // armazenamos o tempo de abertura da barra atual
//--- obtemos o tempo de abertura da barra zero
   datetime currbar_time=iTime(_Symbol,_Period,0);
//--- se o tempo de abertura mudar, é porque apareceu uma nova barra
   if(bartime!=currbar_time)
     {
      bartime=currbar_time;
      lastbar_timeopen=bartime;
      //--- exibir no log informações sobre o tempo de abertura da nova barra      
      if(print_log && !(MQLInfoInteger(MQL_OPTIMIZATION)||MQLInfoInteger(MQL_TESTER)))
        {
         //--- exibimos uma mensagem sobre o tempo de abertura da nova barra
         PrintFormat("%s: new bar on %s %s opened at %s",__FUNCTION__,_Symbol,
                     StringSubstr(EnumToString(_Period),7),
                     TimeToString(TimeCurrent(),TIME_SECONDS));
         //--- obtemos os dados do último tick
         MqlTick last_tick;
         if(!SymbolInfoTick(Symbol(),last_tick))
            Print("SymbolInfoTick() failed, error = ",GetLastError());
         //--- exibimos o tempo do último tick em segundos
         PrintFormat("Last tick was at %s.%03d",
                     TimeToString(last_tick.time,TIME_SECONDS),last_tick.time_msc%1000);
        }
      //--- temos uma nova barra
      return (true);
     }
//--- não há nenhuma barra nova
   return (false);
  }


Exemplo da Base de Código:

Free download of the 'Detecting the start of a new bar or candle' expert by 'FMIC' for MetaTrader 5 in the MQL5 Code Base, 2022.04.24


Se estiver utilizando MetaTrader 4:

Free download of the 'Detecting the start of a new bar or candle' expert by 'FMIC' for MetaTrader 4 in the MQL5 Code Base, 2022.04.24

 
MUITO OBRIGADO
 
Rodrigo Pereira #MUITO OBRIGADO


De nada. 👍