Last tick of the day?
-
Thanks for fxDreema. Really enjoying using it.
Q: How do I detect the last tick of the day so I can close out all my trades?
Reason I'm asking is that I'm trading during specific hours e.g. 7am - 8pm. However, using Tick Data Manager I'm finding some of the historical tick data ends at 5pm/6pm. And so the EA ends up rolling over into the following morning at 7am.
I thought maybe using a Candle ID of -1 to detect the time of the next tick and compare the time with the previous tick might do it. Then I can close out all the trades on the current tick, which would be the last tick of the day.
Please let me know if it's possible. Thx.
-
For Candle ID use positive values. 1 instead of -1. Candle's Close time at Candle ID = 1 should be the last data available
-
Thanks, however it doesn't solve my exact issue.
What is happening is that there is a task at 8pm to close all the trades. However the ticks do not get to 8pm, they stop at 6pm (not enough data available for that date). And then the next tick is 7am in the morning. So all the trades end up continuing into the next day. They do not get closed at 8pm because there is no tick data to get to 8pm.
So how do I detect at 6pm (when the data runs out) that the NEXT tick will be at 7am so I can close my trades out at 6pm? Does that make sense?
-Mike
-
Or at least is there a way to say we are now at the end of the day, the last tick/candle of the current day?
-
The simplest solution I can think of is a way to look "ahead" and see what the data for the next tick will be. That's why I mentioned using -1 for the candle to mean look forwards to the next candle in the future.
-
In MQL4 there are holes in the history data, this is not unexpected. But if some EA works on real, at least then ticks should come. So you can just skip this situation. In fact, if the EA does not receive any ticks from the broker, this probably means that something is wrong anyway - markets are closed, network connection is broken or something else - so even if you force the trades to be closed, it will probably not happen. Because you can always put some blocks under "on Timer" and this event does not care if there are ticks or not. Well, "on Timer" don't work very well in the Tester, if it works at all. But anyway, if with "on Timer" you force the EA to close everything at 08:00 and the markets are closed at that time... then what is the point.