![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
I am trying to write an EA that will close open order at the end of the next bar and have tried the following for the 4hr period:
--------------------------------------------------------------------
datetime a = TimeHour(OrderOpenTimeA);
string closestringA;
datetime closetimeA;
if ( a >= 0 && a < 4 )
{
closestringA = "7:59";
closetimeA = StrToTime(closestringA) + TimeDay(1);
}
closetimeA = StrToTime(closestringA);
if ( TimeCurrent() >= closetimeA ) {CloseBasketA = True;}
----------------------------------------------------------------------
This code will return the date as a day before the order opens and does not work for any timeframe.
There must be an easier/simpler way to code this for any timeframe. I would appreciate any suggestions.