EAs with no compilation erros but are not trading on backtest and live

 

Hi everybody!


I am a beginner on programming. I have created two EAs:


One is based on colors changes provided by the indicator "i-impulsesystem". I have used the iCustom fucntion with no inputs in accordance with the indicator. The EA should buy when candle[2] color is red or grey and candle[1] is green. Bythe other side, EA should sell when candle[2] color is green or grey and candle[1] is red. The EA code is compiling without errors (LDWDO_IMPULSE compilation file attached) but no tradings are performed on backtest (LDWDO_IMPULSE 09192020 test log file attached) and live market.


//+------------------------------------------------------------------+
//|                                                LDWDO_IMPULSE.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

#include <SmoothAlgorithms.mqh> 
#include <GetIndicatorBuffers.mqh> 
#include <Trade\Trade.mqh>
CTrade trade;

MqlRates rates[];
MqlDateTime horaAtual;

input double                  _volume = 1.0;            // Informe a quantidade de lotes.
input ulong                   magicNum = 123456;        //Magic Number
input ulong                   desvPts = 10;             //Desvio em Pontos

input int                     horaInicioAbertura = 09;  //Hora de Inicio de Abertura de Posições
input int                     minutoInicioAbertura = 00;//Minuto de Inicio de Abertura de Pisoções
input int                     horaFimAbertura = 17;     //Hora de Encerramento de Abertura de Posições
input int                     minutoFimAbertura = 15;   //Minuto de Encerramento de Abertura de Posições
input int                     horaInicioFechamento = 17;//Hora de Inicio de Fechamento de Posições
input int                     minutoInicioFechamento = 35;//Minuto de Inicio de Fechamento de Posições


double ColorBuffer[];

int   IMP_Handle;                   // impulse system handle
int calculatp;                   // calculo de take profit


int OnInit(){
   
   IMP_Handle = iCustom(Symbol(),Period(),"Examples\\i-impulsesystem.ex5");

   
   
   ArraySetAsSeries(ColorBuffer, true);
   ArraySetAsSeries(rates, true);

   trade.SetTypeFilling(ORDER_FILLING_IOC);
   trade.SetDeviationInPoints(desvPts);
   trade.SetExpertMagicNumber(magicNum);

 if(horaInicioAbertura > horaFimAbertura || horaFimAbertura > horaInicioFechamento)
         {  
            Alert("Inconsistência de Horários de Negociação!");
            return(INIT_FAILED);
         }
      if(horaInicioAbertura == horaFimAbertura && minutoInicioAbertura >= minutoFimAbertura)
         {
            Alert("Inconsistência de Horários de Negociação!");
            return(INIT_FAILED);
         }
      if(horaFimAbertura == horaInicioFechamento && minutoFimAbertura >= minutoInicioFechamento)
         {
            Alert("Inconsistência de Horários de Negociação!");
            return(INIT_FAILED);
         }


   return(INIT_SUCCEEDED);
}

void OnTick(){

 if(HoraFechamento())
         {
            Comment("Horário de Fechamento de Posições!");
            FechaPosicao();
         }
      else if(HoraNegociacao())
         {
            Comment("Dentro do Horário de Negociação!");
         }
      else
         {
            Comment("Fora do Horário de Negociação!");
            DeletaOrdens();
         }



if(isNewBar())
     {
   
   CopyBuffer(IMP_Handle, 0, 0, 3, ColorBuffer);
   CopyRates(Symbol(), Period(), 0, 3, rates);

      
      
   if((ColorBuffer[2]==2 && ColorBuffer[1]==0) || (ColorBuffer[2]==1 && ColorBuffer[1]==0)){      //---
      //ObjectCreate(0, rates[1].time, OBJ_ARROW_CHECK, 0, rates[1].time, rates[1].low);
      
      if(HoraNegociacao() == true && PositionsTotal() == 0 && OrdersTotal() == 0){
         double Ask=NormalizeDouble(SymbolInfoDouble(Symbol(),SYMBOL_ASK),_Digits);
         trade.Buy(_volume, Symbol(), 0, Ask - 4000 *_Point,Ask + 8000 *_Point, "Compra");{
         }
      }

   }
   
   
   if((ColorBuffer[2]==2 && ColorBuffer[1]==1) || (ColorBuffer[2]==0 && ColorBuffer[1]==1)){    //---
      //ObjectCreate(0, rates[1].time, OBJ_ARROW_CHECK, 0, rates[1].time, rates[1].high);
      
        if(HoraNegociacao() == true && PositionsTotal() == 0 && OrdersTotal() == 0){
        double Bid=NormalizeDouble(SymbolInfoDouble(Symbol(),SYMBOL_BID),_Digits);
             trade.Sell(_volume, Symbol(),0, Bid + 4000 *_Point, Bid - 8000 *_Point, "Venda");{
         }
      }
      
   }
  
}

}

