// AFL for gathering count of negative/red/black candlesticks for a particular period. Will count candles in the chart timeframe, whether EOD or IEOD doesn't matter.
/* In chart: If no bar is selected, LookBackPeriod will start from right most bar.
If any bar is selected then LookBackPeriod will start from the left of that selected bar.
*/
_SECTION_BEGIN("CountCandle's in LookBackPeriod");
ShowCandleCount=ParamToggle("ShowCandleCount", "No|Yes", 1);
if(ShowCandleCount)
{
LookBackPeriod=Param("LookBackPeriod",10,Minimum=1,Maximum=1000);
totalRedCandles=0;
totalGreenCandles=0;
totalDojiCandles=0;
for(i=1; i<=LookBackPeriod AND i<BarCount;i++)
{
iO=Ref(O,-i);
iC=Ref(C,-i);
isGreenBar =IIf((iO<iC),1,0);
isRedBar =IIf((iO>iC),1,0);
isDojiBar =IIf((iO==iC),1,0);
totalGreenCandles=totalGreenCandles+(IsTrue(isGreenBar));
totalRedCandles=totalRedCandles+(IsTrue(isRedBar));
totalDojiCandles=totalDojiCandles+(IsTrue(isDojiBar));
}
GfxSetTextColor(textColor=ParamColor("TextColor",colorLavender));
GfxSetBkColor(bkColor = ParamColor("bkColor",colorBlack));
xR=Param("xR",0,0,1000,1);
yR=Param("yR",80,0,1000,1);
GfxTextOut("totalGreenCandles="+(totalGreenCandles),xR,yR+25);
GfxTextOut("totalRedCandles="+(totalRedCandles),xR,yR+40);
GfxTextOut("totalDojiCandles="+(totalDojiCandles),xR,yR+55);
Filter=(totalGreenCandles>0) OR (totalRedCandles>0);
greenTotalColor=IIf(totalGreenCandles>totalRedCandles AND totalGreenCandles>=totalDojiCandles, colorPaleGreen, colorLavender);
redTotalColor=IIf(totalRedCandles>totalGreenCandles AND totalRedCandles>=totalDojiCandles, colorRed, colorLavender);
flatTotalColor=IIf(totalDojiCandles>=totalGreenCandles AND totalDojiCandles>=totalRedCandles, colorLightYellow, colorLavender);
AddColumn(totalGreenCandles,"totalGreenCandles", format=1, textColor=colorBlack, bkgndColor=greenTotalColor);
AddColumn(totalRedCandles,"totalRedCandles", format=1, textColor=colorBlack, bkgndColor=redTotalColor);
AddColumn(totalDojiCandles,"totalDojiCandles", format=1, textColor=colorBlack,bkgndColor=flatTotalColor);
}
_SECTION_END();