Code compiles but does not open orders

 
Guys, this code compiles normally but does not open commands, the highlighted term, when removed, works normally.

My intention is to buy/sell when the price follows support/resistance and 3 candles later break the high of its predecessors.

Can anyone tell me what is wrong?

#include <Trade\Trade.mqh>

CTrade trade;



input int  takeprofit             = 300; //TAKE PROFIT

input int  stoploss               = 200; //STOP LOSS

input int  passots                = 10;  //PASSO TRAILING STOP

input int  lote                   = 1;   //LOTE

input int  barras                 = 50;  //BARRAS

input int  spreadmax              = 4;

input bool trailingstop           = true; //TRAILING STOP

input bool controltime           = true; //NÃO ABRIR POSIÇÕES FORA DO HORÁRIO DE NEGOCIAÇÃO

input int  horaInicioAbertura     = 00;//Hora de Inicio de Abertura de Posições

input int  minutoInicioAbertura   = 00;//Minuto de Inicio de Abertura de Pisoções

input int  horaFimAbertura        = 12;//Hora de Encerramento de Abertura de Posições

input int  minutoFimAbertura      = 15;//Minuto de Encerramento de Abertura de Posições

input int  horaInicioFechamento   = 13;//Hora de Inicio de Fechamento de Posições

input int  minutoInicioFechamento = 20;//Minuto de Inicio de Fechamento de Posições

MqlDateTime horaAtual;



int OnInit()

  {

  TimeToStruct(TimeCurrent(),horaAtual);

   if(horaInicioAbertura > horaFimAbertura || horaFimAbertura > horaInicioFechamento)

         {  

            Alert("Inconsistência de Horários de Negociação!");

            return(INIT_FAILED);

         }

      if(horaInicioAbertura == horaFimAbertura)

         {

            Alert("Inconsistência de Horários de Negociação!");

            return(INIT_FAILED);

         }

      if(horaFimAbertura == horaInicioFechamento)

         {

            Alert("Inconsistência de Horários de Negociação!");

            return(INIT_FAILED);

         }

  

  return(INIT_SUCCEEDED);}

void OnTick()

  {

int max,min;

double maxi[],mini[];

ArraySetAsSeries(maxi,true);

ArraySetAsSeries(mini,true);

CopyHigh(_Symbol,PERIOD_CURRENT,0,barras,maxi);

CopyLow(_Symbol,PERIOD_CURRENT,0,barras,mini);

max = ArrayMaximum(maxi,0,barras);

min = ArrayMinimum(mini,0,barras);



MqlRates preco[];

ArraySetAsSeries(preco,true);

CopyRates(_Symbol,PERIOD_CURRENT,0,Bars(_Symbol,PERIOD_CURRENT),preco);



//indicador R 

    ObjectCreate(0,"RESISTENCIA", OBJ_HLINE,0,0,preco[max].high);

ObjectSetInteger(0,"RESISTENCIA", OBJPROP_COLOR,clrWhite);

ObjectSetInteger(0,"RESISTENCIA",OBJPROP_WIDTH,1);

      ObjectMove(0,"RESISTENCIA",0,0,preco[max].high);

//indicador S

    ObjectCreate(0,"SUPORTE", OBJ_HLINE,0,0,preco[min].low);

ObjectSetInteger(0,"SUPORTE", OBJPROP_COLOR,clrWhiteSmoke);

ObjectSetInteger(0,"SUPORTE",OBJPROP_WIDTH,1);

      ObjectMove(0,"SUPORTE",0,0,preco[min].low);

      

double ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);

double bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);

double price=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_LAST),_Digits);

      

if((PositionsTotal() < 1) && HoraNegociacao() &&(preco[4].low == preco[min].low)&& (ask>iHigh(_Symbol,PERIOD_CURRENT,3))&& (ask>iHigh(_Symbol,PERIOD_CURRENT,2)) && (ask>iHigh(_Symbol,PERIOD_CURRENT,1)))

trade.Buy(lote,_Symbol,ask,(ask-stoploss*_Point),(ask+takeprofit*_Point),NULL);

if(trailingstop){

CheckTrailingStop(ask);

}

else{

return;}





if((PositionsTotal() < 1) && HoraNegociacao() &&( preco[4].high == preco[max].high) && (bid<iLow(_Symbol,PERIOD_CURRENT,3))&& (bid<iLow(_Symbol,PERIOD_CURRENT,2)) && (bid<iLow(_Symbol,PERIOD_CURRENT,1)))

trade.Sell(lote,_Symbol,bid,(bid+stoploss*_Point),(bid-takeprofit*_Point),NULL);

if(trailingstop){

CheckTrailingStop1(bid);

}

else{

return;}



}



void CheckTrailingStop(double ask)

{

double SL=NormalizeDouble(ask-stoploss*_Point,_Digits);

for(int i=PositionsTotal()-1;i>=0;i--)

{

string symbol=PositionGetSymbol(i);

if (_Symbol==symbol)

  {

ulong PositionTicket=PositionGetInteger(POSITION_TICKET);

double CurrentStopLoss=PositionGetDouble(POSITION_SL);

if (CurrentStopLoss<SL) 

   {

trade.PositionModify(PositionTicket,(CurrentStopLoss+passots*_Point),(ask+takeprofit*_Point));

    }

  }

}



}



void CheckTrailingStop1(double bid)

{

double SL1=NormalizeDouble(bid+stoploss*_Point,_Digits);

for(int i=PositionsTotal()-1;i>=0;i--)

{

string symbol=PositionGetSymbol(i);

if (_Symbol==symbol)

{

ulong PositionTicket=PositionGetInteger(POSITION_TICKET);

double CurrentStopLoss=PositionGetDouble(POSITION_SL);

if (CurrentStopLoss>SL1) 

{

trade.PositionModify(PositionTicket,(CurrentStopLoss-passots*_Point),(bid-takeprofit*_Point));

}

}

}

}



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;

   }