//+------------------------------------------------------------------+




//+------------------------------------------------------------------+
bool isNewBar()
  {
//--- memorize the time of opening of the last bar in the static variable
   static datetime last_time=0;
//--- current time
   datetime lastbar_time=(datetime)SeriesInfoInteger(Symbol(),Period(),SERIES_LASTBAR_DATE);

//--- if it is the first call of the function
   if(last_time==0)
     {
      //--- set the time and exit
      last_time=lastbar_time;
      return(false);
     }

//--- if the time differs
   if(last_time!=lastbar_time)
     {
      //--- memorize the time and return true
      last_time=lastbar_time;
      return(true);
     }
//--- if we passed to this line, then the bar is not new; return false
   return(false);
  }

//+------------------------------------------------------------------+

bool HoraFechamento()
   {
      TimeToStruct(TimeCurrent(), horaAtual);
      if(horaAtual.hour >= horaInicioFechamento)
         {
            if(horaAtual.hour == horaInicioFechamento)
               {
                  if(horaAtual.min >= minutoInicioFechamento)
                     {
                        return true;
                     }
                  else
                     {
                        return false;
                     }
               }
            return true;
         }
      return false;
   }
//+------------------------------------------------------------------+
bool HoraNegociacao()
   {
      TimeToStruct(TimeCurrent(), horaAtual);
      if(horaAtual.hour >= horaInicioAbertura && horaAtual.hour <= horaFimAbertura)
         {
            if(horaAtual.hour == horaInicioAbertura)
               {
                  if(horaAtual.min >= minutoInicioAbertura)
                     {
                        return true;
                     }
                  else
                     {
                        return false;
                     }
               }
            if(horaAtual.hour == horaFimAbertura)
               {
                  if(horaAtual.min <= minutoFimAbertura)
                     {
                        return true;
                     }
                  else
                     {
                        return false;
                     }
               }
            return true;
         }
      return false;
   }
   
//+------------------------------------------------------------------+
void FechaPosicao()
   {
      for(int i = PositionsTotal()-1; i>=0; i--)
         {
            string symbol = PositionGetSymbol(i);
            ulong magic = PositionGetInteger(POSITION_MAGIC);
            if(symbol == _Symbol && magic == magicNum)
               {
                  ulong PositionTicket = PositionGetInteger(POSITION_TICKET);
                  if(trade.PositionClose(PositionTicket, desvPts))
                     {
                        Print("Posição Fechada - sem falha. ResultRetcode: ", trade.ResultRetcode(), ", RetcodeDescription: ", trade.ResultRetcodeDescription());
                     }
                  else
                     {
                        Print("Posição Fechada - com falha. ResultRetcode: ", trade.ResultRetcode(), ", RetcodeDescription: ", trade.ResultRetcodeDescription());
                     }
               }
         }
   }
   
 //+------------------------------------------------------------------+
void DeletaOrdens ()
   {
      for(int i = OrdersTotal()-1; i>=0; i--)
         {
            string symbol = OrderGetString(ORDER_SYMBOL);
            ulong ticket = OrderGetTicket(i);
            ulong magic = OrderGetInteger(ORDER_MAGIC);
            if(symbol == _Symbol && magic == magicNum)
               {
                  if (trade.OrderDelete(ticket))
                      {
                       Print("Ordem Deletada - sem falha. ResultRetcode: ", trade.ResultRetcode(), ", RetcodeDescription: ", trade.ResultRetcodeDescription());
                      }
                  else
                      {
                       Print("Ordem Deletada - com falha. ResultRetcode: ", trade.ResultRetcode(), ", RetcodeDescription: ", trade.ResultRetcodeDescription());
                      }
               }
         }
   }


