Expert Advisor MQL4

 
Good morning everyone,

I wrote an expert Advisor in mql4 format which open position at certain time of the day, it calculate number of lots, take profit and stop loss.

Now I want to change it because it doesn’t work very well and I want that it open position when the candlestick start (in the timeframe I set). For example, I set the timeframe M5, every 5 minutes (when the candle starts) it opens my position, but I don’t know the function to write it.

Can someone please help me? 


 

int OnInit()

  {

   EventSetTimer(300);//300second

   return(INIT_SUCCEEDED);

  }

void OnDeinit(const int reason)

  {

   EventKillTimer()

  }

void OnTimer()

{

}

void OnTick()

  {

  }

//Now execute the code you run in OnTimer(), it will be executed every 5min.

 
Renjun Gu:

int OnInit()

  {

   EventSetTimer(300);//300second

   return(INIT_SUCCEEDED);

  }

void OnDeinit(const int reason)

  {

   EventKillTimer()

  }

void OnTimer()

{

}

void OnTick()

  {

  }

//Now execute the code you run in OnTimer(), it will be executed every 5min.

Thank you, but this function will execute every 300 seconds from when I start the autotrading, but I need to execute every 5 minutes of clock, that means, if I activate autotrading at 09:04, from 09:05 every 5 minutes it opens position, if I start autotrading at 10:16, from 10:20 it will open position every 5 minutes. I don’t know if I explained well what I need...
 

You can track the opening of a new bar using a static variable and the bar time. 


void OnTick()
{
   static datetime last_trade = 0;
   if (last_trade == 0)
      last_trade = Time[0];
   else if (last_trade != Time[0]) {
      int ticket = OrderSend(_Symbol, OP_BUY, 0.01, Ask, 0, 0.0, 0.0);
      if (ticket >= 0)
         last_trade = Time[0];
   }
}
 
nicholi shen:

You can track the opening of a new bar using a static variable and the bar time. 


Ok, I will try it... Thank you
 

HKKY ,

Put your adviser here, otherwise it is impossible to help.

 
Sergiy Podolyak:

HKKY ,

Put your adviser here, otherwise it is impossible to help.

Please only post in English in this forum.

I have used the site's translation tool to edit your post.

 
My mt4 app on android has been loading charts for the past two day...i cant find charts please help
 
Кит Уотфорд:

Пожалуйста, отправляйте сообщения только на английском языке на этом форуме.

Я использовал инструмент перевода сайта для редактирования вашего поста.

Sorry for the inconvenience