Get ID for oldest candle on chart
-
Hello,
I have an EA that loops back through many candles on the chart. It works so far when putting it on a live chart, but when I run it in the tester, there are only around 100 candles in the past. and it causes a critical error.
Is there a way to identify the oldest candle on the chart, so that I could stop the loop at that candle? Or add something like "if candle exists" to the loop.
I am aware that I can add a delay to the EA, but that does not solve the problem if it ever occurs on a live chart, so the oldest candle ID would be good to know.
-
@nk0815 Apparently the loop searching for that last candle is having some limitations. Can you please share that part of the project?
-
Hey, thanks for the reply

This is the part that checks the candles:
https://fxdreema.com/shared/6VSzHpSBd
I think I need to find a way to stop the loop once it hits the oldest candle on the chart.
-
@nk0815 You could use this in custom code
CANDLES = WindowBarsPerChart();
CANDLES is a int variable, this will contain all the visible candles so if you zoom in or out it will change.
-
Thanks a lot, didn't know that one. This would't give me enough candles though. However, I added a condition to only loop back 2000 candles and it works now
