Quite often you see a code where buys occur when the price goes below a bottom Bollinger Band or shifted moving average band and the sell is when price hits the top band. In an uptrend, they bands will typically fall below the prices and in a downtrend the bands occur above the prices.
What I'd like to do is have the bands be able to "see" if they are above the price channel and to make automatic adjustments. What I'd like to do is count how many bars it has been since the high price has crossed above the top band and then use that number to keep pushing the top band down until the price hits it.
I have this code started here:
MiddleLine = MA(C,5);
Shift = ATR(5);
TopBand = MiddleLine + 0.5*Shift;
TopHit = High > TopBand;
SinceTopHit = BarsSince(TopHit);
TopBandModified = MiddleLine + 0.5*Shift - 0.1*SinceTopHit*Shift;
//TopBandModified goes a little lower each time the high doesn't cross the TopBand
//Is it possible to have the TopBandModified go lower each time the high doesn't cross the TopBandModified itself?
Plot( C, "Price", colorDefault, styleCandle );
Plot(TopBandModified,"TopBandModified", colorBlue, styleLine|styleThick);
Plot(MiddleLine, "MiddleLine", colorwhite, styleDashed);
Plot(TopBand,"TopBand", colorBlue, styleDashed);
Plot(SinceTopHit,"SinceTopHit",colorYellow,styleLine|styleOwnScale);
The shortcoming in my code is that it has to use a separate "TopBand" to calculate the BarsSince the high crossed above. I'd like to use the BarsSince the high has crossed above the "TopBandModified" itself. Does it make sense what I'm asking? Is it possible to do it?