The other EA is based on UP and DOWN buffers crossing over provided by the indicator "UDP".  The EA should buy when candle[2] UP =0 and DOWN =1 and candle[1] UP =1 and DOWN =0.  Bythe other side, EA should sell when candle[2] UP =1 and DOWN =0 and candle[1] UP =0 and DOWN =1. The EA code is compiling without errors (LDWIN_UDP compilation file attached) but no tradings are performed on backtest (LDWIN_UDP 09192020 test log file attached), I have not tried it on live market yet.


//+------------------------------------------------------------------+
//|                                                    LDWIN_UDP.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

#include <SmoothAlgorithms.mqh> 
#include <Trade\Trade.mqh>
CTrade trade;

MqlRates rates[];
MqlDateTime horaAtual;

input double                  _volume = 1.0;            // Informe a quantidade de lotes.
input ulong                   desvPts = 10;             //Desvio em Pontos
input ulong                   magicNum = 123456;        //Magic Number
input int                     horaInicioAbertura = 09;  //Hora de Inicio de Abertura de Posições
input int                     minutoInicioAbertura = 00;//Minuto de Inicio de Abertura de Pisoções
input int                     horaFimAbertura = 17;     //Hora de Encerramento de Abertura de Posições
input int                     minutoFimAbertura = 15;   //Minuto de Encerramento de Abertura de Posições
input int                     horaInicioFechamento = 17;//Hora de Inicio de Fechamento de Posições
input int                     minutoInicioFechamento = 35;//Minuto de Inicio de Fechamento de Posições
//+------------------------------------------------------------------+
//Inputs do indicador Bulls Bears Eyes
//+------------------------------------------------------------------+
input uint                 InpPeriod         =  14;            // Period
input ENUM_APPLIED_PRICE   InpAppliedPrice   =  PRICE_CLOSE;   // Applied price 

#include <GetIndicatorBuffers.mqh> 
double         BufferUP[];
double         BufferDN[];

int   UDP_Handle;                   // change of volatility
int calculatp;                   // calculo de take profit

int OnInit(){
   
   UDP_Handle = iCustom(Symbol(),Period(),"Examples\\UDP.ex5",InpPeriod,InpAppliedPrice);

   
   
   ArraySetAsSeries(BufferUP, true);
   ArraySetAsSeries(BufferDN, true);
   ArraySetAsSeries(rates, true);

   trade.SetTypeFilling(ORDER_FILLING_IOC);
   trade.SetDeviationInPoints(desvPts);
   trade.SetExpertMagicNumber(magicNum);

 if(horaInicioAbertura > horaFimAbertura || horaFimAbertura > horaInicioFechamento)
         {  
            Alert("Inconsistência de Horários de Negociação!");
            return(INIT_FAILED);
         }
      if(horaInicioAbertura == horaFimAbertura && minutoInicioAbertura >= minutoFimAbertura)
         {
            Alert("Inconsistência de Horários de Negociação!");
            return(INIT_FAILED);
         }
      if(horaFimAbertura == horaInicioFechamento && minutoFimAbertura >= minutoInicioFechamento)
         {
            Alert("Inconsistência de Horários de Negociação!");
            return(INIT_FAILED);
         }


   return(INIT_SUCCEEDED);
}

void OnTick(){

 if(HoraFechamento())
         {
            Comment("Horário de Fechamento de Posições!");
            FechaPosicao();
         }
      else if(HoraNegociacao())
         {
            Comment("Dentro do Horário de Negociação!");
         }
      else
         {
            Comment("Fora do Horário de Negociação!");
            DeletaOrdens();
         }



if(isNewBar())
     {
   
   CopyBuffer(UDP_Handle, 0, 0, 3, BufferUP);
   CopyBuffer(UDP_Handle, 1, 0, 3, BufferDN);
   CopyRates(Symbol(), Period(), 0, 3, rates);

      
      
   if(BufferUP[2]==0 && BufferDN[2]==1 && BufferUP[1]==1 && BufferDN[1]==0){      //---
      //ObjectCreate(0, rates[1].time, OBJ_ARROW_CHECK, 0, rates[1].time, rates[1].low);
      
      if(HoraNegociacao() == true && PositionsTotal() == 0 && OrdersTotal() == 0){
         double Ask=NormalizeDouble(SymbolInfoDouble(Symbol(),SYMBOL_ASK),_Digits);
         trade.Buy(_volume, Symbol(), 0, Ask - 100 *_Point,Ask + 50 *_Point, "Compra");{
         }
      }

   }
  
   
   if(BufferUP[2]==1 && BufferDN[2]==0 && BufferUP[1]==0 && BufferDN[1]==1){    //---
      //ObjectCreate(0, rates[1].time, OBJ_ARROW_CHECK, 0, rates[1].time, rates[1].high);
      
        if(HoraNegociacao() == true && PositionsTotal() == 0 && OrdersTotal() == 0){
        double Bid=NormalizeDouble(SymbolInfoDouble(Symbol(),SYMBOL_BID),_Digits);
             trade.Sell(_volume, Symbol(),0, Bid + 100 *_Point, Bid - 50 *_Point, "Venda");{
         }
      }
      
   }


}

}

