Good morning,
I'm writing an Expert Advisor for MT4, but I need to open the order at the closure of the candle and not immediately when the condition meet. There is a function to do it? Or how I can write it? Can someone please help me?
What I wrote it sends the order immediately when the condition are satisfied, but how can I modify it to send the oreder at the closure of the candle?
I didn't read your codes, but it is the answer for what you asked.
You can't get the exact closure of the bar, but you can check for opening of the next bar.
Therefor you need to check your conditions based on the bar 1 and not the bar 0 which is the current bar.
define a variable in the global area (after your externs/inputs and before OnInit() )
datetime newBar=0;// 0 means 1970,01,01 00:00:00
then in the OnTick ()
if(newBar <Time[0]) { //check for your condition in the bar 1 and open the trade if your conditions are satisfied. //at the bottom of OnTick: newBar=Time[0]; }
You may need to change it sometimes .
if(newBar <Time[0])Don't use less than, use not equals. A clock mis-set and then corrected could stop your EA indeterminately. (Happened 8 years ago.)
Don't use less than, use not equals. A clock mis-set and then corrected could stop your EA indeterminately. (Happened 8 years ago.)
Thanks a lot William Roeder
Perfect !
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Good morning,
I'm writing an Expert Advisor for MT4, but I need to open the order at the closure of the candle and not immediately when the condition meet. There is a function to do it? Or how I can write it? Can someone please help me?
What I wrote it sends the order immediately when the condition are satisfied, but how can I modify it to send the oreder at the closure of the candle?