In other words, if SL is hit, skip the whole bar and wait for a new day.
I think you are asking how to detect when a new bar forms.
This article describes a time-based method to do so.
- www.mql5.com
I think you are asking how to detect when a new bar forms.
This article describes a time-based method to do so.
Lord Odin:
but how will I know at the start of my condition that my orders' Stop Loss is hit?
I don't use MQL4, but a quick search suggests this might help:
- 2008.12.18
- www.mql5.com
Lord Odin: Sorry if this question is an idiotic one, but I am rather new to this whole MQL thing. I am coding a small expert advisor, and would like the following to be achieved:
If any of my buy orders, hits its stop loss, I would like to stop all operations and jump to next bar, ( I am using it on a daily chart). In other words, if SL is hit, skip the whole bar and wait for a new day.
Is there an easy way to do this? Kindly find a piece of my code below.
Best Regards,
Lord Odin
Detecting a new Bar and/or New Day if on a Daily Chart ...
// Attention: Untested and uncompiled code to serve only as an example // Compatible with both MQL4 and MQL5 void OnTick() { // Check for New Current Bar static datetime dtBarCurrent = WRONG_VALUE; datetime dtBarPrevious = dtBarCurrent; dtBarCurrent = (datetime) SeriesInfoInteger( _Symbol, _Period, SERIES_LASTBAR_DATE ); boolNewBarFlag = ( dtBarCurrent != dtBarPrevious ); if( boolNewBarFlag ) // Check for New Bar { // Do something ... } else { // Do something else ... } // Do things ... }
Thank you both for your replies.
I understand now how it should be done. Cheers
Best Regards,
Lord Odin
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello Community,
Sorry if this question is an idiotic one, but I am rather new to this whole MQL thing. I am coding a small expert advisor, and would like the following to be achieved:
If any of my buy orders, hits its stop loss, I would like to stop all operations and jump to next bar, ( I am using it on a daily chart). In other words, if SL is hit, skip the whole bar and wait for a new day.
Is there an easy way to do this? Kindly find a piece of my code below.
Best Regards,
Lord Odin