Counter to check past candles conditions
-
Hi there!
I'm trying to realize this idea: if a certain number of past bars closed below the middle bollinger band and the last bar closed above, then buy.
I tried to do this using a counter "Count n then pass". The idea is this: if i want to count 5 bars under bollinger middle line i need to check 6 bars... 5 under bollinger and 1 above bollinger, so i set a constant (COUNTER CYCLES) equal to 6-2=4. Then i set a variable (ID) equal to the (COUNTER CYCLES)+2.
The counter should check the condition Candle Close < Bollinger Middle at the candle ID = (ID), if is true, set (ID)=(ID)-1. When the counter passes, If all the past candles closed below the bollinger then (ID) must be == 2 and i just have to check if the last candle closed above and eventually buy.This is the project: shared/1g4dy10Hc
My problem is that the variable (ID) goes immediatly to -1 which should be impossible... if the counter passes 4 times and (ID) is initialized to 4+2 it should never go under 2. I can't get the reason.
Probably i did a wrong use of the counter. To realize this idea i connected to the yellow dot a "run blocks" command to run the candle condition check.Can someone tell me where i'm wrong?
-
Hi!
My problem is that the variable (ID) goes immediatly to -1 which should be impossible...
That is because the block #6 executes on every tick (and so does 7), it doesn't need block 5 to run.
I probably didn't even fully understand the counter block method, there might be a less complicated way

I would use a counter variable, so I could track the count with the comment block.How bout dis:
https://fxdreema.com/shared/b2lenwGXd

-
Thanks Roar,
Your workaround it's certainly less complicated but is not what i want, because you are counting each bar waiting for the condition to buy, while i want a "picture" of X past bars at every new bar.
Anyway you suggested me where to focus my attention, and i discovered that i was using the wrong counter block. Using Loop (Pass "n" times) it works!That's the right version:
https://fxdreema.com/shared/z2aQGGpae -
Try that block called "Indicator moves within limits"