//+------------------------------------------------------------------+




//+------------------------------------------------------------------+
bool isNewBar()
  {
//--- memorize the time of opening of the last bar in the static variable
   static datetime last_time=0;
//--- current time
   datetime lastbar_time=(datetime)SeriesInfoInteger(Symbol(),Period(),SERIES_LASTBAR_DATE);

//--- if it is the first call of the function
   if(last_time==0)
     {
      //--- set the time and exit
      last_time=lastbar_time;
      return(false);
     }

//--- if the time differs
   if(last_time!=lastbar_time)
     {
      //--- memorize the time and return true
      last_time=lastbar_time;
      return(true);
     }
//--- if we passed to this line, then the bar is not new; return false
   return(false);
  }

//+------------------------------------------------------------------+

bool HoraFechamento()
   {
      TimeToStruct(TimeCurrent(), horaAtual);
      if(horaAtual.hour >= horaInicioFechamento)
         {
            if(horaAtual.hour == horaInicioFechamento)
               {
                  if(horaAtual.min >= minutoInicioFechamento)
                     {
                        return true;
                     }
                  else
                     {
                        return false;
                     }
               }
            return true;
         }
      return false;
   }
//+------------------------------------------------------------------+
bool HoraNegociacao()
   {
      TimeToStruct(TimeCurrent(), horaAtual);
      if(horaAtual.hour >= horaInicioAbertura && horaAtual.hour <= horaFimAbertura)
         {
            if(horaAtual.hour == horaInicioAbertura)
               {
                  if(horaAtual.min >= minutoInicioAbertura)
                     {
                        return true;
                     }
                  else
                     {
                        return false;
                     }
               }
            if(horaAtual.hour == horaFimAbertura)
               {
                  if(horaAtual.min <= minutoFimAbertura)
                     {
                        return true;
                     }
                  else
                     {
                        return false;
                     }
               }
            return true;
         }
      return false;
   }
   
//+------------------------------------------------------------------+
void FechaPosicao()
   {
      for(int i = PositionsTotal()-1; i>=0; i--)
         {
            string symbol = PositionGetSymbol(i);
            ulong magic = PositionGetInteger(POSITION_MAGIC);
            if(symbol == _Symbol && magic == magicNum)
               {
                  ulong PositionTicket = PositionGetInteger(POSITION_TICKET);
                  if(trade.PositionClose(PositionTicket, desvPts))
                     {
                        Print("Posição Fechada - sem falha. ResultRetcode: ", trade.ResultRetcode(), ", RetcodeDescription: ", trade.ResultRetcodeDescription());
                     }
                  else
                     {
                        Print("Posição Fechada - com falha. ResultRetcode: ", trade.ResultRetcode(), ", RetcodeDescription: ", trade.ResultRetcodeDescription());
                     }
               }
         }
   }
   
 //+------------------------------------------------------------------+
void DeletaOrdens ()
   {
      for(int i = OrdersTotal()-1; i>=0; i--)
         {
            string symbol = OrderGetString(ORDER_SYMBOL);
            ulong ticket = OrderGetTicket(i);
            ulong magic = OrderGetInteger(ORDER_MAGIC);
            if(symbol == _Symbol && magic == magicNum)
               {
                  if (trade.OrderDelete(ticket))
                      {
                       Print("Ordem Deletada - sem falha. ResultRetcode: ", trade.ResultRetcode(), ", RetcodeDescription: ", trade.ResultRetcodeDescription());
                      }
                  else
                      {
                       Print("Ordem Deletada - com falha. ResultRetcode: ", trade.ResultRetcode(), ", RetcodeDescription: ", trade.ResultRetcodeDescription());
                      }
               }
         }
   }


