Looking for a Crossing during last n candles
-
I want to know if there was a ema crossing during the last 5 candles.
Ok I can add 5 blocks for long condition with different offsets but then i need another 5 blocks for the short condition.Is there an simpler way?
-
If at the moment EMA20 > EMA5 and for the fifth candle EMA20 < EMA5, then this means that there was a crossover somewhere in between. This is what the "Cross width" parameter do actually (although I keep this parameter only for compatibility with old projects), but I will recommend to use two blocks instead

-
Two blocks is not exactly hitting the point.

maybe there are more crossings during the last 5 candles. One on candle 4 one on candle 1. Comparing like you say will give me a false where it must be a true....
-
People are always asking me how to make indicator in the EA, because these calculations are basically this
And I always explain that the best is to get signals directly from indicators. The difference is that indicators (if well written) does not recalculate on every tick, while in the EA this is hard to make, especially in EA builder.Anyway, I finally added this field, which allows us to calculate some things - http://prntscr.com/9egr7i - but your scenario (to detect that only 1 crossover happened in the last N candles) is more complex and specific and I don't feel like I want to do it, at leat not somewhere in Condition

Otherwise the logic would be to make "for" loop and count crossovers from below and from above and then to pass only if this count is 1. If the count is 2 - break the loop.