Hey, I´ve been searching quite some time now but didnt find anything, so I hope anyone can help me here
I want to close an order after 24 Hours, but it should be at the end of the current bar(Dailyperiod), not at the start of the new one, in case of gaps.
And I dont want to close all open trades, I want the ea to specifiy which trade´s open time is= 24hours
Thanks in advance
Working with the idea of the end of a bar is difficult, because you never know which tick will be the last one in for that bar. Workarounds include using timers and/or various time functions, but they are all just that - workarounds and prone to issues. You end up balancing how close to the line you want to push it (milliseconds? seconds? minutes?) versus the risk of missing the end of the bar.
I am a little confused - do you want the orders closed at the end of the D1 bar in which the order was placed, or after 24 hours of being opened?
If you wanted to close at 5 minutes before Midnight (assuming that there is a tick within the last 5 minutes)
datetime NextMidnight=TimeCurrent() -(TimeCurrent()%(PERIOD_D1*60))+PERIOD_D1*60;
datetime CloseTime=NextMidnight-300;
if(TimeCurrent()>=CloseTime)
{
//code to close trades
}
Working with the idea of the end of a bar is difficult, because you never know which tick will be the last one in for that bar. Workarounds include using timers and/or various time functions, but they are all just that - workarounds and prone to issues. You end up balancing how close to the line you want to push it (milliseconds? seconds? minutes?) versus the risk of missing the end of the bar.
I am a little confused - do you want the orders closed at the end of the D1 bar in which the order was placed, or after 24 hours of being opened?
What part of their posts about "end of a bar is difficult" was unclear? Closing at 23:59:59 is not possible.
There might be a tick in the last 5 minutes, there might not. There is a 99.99% probably that there will not be in the last second.
Even if it was, it takes time to close an order (live). It's likely that the order will be closed after midnight due to transmission delays, server delays, possible disconnects.
Well,
What if i want to close it, at the beginning of the new bar?
skyblazer: What if i want to close it, at the beginning of the new bar?
| What about it? |

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey, I´ve been searching quite some time now but didnt find anything, so I hope anyone can help me here
I want to close an order after 24 Hours, but it should be at the end of the current bar(Dailyperiod), not at the start of the new one, in case of gaps.
And I dont want to close all open trades, I want the ea to specifiy which trade´s open time is= 24hours
Thanks in advance