I appreciate should you help me out to fix these issues. I have created EAs with iCustom before and they ran allright. But somehow I am not figuring out how to deal with the buffers on both indicators herein.


Thanks!

 
If you want help, attach the mql5 file of the advisor and the mql5 file of the indicator. What you attached above does not fit.
 
Vladimir Karputov:
If you want help, attach the mql5 file of the advisor and the mql5 file of the indicator. What you attached above does not fit.

Indicators were attached on initial mensage. However I have attached them again. EAs files attached now.

Files:
 

Errors in the 'LDWIN_UDP' advisor - you are trying to compare non-existent values of the 'UDP' indicator.

For example, the 'UDP' indicator gives fractional values

and you in the advisor, for some reason, expect the values '0' and '1'

      if(BufferUP[2]==0 && BufferDN[2]==1 && BufferUP[1]==1 && BufferDN[1]==0)       //---
        {
         //ObjectCreate(0, rates[1].time, OBJ_ARROW_CHECK, 0, rates[1].time, rates[1].low);
         if(HoraNegociacao() == true && PositionsTotal() == 0 && OrdersTotal() == 0)
           {
            double Ask=NormalizeDouble(SymbolInfoDouble(Symbol(),SYMBOL_ASK),_Digits);
            trade.Buy(_volume, Symbol(), 0, Ask - 100 *_Point,Ask + 50 *_Point, "Compra");
              {
              }
           }
        }
      if(BufferUP[2]==1 && BufferDN[2]==0 && BufferUP[1]==0 && BufferDN[1]==1)     //---
        {
         //ObjectCreate(0, rates[1].time, OBJ_ARROW_CHECK, 0, rates[1].time, rates[1].high);
         if(HoraNegociacao() == true && PositionsTotal() == 0 && OrdersTotal() == 0)
           {
            double Bid=NormalizeDouble(SymbolInfoDouble(Symbol(),SYMBOL_BID),_Digits);
            trade.Sell(_volume, Symbol(),0, Bid + 100 *_Point, Bid - 50 *_Point, "Venda");
              {
              }
           }
        }


I didn't look further - you need to fix this error.

 
Vladimir Karputov:

Errors in the 'LDWIN_UDP' advisor - you are trying to compare non-existent values of the 'UDP' indicator.

For example, the 'UDP' indicator gives fractional values

and you in the advisor, for some reason, expect the values '0' and '1'


I didn't look further - you need to fix this error.

Thanks  Vladimir.

The values  '0' and '1' were related to the indicators range on the Symbol which EAs was created for. Based on your comment I have fixed EA as below but it is still not trading.

   if(BufferUP[2]<=BufferDN[2] && BufferUP[1]>BufferDN[1]){      //---
      //ObjectCreate(0, rates[1].time, OBJ_ARROW_CHECK, 0, rates[1].time, rates[1].low);
      
      if(HoraNegociacao() == true && PositionsTotal() == 0 && OrdersTotal() == 0){
         double Ask=NormalizeDouble(SymbolInfoDouble(Symbol(),SYMBOL_ASK),_Digits);
         trade.Buy(_volume, Symbol(), 0, Ask - 100 *_Point,Ask + 50 *_Point, "Compra");{
         }
      }

   }
  
   
   if(BufferUP[2]>=BufferDN[2] && BufferUP[1]<BufferDN[1]){    //---
      //ObjectCreate(0, rates[1].time, OBJ_ARROW_CHECK, 0, rates[1].time, rates[1].high);
      
        if(HoraNegociacao() == true && PositionsTotal() == 0 && OrdersTotal() == 0){
        double Bid=NormalizeDouble(SymbolInfoDouble(Symbol(),SYMBOL_BID),_Digits);
             trade.Sell(_volume, Symbol(),0, Bid + 100 *_Point, Bid - 50 *_Point, "Venda");{
         }
      }
      
   }
Files:
LDWIN_UDP.mq5  18 kb
 
ZURC TRADER :

Thanks  Vladimir.

The values  ' 0 ' and ' 1 ' were related to the indicators range on the Symbol which EAs was created for. Based on your comment I have fixed EA as below but it is still not trading.

