Expert Advisor MQL4

To add comments, please log in or register
Trader1529
198
Trader1529  
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? 


Renjun Gu
262
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.

Trader1529
198
Trader1529  
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...
nicholi shen
2317
nicholi shen  

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];
   }
}
Trader1529
198
Trader1529  
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
Sergiy Podolyak
3808
Sergiy Podolyak  

HKKY ,

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

Keith Watford
Moderator
15730
Keith Watford  
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.

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

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

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

Sorry for the inconvenience

To add comments, please log in or register