What's wrong with my code?I need help

 

  if (rt[0].close>=iHigh(_Symbol,0,H))
      {
      if (m_position.Select(_Symbol))
       m_trade.PositionClose(_Symbol);
        
      else //if(OrdersTotal()==0)
      m_trade.PositionOpen(_Symbol,ORDER_TYPE_BUY,Lots,SYMBOL_BID,0,0,"Buy"); 
   }


Error:'if'-Semicolon expexted

 
SQ_spirit:

  if (rt[0].close>=iHigh(_Symbol,0,H))
      {
      if (m_position.Select(_Symbol))
       m_trade.PositionClose(_Symbol);
        
      else //if(OrdersTotal()==0)
      m_trade.PositionOpen(_Symbol, ORDER_TYPE_BUY,Lots,SYMBOL_BID,0,0,"Buy"); 
   }


Error:'if'-Semicolon expexted

What do you have before the first 'if'?

 
Seng Joo Thio:

What do you have before the first 'if'?

void OnTick()
  {
//---
   MqlRates rt[];
//--- go trading only for first ticks of new bar
   if(CopyRates(_Symbol,_Period,0,2,rt)!=2)
     {
      Print("CopyRates of ",_Symbol," failed, no history");
      return;
     }
   if(rt[1].tick_volume>1)
      return;
   


I wrote this

 

Forum on trading, automated trading systems and testing trading strategies


When you post code please use the CODE button (Alt-S)!

Use the CODE button

 
SQ_spirit:

I wrote this

Scroll up your Errors tab, what else do you see before "Error:'if'-Semicolon expexted"?

 
Seng Joo Thio:

Scroll up your Errors tab, what else do you see before "Error:'if'-Semicolon expexted"?

Oooops    I forgot an ;
 
 if (rt[0].close>=iHigh(_Symbol,0,H))
      {
      if (m_position.Select(_Symbol)) { m_trade.PositionClose(_Symbol); }
      else { m_trade.PositionOpen(_Symbol,ORDER_TYPE_BUY,Lots,SYMBOL_BID,0,0,"Buy"); }
   }

*it's no a shame to use { }* if you don't feel comfortable with indentation

 
Icham Aidibe:

*it's no a shame to use { }* if you don't feel comfortable with indentation

Yes,thanks
Reason: