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:
- On each bar, calculate difference between price and bollinger bands
- Add them to a running sum if higher or lower than BB,
- 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();