The logic for determining whether a trade has been open in the current bar and, hence, avoiding the opening of new positions is incorrect; it depends on the server's time. Therefore, in the case of a significant movement, it's possible for multiple trades to be opened on the same bar, but not simultaneously. To solve this issue, make the time variable a global variable instead of static and use the iTime function for example datetime lastBarTime=0;
void OnTick() {
//--- Use a static variable to ensure logic runs only once per bar datetime barTime =iTime(_Symbol,_Period,0); if( barTime == lastBarTime) return; lastBarTime = barTime;
.... rest of the code
Aws Kyoma #:
The logic for determining whether a trade has been open in the current bar and, hence, avoiding the opening of new positions is incorrect; it depends on the server's time. Therefore, in the case of a significant movement, it's possible for multiple trades to be opened on the same bar, but not simultaneously. To solve this issue, make the time variable a global variable instead of static and use the iTime function for example datetime lastBarTime=0; void OnTick() { //--- Use a static variable to ensure logic runs only once per bar datetime barTime =iTime(_Symbol,_Period,0); if( barTime == lastBarTime) return; lastBarTime = barTime; .... rest of the code
The logic for determining whether a trade has been open in the current bar and, hence, avoiding the opening of new positions is incorrect; it depends on the server's time. Therefore, in the case of a significant movement, it's possible for multiple trades to be opened on the same bar, but not simultaneously. To solve this issue, make the time variable a global variable instead of static and use the iTime function for example datetime lastBarTime=0; void OnTick() { //--- Use a static variable to ensure logic runs only once per bar datetime barTime =iTime(_Symbol,_Period,0); if( barTime == lastBarTime) return; lastBarTime = barTime; .... rest of the code
I published the new version based on your suggestion.
Where can new code be accessed ?
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register

EXSR:
EXSR.mq5: A counter‑trend MT5 EA that catches reversals by combining RSI(14) extremes with Bollinger Band breakouts and a reversal candlestick, placing one trade per symbol with fixed SL/TP.
Author: Le Trung Kien Hoang