Open Candlestick each timeframe=2 minutes ?

 

I've done with a lot of difficulties (I'm completely a beginner) the following code, but the order is opening every tick (I've used MqlTick).

Is there a possibility to use another command to check every candlsestick closure ?

Thanks


//--- Open Buy Order
   if(RSI_Scalping_1[0] != 0 && RSI_Scalping_1[0] != EMPTY_VALUE) //RSI_Scalping is not equal to fixed value
     {
      MqlTick last_tick;
      SymbolInfoTick(Symbol(), last_tick);
      price = last_tick.ask;
      SL = 8 * myPoint; //Stop Loss = value in points (relative to price)
      if(!inTimeInterval(TimeCurrent(), TOD_From_Hour, TOD_From_Min, TOD_To_Hour, TOD_To_Min))
         return; //open trades only at specific times of the day
      if(!TradeDayOfWeek())
         return; //open trades only on specific days of the week
      if(TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) && MQLInfoInteger(MQL_TRADE_ALLOWED))
        {
         ticket = myOrderSend(ORDER_TYPE_BUY, price, TradeSize, "");
         if(ticket == 0)
            return;
        }
      else //not autotrading => only send alert
         myAlert("order", "");
      myOrderModifyRel(ORDER_TYPE_BUY, ticket, SL, 0);
     }
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Order Properties - Trade Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Luca Motta: use another command to check every candlsestick closure ?
You can't know when a candle closes. Only when a new tick arrives that starts a new bar is the old bar closed.

For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart), volume is unreliable (miss ticks), Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
          New candle - MQL4 programming forum #3 2014.04.04

I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
          Running EA once at the start of each bar - MQL4 programming forum 2011.05.06