not sure how to determine a shift value for this situation?

 

Hello Forum, I am wondering if there is a neat way I can define the following.

I want to express a condition such as (using the diagram below)

if the black moving average has been above the green bollinger bands more recently than it has been below the green bollinger bands

but I am not sure how to approach it

previously I have used the shift function (i+1, i +2, i+3 etc) to check if the candle has closed above the Bollinger Bands in last 5, 10 candles etc, it is longwinded but works for this newbie

but I am thinking what I need to determine is the shift value where the candle last closed above the upper bollinger band and the shift value where the candle last closed below the lower bollinger band and check which is larger

woulld someone mind giving me a hint as to how to work out the shift value that satisfies a certain condition (if indeed this is the approach that is logical to use)

thanks in advance




 
pullend: if the black moving average has been above the green bollinger bands more recently than it has been below the green bollinger bands
translates to: what type was the last crossing of MA and BB? was it an up or down crossing?


you need to distinguish between 2 situations (assumed you want to use this signal as an entry condition):

1) EA start: here you want to know the last signal (where am i in the current market). resolving a shift value is not the way to go. instead you walk backwards through both buffers until you hit the first crossing. once arrived you check what type it is.

2) EA run: you want to know when a current signal is triggered. again, you don't need shift values. at every bar open (or at every tick if this makes sense to you; probably not) you check for a new crossing by comparing the last value to the current value.

EA start (1) is a relatively rare situation in time compared to EA run (2). you might consider ignoring EA start and instead "heating the history up": you load the EA, ignore the last signal and wait for the next valid signal. but you also need to prepare for the obvious, EA/terminal/computer/network crashes during a running strategy. at restart you need to rebuild/synchronize state and for this you need the last signal, anyway.


storing state (like tickets, signals for ex.) outside the terminal to be able to safely synchronize/rebuild state later is a good idea.

 
pullend: I want to express if the black moving average has been above the green bollinger bands more recently than it has been below the green bollinger bands
For a given look back (nLB) count the number of blacks above green (nBAG). Blacks below green = (nLB - nBAG). bool isBAB = nBAG > nBBG;
 
given this:

nLB  = 200
nBAG = 100
nBBG = 100

(1) can you answer the thread openers question "...if the ma has been above ... MORE RECENTLY than it has been below ..." with this values? you can't.
can you answer it with looking for and stopping at the 1st found crossing? you can.

(2) what will be the answer with your code if nBAG was 190 and the last 10 bars went below the BB? you might answer it to yourself.
 
paulepanke:
given this:

nLB  = 200
nBAG = 100
nBBG = 100

(1) can you answer the thread openers question "...if the ma has been above ... MORE RECENTLY than it has been below ..." with this values? you can't.

Yes I can. The answer is NO. It is not been above. And neither has it been below.

Your post isn't useful. Sounded like a troll to me.

 
WHRoeder:

Yes I can. The answer is NO. It is not been above. And neither has it been below.

Your post isn't useful. Sounded like a troll to me.


thanks for the help from both of you, I will go and do some work around this, it's frustrating but rewarding trying to get my head around these basics !