_SECTION_BEGIN("asnavale candlePatterns");
/******************************************************/
/* */
/* PATTERNS.AFL */
/* ============ */
/* By A. S. Navale) */
/* */
/* This AFL marks different patterns on the chart. */
/* The Patterns to mark can be selected from the */
/* 'Parameters' Drop-down list which appears when */
/* right-click in the chart. By Fefault all patterns */
/* are marked. */
/* */
/* The Title of the chart displays the name of the */
/* pattern made by the candle which is selected. */
/* */
/* The patterns are: Pin Bar, Inside Bar (IB), Doji, */
/* Double Doji, 3IB(Double Inside Bar), PopGun and */
/* Master Candle. */
/* */
/* You can also run Exploration to list the stocks */
/* which have the selected pattern. */
/* */
/******************************************************/
SetChartOptions(0, chartShowDates | chartWrapTitle);
SetChartBkColor(colorBlack);
Body = abs(O - C);
InsideBody = IIf(Ref(O, -1) > Ref(C, -1), (O < Ref(O, -1) AND O > Ref(C, -1)) AND (C < Ref(O, -1) AND C > Ref(C, -1)), (O > Ref(O, -1) AND O < Ref(C, -1)) AND (C > Ref(O, -1) AND C < Ref(C, -1)));
Wick = IIf(O > C, H - O, H - C);
Tail = IIf(O > C, C - L, O - L);
PB = (Wick >= 3 * Body) OR (Tail >= 3 * Body) AND InsideBody;
DJ = CdDoji();
DblDJ = DJ AND Ref(DJ, -1);
OB = Outside();
IB = Inside();
IIB = IB AND Ref(IB, -1);
PopGun = OB AND Ref(IB, -1);
M = H < Ref(H, -4) AND Ref(H, -1) < Ref(H, -4) AND Ref(H, -2) < Ref(H, -4) AND Ref(H, -3) < Ref(H, -4) AND L > Ref(L, -4) AND Ref(L, -1) > Ref(L, -4) AND Ref(L, -2) > Ref(L, -4) AND Ref(L, -3) > Ref(L, -4);
MC = Null;
for(i = 4; i< BarCount; i++)
{
MC[i - 4] = M[i];
}
Fltr = ParamList("Filter on", "All,PinBar,Doji,DoubleDoji,InsideBar,3IB,PopGun,MasterCandle");
PBTxt = WriteIf(PB, "Pin Bar, ", "");
IBTxt = WriteIf(IB, "Inside Bar, ", "");
IIBTxt = WriteIf(IIB, "3IB, ", "");
DblDJTxt = WriteIf(DblDJ, "Double ", "");
DJTxt = WriteIf(DJ, "Doji, ", "");
PGTxt = WriteIf(PopGun, "Pop Gun, ", "");
MCTxt = WriteIf(MC, "Master Candle, ", "");
CdlTxt = MCTxt + IBTxt + IIBTxt + DblDJTxt + DJTxt + PGTxt + PBTxt;
if(Status("action") == actionIndicator)
{
_N(Title = StrFormat("{{NAME}}({{INTERVAL}}), {{DATE}} : {{OHLCX}}, V=%1.0f, ", V) + CdlTxt);
Plot(C, "", colorLightGrey, styleCandle);
if(Fltr == "Doji")
{
PlotShapes(IIf(DJ, shapeSmallCircle, shapeNone), colorSkyblue, 0, L);
}
if (Fltr == "DoubleDoji")
{
PlotShapes(IIf(DblDJ, shapeHollowCircle, shapeNone), colorSkyblue, 0, L);
}
if(Fltr == "PopGun")
{
PlotShapes(IIf(PopGun, shapeSmallSquare, shapeNone), colorYellow, 0, H, 12);
}
if(Fltr == "InsideBar")
{
PlotShapes(IIf(IB, shapeHollowSmallCircle, shapeNone), colorGold, 0, H, 12);
}
if(Fltr == "3IB")
{
PlotShapes(IIf(IIB, shapeDigit3, shapeNone), colorPink, 0, H, 12);
}
if(Fltr == "MasterCandle")
{
PlotShapes(IIf(MC, shapeCircle, shapeNone), colorYellow, 0, H, 12);
}
if(Fltr == "PinBar")
{
PlotShapes(IIf(PB, shapeHollowDownArrow, shapeNone), colorWhite, 0, H, -20);
}
if(Fltr == "All")
{
PlotShapes(IIf(PB, shapeHollowDownArrow, shapeNone), colorWhite, 0, H, -20);
PlotShapes(IIf(DJ, shapeSmallCircle, shapeNone), colorSkyblue, 0, L);
PlotShapes(IIf(DblDJ, shapeHollowCircle, shapeNone), colorSkyblue, 0, L);
PlotShapes(IIf(PopGun, shapeSmallSquare, shapeNone), colorYellow, 0, H, 12);
PlotShapes(IIf(IB, shapeHollowSmallCircle, shapeNone), colorGold, 0, H, 12);
PlotShapes(IIf(IIB, shapeDigit3, shapeNone), colorPink, 0, H, 12);
PlotShapes(IIf(MC, shapeCircle, shapeNone), colorYellow, 0, H, 12);
}
}
if(Status("action") == actionExplore)
{
SetOption("NoDefaultColumns", True);
switch (Fltr)
{
case "PinBar":
Filter = PB;
AddTextColumn(Name(), "SYMBOL", 77, colorDefault, colorDefault, 150);
AddColumn(DateTime(), "DATE & TIME", formatDateTime, colorDefault, colorDefault, 200);
AddColumn(C, "LAST CLOSE", 1.2);
AddTextColumn(PBTxt, "PATTERN", 77, colorDefault, colorDefault, 600);
break;
case "InsideB":
Filter = IB;
AddTextColumn(Name(), "SYMBOL", 77, colorDefault, colorDefault, 150);
AddColumn(DateTime(), "DATE & TIME", formatDateTime, colorDefault, colorDefault, 200);
AddColumn(C, "LAST CLOSE", 1.2);
AddTextColumn(IBTxt, "PATTERN", 77, colorDefault, colorDefault, 600);
break;
case "3IB":
Filter = IIB;
AddTextColumn(Name(), "SYMBOL", 77, colorDefault, colorDefault, 150);
AddColumn(DateTime(), "DATE & TIME", formatDateTime, colorDefault, colorDefault, 200);
AddColumn(C, "LAST CLOSE", 1.2);
AddTextColumn(IIBTxt, "PATTERN", 77, colorDefault, colorDefault, 600);
break;
case "DoubleDoji":
Filter = DblDJ;
AddTextColumn(Name(), "SYMBOL", 77, colorDefault, colorDefault, 150);
AddColumn(DateTime(), "DATE & TIME", formatDateTime, colorDefault, colorDefault, 200);
AddColumn(C, "LAST CLOSE", 1.2);
AddTextColumn(DblDJTxt + "Doji", "PATTERN", 77, colorDefault, colorDefault, 600);
break;
case "Doji":
Filter = DJ;
AddTextColumn(Name(), "SYMBOL", 77, colorDefault, colorDefault, 150);
AddColumn(DateTime(), "DATE & TIME", formatDateTime, colorDefault, colorDefault, 200);
AddColumn(C, "LAST CLOSE", 1.2);
AddTextColumn(DJTxt, "PATTERN", 77, colorDefault, colorDefault, 600);
break;
case "PopGun":
Filter = PopGun;
AddTextColumn(Name(), "SYMBOL", 77, colorDefault, colorDefault, 150);
AddColumn(DateTime(), "DATE & TIME", formatDateTime, colorDefault, colorDefault, 200);
AddColumn(C, "LAST CLOSE", 1.2);
AddTextColumn(PGTxt, "PATTERN", 77, colorDefault, colorDefault, 600);
break;
case "MasterCandle":
Filter = MC;
AddTextColumn(Name(), "SYMBOL", 77, colorDefault, colorDefault, 150);
AddColumn(DateTime(), "DATE & TIME", formatDateTime, colorDefault, colorDefault, 200);
AddColumn(C, "LAST CLOSE", 1.2);
AddTextColumn("Master Candle", "PATTERN", 77, colorDefault, colorDefault, 600);
break;
case "All":
Filter = PB OR IB OR IIB OR DblDJ OR DJ OR PopGun OR MC;
AddTextColumn(Name(), "SYMBOL", 77, colorDefault, colorDefault, 150);
AddColumn(DateTime(), "DATE & TIME", formatDateTime, colorDefault, colorDefault, 200);
AddColumn(C, "LAST CLOSE", 1.2);
AddTextColumn(CdlTxt, "PATTERN", 77, colorDefault, colorDefault, 600);
break;
}
}
_SECTION_END();