Your settings are incompatible with trading. I removed the time limit and dropped the mention of PENDED orders. Added print output if trade order is unsuccessful.

   if(isNewBar())
     {
      CopyBuffer(UDP_Handle, 0, 0, 3, BufferUP);
      CopyBuffer(UDP_Handle, 1, 0, 3, BufferDN);
      CopyRates(Symbol(), Period(), 0, 3, rates);
      if(BufferUP[2]<=BufferDN[2] && BufferUP[1]>BufferDN[1])       //---
        {
         //ObjectCreate(0, rates[1].time, OBJ_ARROW_CHECK, 0, rates[1].time, rates[1].low);
         if(/*HoraNegociacao() == true && */PositionsTotal() == 0 /*&& OrdersTotal() == 0*/)
           {
            double Ask=NormalizeDouble(SymbolInfoDouble(Symbol(),SYMBOL_ASK),_Digits);
            if(!m_trade.Buy(_volume, Symbol(), 0, Ask - 100 *_Point,Ask + 50 *_Point, "Compra"))
               Print(__FILE__," ",__FUNCTION__,", ERROR: ","#3 BUY -> false. Result Retcode: ",m_trade.ResultRetcode(),
                     ", description of result: ",m_trade.ResultRetcodeDescription());
           }
        }
      if(BufferUP[2]>=BufferDN[2] && BufferUP[1]<BufferDN[1])     //---
        {
         //ObjectCreate(0, rates[1].time, OBJ_ARROW_CHECK, 0, rates[1].time, rates[1].high);
         if(/*HoraNegociacao() == true && */PositionsTotal() == 0 /*&& OrdersTotal() == 0*/)
           {
            double Bid=NormalizeDouble(SymbolInfoDouble(Symbol(),SYMBOL_BID),_Digits);
            if(!m_trade.Sell(_volume, Symbol(),0, Bid + 100 *_Point, Bid - 50 *_Point, "Venda"))
               Print(__FILE__," ",__FUNCTION__,", ERROR: ","#3 Sell -> false. Result Retcode: ",m_trade.ResultRetcode(),
                     ", description of result: ",m_trade.ResultRetcodeDescription());
           }
        }
     }
 
Vladimir Karputov:

Your settings are incompatible with trading. I removed the time limit and dropped the mention of PENDED orders. Added print output if trade order is unsuccessful.

I had to change the "m_trades.*" from your code to  "trades.*" in order to fit the "CTrade trade". By adding your code the EA did not compile. Even with the changes EA is still not trading.


if(isNewBar())
     {
      CopyBuffer(UDP_Handle, 0, 0, 3, BufferUP);
      CopyBuffer(UDP_Handle, 1, 0, 3, BufferDN);
      CopyRates(Symbol(), Period(), 0, 3, rates);
      if(BufferUP[2]<=BufferDN[2] && BufferUP[1]>BufferDN[1])       //---
        {
         //ObjectCreate(0, rates[1].time, OBJ_ARROW_CHECK, 0, rates[1].time, rates[1].low);
         if(/*HoraNegociacao() == true && */PositionsTotal() == 0 /*&& OrdersTotal() == 0*/)
           {
            double Ask=NormalizeDouble(SymbolInfoDouble(Symbol(),SYMBOL_ASK),_Digits);
            if(!trade.Buy(_volume, Symbol(), 0, Ask - 100 *_Point,Ask + 50 *_Point, "Compra"))
               Print(__FILE__," ",__FUNCTION__,", ERROR: ","#3 BUY -> false. Result Retcode: ",trade.ResultRetcode(),
                     ", description of result: ",trade.ResultRetcodeDescription());
           }
        }
      if(BufferUP[2]>=BufferDN[2] && BufferUP[1]<BufferDN[1])     //---
        {
         //ObjectCreate(0, rates[1].time, OBJ_ARROW_CHECK, 0, rates[1].time, rates[1].high);
         if(/*HoraNegociacao() == true && */PositionsTotal() == 0 /*&& OrdersTotal() == 0*/)
           {
            double Bid=NormalizeDouble(SymbolInfoDouble(Symbol(),SYMBOL_BID),_Digits);
            if(!trade.Sell(_volume, Symbol(),0, Bid + 100 *_Point, Bid - 50 *_Point, "Venda"))
               Print(__FILE__," ",__FUNCTION__,", ERROR: ","#3 Sell -> false. Result Retcode: ",trade.ResultRetcode(),
                     ", description of result: ",trade.ResultRetcodeDescription());
           }
        }
     }
Files:
LDWIN_UDP.mq5  19 kb
Reason: