Download MetaTrader 5

order candel

To add comments, please log in or register
ea_mt4
50
ea_mt4  
hello, how can I say of the Expert no enter  on the same candle if you take profit or stoploss?

if(OrderOpenTime() > Time[0]) return(0);
if(OrderCloseTime()> Time[0]) return(0); 
if(!IsTradeAllowed())

if it is incorrect, how can I write ?
honest_knave
Moderator
2342
honest_knave  

Function:

datetime GetLastOrder()
  {
   datetime last_order = 0;
   for(int i=OrdersHistoryTotal()-1; i>=0; i--)
     {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue;
      if(OrderSymbol()!=_Symbol) continue;
      // if(OrderMagicNumber() != magic_no) continue;
      if(OrderType()>1) continue;
      datetime close_time = OrderCloseTime();
      if(close_time>last_order) last_order=close_time;
     }
   return(last_order);
  }

Call: 

   if(GetLastOrder() >= Time[0]) return;
whroeder1
17084
whroeder1  
or just remember when
static datetime lastBarOpened=0;
if(Time[0] != lastBarOpened
&& tbdOpenNowCondition
){
   int ticket = OrderSend( ... );
   if(ticket < 0) ...
   else lastBarOpened = Time[0];
}
To add comments, please log in or register