I work on an EA to
place an orders at second 0, when a condition is true.
This EA is running
in one Chart – one Currency – but it checks conditions for
Condition – check
the previous candle
The condition will
check the last candle (index 1) , when the current candle (index 0)
has opened and it's second 0.
In other words, when we are in second 0
of a new candle, the condition will check the previous candle and if
the condition is true, an order will be generated.
Lets stay in one
timeframe, and just look at different currencys, that are analysed by
the EA, thats running in only one chart:
On my way getting
these two things (second-0 and condition) together, i found out, that
on some currencys the iTime() call sometimes returns the
new-candle-time, or sometimes the time of the previous candle. How
can that, be? The new candle has startet but, at some currencys
iTime() returns the time of the old, previous candle.
My explaination is, that the metatrader 4 gets a timestamp with every tick of a
certain currenys. And thats the time especially for that one tick in
that one currency. So if there's no new tick, even when the new
candle has startet, for that one curreny, you will get the last known
candle time where the last tick was in, if you call iTime(). Is that
So, we need the
condition that checks the previous candle to start a trade.
I thought, we might
do it in two cases than:
There is no "second 0" of a candle.
So if there's no new tick, even when the new
candle has startet
If there is no new tick, there is no new candle, it's how MT4 (and MT5) are working. To be clear, an example : timeframe H1, we have a candle with time 09:00, the candle with time 10:00 will only be created on the first tick after 10:00. It could be 10:00:00 or 10:00:10 or 10:01 or whatever.
From there it depends of your need how you will deal with that.