Why doesn't this generate stable signals?

Hi! I’m trying to figure out why the simple code below generates disappearing buy/sell signals. The logic seems straightforward and per the AFL check it doesn’t look at future bars:

  1. On each bar, calculate difference between price and bollinger bands
  2. Add them to a running sum if higher or lower than BB,
  3. Trade on the value of this sum
_SECTION_BEGIN("@1");

BBTOp = BBandTop( C, 3,1);
BBBot = BBandBot( C, 3,1);

Plot( BBTop, "BBTop", colorBlue, styleLine );
Plot( BBBOt, "BBBot", colorBlue, styleLine );
Plot( Close, "Price", colorBlack, styleCandle );

up=H-BBTop;
down=BBBOt-L;

a1=IIf(H>=BBTop,up,0);//max
b1=IIf(L<=BBBot,down,0);//min

a1=Cum(up);
b1=Cum(down);

Buy=a1>b1;
Short= b1>a1;
Sell=Short;
Cover=Buy;

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover) ;
Cover=ExRem(Cover,Short);

ShowTriangles = ParamToggle( "Arrows", "HIDE|SHOW", 1 );
if ( showTriangles )
{
PlotShapes( IIf( Buy, shapeSmallUpTriangle, shapeNone ), 5, 0, BuyPrice, 0 );
PlotShapes( IIf( Sell, shapeHollowCircle, shapeNone ), 4, 0, SellPrice, 0 );
PlotShapes( IIf( Cover, shapeHollowCircle, shapeNone ), 5, 0, CoverPrice, 0 );
PlotShapes( IIf( Short, shapeSmallDownTriangle, shapeNone ), 4, 0, ShortPrice, 0 );
}
_SECTION_END();

When they are "disappearing". When you scroll?

User's manual: Cum() function, quote:

Note: Starting from AmiBroker 5.30, the Cum() function does NOT force using all bars. In the past versions Cum() functions effectively turned OFF QuickAFL feature by requesting all bars to be processed. Since Cum() function was popular it caused that many legacy formulas that used it were not benefiting from QuickAFL.

To enable QuickAFL with such formulas now Cum() function does NOT affect required bars count (previously it forced all bars).

This change may lead to different results when comparing with old versions. If you are interested in getting old behaviour and use all bars just add:

SetBarsRequired( sbrAll )

anywhere in your formula.

I suspect this may not be what you really meant to do:

Perhaps you meant:
a1 = Cum(a1);
b1 = Cum(b1);

  • Matt

Hi Tomasz, yes the signals disappeared when you scroll the chart. But I added SetBarsRequired( sbrAll ) and now it’s stable. thanks!!!

Matt, thanks, you’re correct… I had a mistake in the code.