Order Entry at Candle Open Bar

 

Hi,

I have tried this code but I seems to get errors:


static datetime oldTime;


void OnTick()
{

if(oldTime != Time[0])
      {
      m_Trade.Buy(lot_size,_Symbol,Ask,(Ask-300*_Point),(Ask+500*_Point),NULL);
      oldTime = Time[0];
      }


}
'Time' - undeclared identifier  
1 error(s), 0 warning(s)               
I want my EA to only put new entry at the next open candle bar. Do note when click on the error, it refers to the Time[0] inside the if(...) function
if(oldTime != Time[0])


 
Aliff102:

Hi,

I have tried this code but I seems to get errors:


I want my EA to only put new entry at the next open candle bar. Do note when click on the error, it refers to the Time[0] inside the if(...) function


Have you tried this?

void OnTick()
{
static datetime oldTime;
if(oldTime != Time[0])
      {
      m_Trade.Buy(lot_size,_Symbol,Ask,(Ask-300*_Point),(Ask+500*_Point),NULL);
      oldTime = Time[0];
      }
}
 

I have solved it by made some changes to the code:


datetime oldTime;

void OnTick()
{
 if(oldTime!=iTime(Symbol(),_Period,0))
      {
      m_Trade.Buy(lot_size,_Symbol,Ask,(Ask-300*_Point),(Ask+500*_Point),NULL);
      oldTime=iTime(Symbol(),_Period,0);
      }
}


Forgot to mention I am using MQL5.