//+------------------------------------------------------------------+ //| CS method mod by KUSKUS v2.0 | //| (complete rewrite and name change of pattern alert) | //| | //| Copyright Š 2005, Jason Robinson mod by kuskus | //| | //+------------------------------------------------------------------+ #property copyright "Copyright Š 2007, Jason Robinson mod by kuskus" #property indicator_chart_window #property indicator_buffers 4 #property indicator_color1 clrRed #property indicator_color2 clrLimeGreen #property indicator_color3 clrDarkGray #property indicator_color4 clrDarkGray extern int MaxCandlesToDisplay = 50; extern string PatternTextFont = "Arial"; extern int PatternFontSize = 8; extern bool Show_Alert = false; extern double Arrow_Pixel_Gap = 0.2; extern double Uptrend_Text_Pixel_Gap = 0.2; extern double Downtrend_Text_Pixel_Gap = 0.2; extern string Bullish_Patterns = "---------------------------"; extern bool Display_Bullish_Engulfing = true; extern bool Display_Piercing_Line = true; extern bool Display_Three_White_Soldiers = true; extern bool Display_Three_Outside_Up = true; extern bool Display_Three_Inside_Up = true; extern bool Display_Morning_Doji_Stars = true; extern bool Display_Abandon_Baby = true; extern string Bearish_Patterns = "---------------------------"; extern bool Display_Bearish_Engulfing = true; extern bool Display_Dark_Cloud_Cover = true; extern bool Display_Three_Black_Crows = true; extern bool Display_Three_Outside_Down = true; extern bool Display_Three_Inside_Down = true; extern bool Display_Evening_Stars = true; extern bool Display_Evening_Doji_Stars = true; extern string Neutral_Patterns = "---------------------------"; extern bool Display_Harami = true; extern bool Display_Doji = false; extern bool Display_Inverted_Hammer_Shooting_Star = false; extern bool Display_Hanging_Man_Hammer = false; extern string UniqueLabelID = "CandleStickPatterns"; //---- buffers double upArrow[], downArrow[], specialLow[], specialHigh[]; string PatternText[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators IndicatorBuffers(4); SetIndexStyle (0,DRAW_ARROW, EMPTY); SetIndexArrow (0,234); SetIndexBuffer(0, downArrow); SetIndexStyle (1,DRAW_ARROW, EMPTY); SetIndexArrow (1,233); SetIndexBuffer(1, upArrow); SetIndexStyle (2,DRAW_ARROW, EMPTY); SetIndexArrow (2,110); SetIndexBuffer(2, specialLow); SetIndexStyle (3,DRAW_ARROW, EMPTY); SetIndexArrow (3,110); SetIndexBuffer(3, specialHigh); return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { string lookFor = UniqueLabelID + ":pattern-"; int lookForLength = StringLen(lookFor); for (int i=ObjectsTotal()-1; i>=0; i--) { string objectName = ObjectName(i); if (StringSubstr(objectName,0,lookForLength) == lookFor) ObjectDelete(objectName); } return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start(){ double Range, AvgRange; int counter, setalert, shift, shift1, shift2, shift3, setPattern = 0, alert = 0; static datetime prevtime = 0; string pattern, period; double O, O1, O2, C, C1, C2, L, L1, L2, H, H1, H2; if(prevtime == Time[0]) { return(0); } prevtime = Time[0]; ArrayResize(PatternText,Bars); switch (Period()) { case 1: period = "M1"; break; case 5: period = "M5"; break; case 15: period = "M15"; break; case 30: period = "M30"; break; case 60: period = "H1"; break; case 240: period = "H4"; break; case 1440: period = "D1"; break; case 10080: period = "W1"; break; case 43200: period = "MN"; break; } for (int j = 0; j < MaxCandlesToDisplay; j++) { PatternText[j] = UniqueLabelID+":pattern-" + j; } for (shift = 0; shift < MaxCandlesToDisplay; shift++) { ObjectDelete(PatternText[shift]); setalert = 0; counter=shift; Range=0; AvgRange=0; for (counter=shift ;counter<=shift+9;counter++) { AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]); } Range=AvgRange/10; shift1 = shift + 1; shift2 = shift + 2; shift3 = shift + 3; downArrow[shift1] = EMPTY_VALUE; upArrow[shift1] = EMPTY_VALUE; specialLow[shift1] = EMPTY_VALUE; specialHigh[shift1] = EMPTY_VALUE; O = Open [shift1]; O1 = Open [shift2]; O2 = Open [shift3]; H = High [shift1]; H1 = High [shift2]; H2 = High [shift3]; L = Low [shift1]; L1 = Low [shift2]; L2 = Low [shift3]; C = Close[shift1]; C1 = Close[shift2]; C2 = Close[shift3]; // ------------------------------------------------------------------------------------------------------------------------ // Neutral Patterns ------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------------------------------ // Check for Hanging Man if (((H-L)>4*(O-C))&&((C-L)/(0.001+H-L)>=0.75)&&((O-L)/(0.001+H-L)>=0.75)) { if (Display_Hanging_Man_Hammer == true) { ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift1], High[shift1] + Range * Uptrend_Text_Pixel_Gap); ObjectSetText(PatternText[shift], "HangMan & Hammer", PatternFontSize, PatternTextFont, clrDarkGray); ObjectSetDouble(ChartID(), PatternText[shift], OBJPROP_ANGLE, 90); ObjectSetInteger(ChartID(), PatternText[shift], OBJPROP_ANCHOR, ANCHOR_BOTTOM); specialLow[shift1] = Low[shift1] - Range * Arrow_Pixel_Gap; specialHigh[shift1] = High[shift1] + Range * Arrow_Pixel_Gap; } if (shift == 0 && Show_Alert == true) { pattern="Hang Man @ Hammer"; setalert = 1; } } // Check for Doji if (C==O) { if (Display_Doji== true) { ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift1], High[shift1] + Range*Uptrend_Text_Pixel_Gap); ObjectSetText(PatternText[shift], "Doji", PatternFontSize, "Calibri", clrDarkGray); ObjectSetDouble(ChartID(), PatternText[shift], OBJPROP_ANGLE, 90); ObjectSetInteger(ChartID(), PatternText[shift], OBJPROP_ANCHOR, ANCHOR_BOTTOM); specialLow[shift1] = Low[shift1] - Range * Arrow_Pixel_Gap; specialHigh[shift1] = High[shift1] + Range * Arrow_Pixel_Gap; } if (shift == 0 && Show_Alert == true) { pattern="Neutral Signal"; setalert = 1; } } // Check for Inverted Hammer and Shooting Star if (((H-L)>3*(O-C))&&((H-C)/(0.001+H-L)>0.6)&&((H-O)/(0.001+H-L)>0.6)) { if (Display_Inverted_Hammer_Shooting_Star) { ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift1], High[shift1] + Range * Uptrend_Text_Pixel_Gap); ObjectSetText(PatternText[shift], "InvertHammer & ShootStar", PatternFontSize, PatternTextFont, clrDarkGray); ObjectSetDouble(ChartID(), PatternText[shift], OBJPROP_ANGLE, 90); ObjectSetInteger(ChartID(), PatternText[shift], OBJPROP_ANCHOR, ANCHOR_BOTTOM); specialLow[shift1] = Low[shift1] - Range * Arrow_Pixel_Gap; specialHigh[shift1] = High[shift1] + Range * Arrow_Pixel_Gap; } if (shift == 0 && Show_Alert == true) { pattern="Inverted Hammer @ Shooting Star"; setalert = 1; } } // ------------------------------------------------------------------------------------------------------------------------ // Bearish Patterns ------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------------------------------ specialLow[shift] = EMPTY_VALUE; specialHigh[shift] = EMPTY_VALUE; // Check for Bearish Harami pattern if ((C1>O1)&&(O>C)&&(O<=C1)&&(O1<=C)&&((O-C)<(C1-O1))) { if (Display_Harami == true) { ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift1], Low[shift1] - Range*Downtrend_Text_Pixel_Gap); ObjectSetText(PatternText[shift], "SELL Harami", PatternFontSize+1, "Calibri", clrRed); ObjectSetDouble(ChartID(), PatternText[shift], OBJPROP_ANGLE, 270); ObjectSetInteger(ChartID(), PatternText[shift], OBJPROP_ANCHOR, ANCHOR_BOTTOM); downArrow[shift1] = High[shift1] + Range * Arrow_Pixel_Gap; } if (shift == 0 && Show_Alert == true) { pattern="Sell Signal"; setalert = 1; } } // Check for Bearish Engulfing pattern if ((C1>O1)&&(O>C)&&(O>=C1)&&(O1>=C)&&((O-C)>(C1-O1))) { if (Display_Bearish_Engulfing == true) { ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift1], Low[shift1] - Range * Downtrend_Text_Pixel_Gap); ObjectSetText(PatternText[shift], "Bear Engulf", PatternFontSize, PatternTextFont, clrPurple); ObjectSetDouble(ChartID(), PatternText[shift], OBJPROP_ANGLE, 270); ObjectSetInteger(ChartID(), PatternText[shift], OBJPROP_ANCHOR, ANCHOR_BOTTOM); downArrow[shift1] = High[shift1] + Range * Arrow_Pixel_Gap; } if (setalert == 0 && Show_Alert == true) { pattern = "Bearish Engulfing Pattern"; setalert = 1; } } // Check for Three Inside Down pattern if ((C2>O2)&&(O1>C1)&&(O1<=C2)&&(O2<=C1)&&((O1-C1)<(C2-O2))&&(O>C)&&(CO2)&&(O1>C1)&&(O1>=C2)&&(O2>=C1)&&((O1-C1)>(C2-O2))&&(O>C)&&(CO1)&&(((C1+O1)/2)>C)&&(O>C)&&(O>C1)&&(C>O1)&&((O-C)/(0.001+(H-L))>0.6)) { if (Display_Dark_Cloud_Cover == true) { ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift1], Low[shift1] - Range * Downtrend_Text_Pixel_Gap); ObjectSetText(PatternText[shift], "Dark Cloud", PatternFontSize, PatternTextFont, clrRed); ObjectSetDouble(ChartID(), PatternText[shift], OBJPROP_ANGLE, 270); ObjectSetInteger(ChartID(), PatternText[shift], OBJPROP_ANCHOR, ANCHOR_BOTTOM); downArrow[shift1] = High[shift1] + Range * Arrow_Pixel_Gap; } if (setalert == 0 && Show_Alert == true) { pattern="Dark Cloud Cover Pattern"; setalert = 1; } } // Check for Evening Star Pattern if ((C2>O2)&&((C2-O2)/(0.001+H2-L2)>0.2)&&(C2O1)&&((H1-L1)>(3*(C1-O1)))&&(O>C)&&(OO2)&&((C2-O2)/(0.001+H2-L2)>0.6)&&(C2O1)&&((H1-L1)>(3*(C1-O1)))&&(O>C)&&(O C * 0.001)&&(O1 > C1 * 0.01)&&(O2 > C2*0.001)&&(C < C1)&&(C1 < C2)&&(O > C1)&&(O < O1)&&(O1 > C2)&&(O1 < O2)&&(((C - L)/(H - L))<0.6)&&(((C1 - L1)/(H1 - L1))<0.6)&&(((C2 - L2)/(H2 - L2))<0.6)){ if (Display_Three_Black_Crows == true){ ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift1], Low[shift1] - Range * Uptrend_Text_Pixel_Gap); ObjectSetText(PatternText[shift], "3 Black Crows", PatternFontSize, PatternTextFont, clrRed); ObjectSetDouble(ChartID(), PatternText[shift], OBJPROP_ANGLE, 270); ObjectSetInteger(ChartID(), PatternText[shift], OBJPROP_ANCHOR, ANCHOR_BOTTOM); downArrow[shift1] = High[shift1] + Range * Arrow_Pixel_Gap; } if (shift == 0 && Show_Alert == true) { pattern="3 Black Crows Pattern"; setalert = 1; } } // End of Bearish Patterns // ------------------------------------------------------------------------------------------------------------------------ // Bullish Patterns ------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------------------------------ specialLow[shift1] = EMPTY_VALUE; specialHigh[shift1] = EMPTY_VALUE; // Check for Bullish Harami pattern if ((O1>C1)&&(C>O)&&(C<=O1)&&(C1<=O)&&((C-O)<(O1-C1))) { if (Display_Harami == true) { ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift1], High[shift1] + Range * Uptrend_Text_Pixel_Gap); ObjectSetText(PatternText[shift], "BUY Harami", PatternFontSize+1, "Calibri", clrLime); ObjectSetDouble(ChartID(), PatternText[shift], OBJPROP_ANGLE, 90); ObjectSetInteger(ChartID(), PatternText[shift], OBJPROP_ANCHOR, ANCHOR_BOTTOM); upArrow[shift1] = Low[shift1] - Range * Arrow_Pixel_Gap; } if (shift == 0 && Show_Alert == true) { pattern="Buy Signal"; setalert = 1; } } // Check for Bullish Engulfing pattern if ((O1>C1)&&(C>O)&&(C>=O1)&&(C1>=O)&&((C-O)>(O1-C1))) { if (Display_Bullish_Engulfing) { ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift1], High[shift1] + Range * Uptrend_Text_Pixel_Gap); ObjectSetText(PatternText[shift], "Bull Engulf", PatternFontSize, PatternTextFont, clrDarkGreen); ObjectSetDouble(ChartID(), PatternText[shift], OBJPROP_ANGLE, 90); ObjectSetInteger(ChartID(), PatternText[shift], OBJPROP_ANCHOR, ANCHOR_BOTTOM); upArrow[shift1] = Low[shift1] - Range * Arrow_Pixel_Gap; } if (shift == 0 && Show_Alert == true) { pattern="Bullish Engulfing"; setalert = 1; } } // Check for Three Outside Up pattern if ((O2>C2)&&(C1>O1)&&(C1>=O2)&&(C2>=O1)&&((C1-O1)>(O2-C2))&&(C>O)&&(C>C1)) { if (Display_Three_Outside_Up == true) { ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift1], High[shift1] + Range * Uptrend_Text_Pixel_Gap); ObjectSetText(PatternText[shift], "3 Outside Up", PatternFontSize, PatternTextFont, clrLime); ObjectSetDouble(ChartID(), PatternText[shift], OBJPROP_ANGLE, 90); ObjectSetInteger(ChartID(), PatternText[shift], OBJPROP_ANCHOR, ANCHOR_BOTTOM); upArrow[shift1] = Low[shift1] - Range * Arrow_Pixel_Gap; } if (shift == 0 && Show_Alert == true) { pattern="3 Outside Up Pattern"; setalert = 1; } } // Check for Three Inside Up pattern if ((O2>C2)&&(C1>O1)&&(C1<=O2)&&(C2<=O1)&&((C1-O1)<(O2-C2))&&(C>O)&&(C>C1)&&(O>O1)) { if (Display_Three_Inside_Up == true) { ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift1], High[shift1] + Range * Uptrend_Text_Pixel_Gap); ObjectSetText(PatternText[shift], "3 Inside Up", PatternFontSize, PatternTextFont, clrLime); ObjectSetDouble(ChartID(), PatternText[shift], OBJPROP_ANGLE, 90); ObjectSetInteger(ChartID(), PatternText[shift], OBJPROP_ANCHOR, ANCHOR_BOTTOM); upArrow[shift1] = Low[shift1] - Range * Arrow_Pixel_Gap; } if (shift == 0 && Show_Alert == true) { pattern="3 Inside Up Pattern"; setalert = 1; } } // Check for Piercing Line pattern if ((C10.6)) { if (Display_Piercing_Line == true) { ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift1], High[shift1] + Range * Uptrend_Text_Pixel_Gap); ObjectSetText(PatternText[shift], "Pierce Line", PatternFontSize, PatternTextFont, clrLime); ObjectSetDouble(ChartID(), PatternText[shift], OBJPROP_ANGLE, 90); ObjectSetInteger(ChartID(), PatternText[shift], OBJPROP_ANCHOR, ANCHOR_BOTTOM); upArrow[shift1] = Low[shift1] - Range * Arrow_Pixel_Gap; } if (shift == 0 && Show_Alert == true) { pattern="Piercing Line Pattern"; setalert = 1; } } // Check for Three clrDarkGray Soldiers pattern if ((C>O*0.001)&&(C1>O1*0.001) &&(C2>O2*0.001) &&(C>C1) &&(C1>C2) &&(OO1) &&(O1O2) &&(((H-C)/(H-L))<0.2) &&(((H1-C1)/(H1-L1))<0.2)&&(((H2-C2)/(H2-L2))<0.2)) { if (Display_Three_White_Soldiers == true) { ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift1], High[shift1] + Range * Uptrend_Text_Pixel_Gap); ObjectSetText(PatternText[shift], "3 White Soldier", PatternFontSize, PatternTextFont, clrLime); ObjectSetDouble(ChartID(), PatternText[shift], OBJPROP_ANGLE, 90); ObjectSetInteger(ChartID(), PatternText[shift], OBJPROP_ANCHOR, ANCHOR_BOTTOM); upArrow[shift1] = Low[shift1] - Range * Arrow_Pixel_Gap; } if (shift == 0 && Show_Alert == true) { pattern="3 White Soldiers Pattern"; setalert = 1; } } // Check for Abandon Baby if ((C1==O1)&&(C2>O2)&&(O>C)&&(L1>H2)&&(L1>H)) if ((C1==O1)&&(O2>C2)&&(C>O)&&(L2>H1)&&(L>H1)) if (Display_Abandon_Baby== true) { ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift1], High[shift1] + Range * Uptrend_Text_Pixel_Gap); ObjectSetText(PatternText[shift], "Baby", PatternFontSize, PatternTextFont, clrLime); ObjectSetDouble(ChartID(), PatternText[shift], OBJPROP_ANGLE, 90); ObjectSetInteger(ChartID(), PatternText[shift], OBJPROP_ANCHOR, ANCHOR_BOTTOM); upArrow[shift1] = Low[shift1] - Range * Arrow_Pixel_Gap; } if (shift == 0 && Show_Alert == true) { pattern="Abandon Baby"; setalert = 1; } // Check for Morning Doji Star if ((O2>C2)&&((O2-C2)/(0.001+H2-L2)>0.6)&&(C2>O1)&&(O1>C1)&&((H1-L1)>(3*(C1-O1)))&&(C>O)&&(O>O1)) { if (Display_Morning_Doji_Stars == true) { ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift1], High[shift1] + Range * Uptrend_Text_Pixel_Gap); ObjectSetText(PatternText[shift], "Morning Doji", PatternFontSize, PatternTextFont, clrLime); ObjectSetDouble(ChartID(), PatternText[shift], OBJPROP_ANGLE, 90); ObjectSetInteger(ChartID(), PatternText[shift], OBJPROP_ANCHOR, ANCHOR_BOTTOM); upArrow[shift1] = Low[shift1] - Range * Arrow_Pixel_Gap; } if (shift == 0 && Show_Alert == true) { pattern="Morning Doji Star Pattern"; setalert = 1; } } if (setalert == 1 && shift == 0) { Alert(Symbol(), " ", period, " ", pattern); setalert = 0; } } // End of for loop; //for (shift = 0; shift < MaxCandlesToDisplay; shift++) return(0); } //+------------------------------------------------------------------+