static datetime currentbar = 0;
It is good but there can be an issue when you switch the timeframe on the chart manually.
If you want ultimate control over that you can use a global variable instead. (https://www.mql5.com/en/docs/globals/globalvariableset)
![Documentation on MQL5: Global Variables of the Terminal / GlobalVariableSet Documentation on MQL5: Global Variables of the Terminal / GlobalVariableSet](https://c.mql5.com/36/18/documentation-on-mql5-global-variables.png)
- www.mql5.com
It is good but there can be an issue when you switch the timeframe on the chart manually.
If you want ultimate control over that you can use a global variable instead. (https://www.mql5.com/en/docs/globals/globalvariableset)
It is good but there can be an issue when you switch the timeframe on the chart manually.
If you want ultimate control over that you can use a global variable instead. (https://www.mql5.com/en/docs/globals/globalvariableset)
When you switch timeframe the bar time changes so it will trigger your code.
If you dont want that you'd have to use a fixed candle like PERIOD_H1 in stead of PERIOD_CURRENT, or use a global var.
Also if you set the static datetime currentbar = 0; to zero it will be set to zero each time the program is reinitialized which can be undesirable as well.![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm trying to make sure I have the right coding to check and execute a possible close of position After a new bar from opening a position.
Can anyone confirm if this code is good. It seems as if each time it checks for close, it would set the "currentbar" again to datetime?