//+------------------------------------------------------------------+ //| Pattern Recognition v1.0 | //| (complete rewrite and name change of pattern alert) | //| | //| Copyright © 2005, Jason Robinson | //| (jasonrobinsonuk, jnrtrading) | //| http://www.jnrtrading.co.uk | //| | //| This is still work in progress and needs LOTS of testing | //+------------------------------------------------------------------+ #property copyright "Copyright © 2005, Jason Robinson (jnrtrading)." #property link "http://www.jnrtrading.co.uk" #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Yellow #property indicator_color2 Blue extern bool Show_Alert = false; extern int Pointer_Offset = 9; extern int High_Offset = 10; extern bool Display_ShootStar = true; extern bool Show_ShootStar_Alert = true; extern int Offset_ShootStar = 12; extern color Color_ShootStar = Green; extern int Text_ShootStar = 8; extern bool Display_Hammer = true; extern bool Show_Hammer_Alert = true; extern int Offset_Hammer = 6; extern color Color_Hammer = Green; extern int Text_Hammer = 8; extern double Candle_WickBody_Percent=0.90; extern int CandleLength=0.21; //---- buffers double upArrow[]; double downArrow[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0,DRAW_ARROW, EMPTY); SetIndexArrow(0,234); SetIndexBuffer(0, downArrow); SetIndexStyle(1,DRAW_ARROW, EMPTY); SetIndexArrow(1,233); SetIndexBuffer(1, upArrow); return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { ObjectsDeleteAll(0, OBJ_TEXT); return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start(){ double Range, AvgRange; int counter, setalert; static datetime prevtime = 0; int shift; int shift1; int shift2; int shift3; int shift4; string pattern, period; int setPattern = 0; int alert = 0; int arrowShift; int textShift; double O, O1, O2, C, C1, C2, C3, L, L1, L2, L3, H, H1, H2, H3; double CL, CLmin, CL1, CL2, BL, BLa, BL90, BL1, BL2, UW, UWa, UW1, UW2, LW, LWa, LW1, LW2, BodyHigh, BodyLow; BodyHigh = 0; BodyLow = 0; double HW, SW; if(prevtime == Time[0]) { return(0); } prevtime = Time[0]; 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 (shift = 0; shift < Bars; 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; shift4 = shift + 4; O = Open[shift1]; O1 = Open[shift2]; O2 = Open[shift3]; H = High[shift1]; H1 = High[shift2]; H2 = High[shift3]; H3 = High[shift4]; L = Low[shift1]; L1 = Low[shift2]; L2 = Low[shift3]; L3 = Low[shift4]; C = Close[shift1]; C1 = Close[shift2]; C2 = Close[shift3]; C3 = Close[shift4]; if (O>C) { BodyHigh = O; BodyLow = C; } else { BodyHigh = C; BodyLow = O; } CL = High[shift1]-Low[shift1]; CL1 = High[shift2]-Low[shift2]; CL2 = High[shift3]-Low[shift3]; BL = Open[shift1]-Close[shift1]; UW = High[shift1]-BodyHigh; LW = BodyLow-Low[shift1]; BLa = MathAbs(BL); BL90 = BLa*Candle_WickBody_Percent; if (UW>LW) { HW = UW; SW = LW; } else { HW = LW; SW = UW; } // Bearish Patterns // Check for Bearish Shooting Star if ((L1>=L2)){ if ((HW>BLa)&& ((SW/CL)<0.12) && (LW>(2*UW)) ) { if (Display_ShootStar == true) { ObjectCreate(GetName(shift), OBJ_TEXT, 0, Time[shift1], High[shift1] + (Pointer_Offset+Offset_ShootStar+High_Offset)*Point); ObjectSetText(GetName(shift), "*", Text_ShootStar, "Times New Roman", Color_ShootStar); downArrow[shift1] = High[shift1] + (Pointer_Offset*Point); } } if (Show_ShootStar_Alert) { if (setalert == 0 && Show_Alert == true) { pattern = "Shooting Star 2"; setalert = 1; } } } // End of Bearish Patterns // Bullish Patterns // Check for Bullish Hammer if ((L1<=L2)) { if ((UW>BLa)&&((LW/CL)<0.12) && (UW>(2*LW)) ) { if (Display_Hammer == true) { ObjectCreate(GetName(shift), OBJ_TEXT, 0, Time[shift1], Low[shift1] - (Pointer_Offset+Offset_Hammer)*Point); ObjectSetText(GetName(shift), "*", Text_Hammer, "Times New Roman", Color_Hammer); upArrow[shift1] = Low[shift1] - (Pointer_Offset*Point); } } if (Show_Hammer_Alert) { if (setalert == 0 && Show_Alert == true) { pattern = "Bullish Hammer 2"; setalert = 1; } } } // End of Bullish Patterns if (setalert == 1 && shift == 0) { Alert(Symbol(), " ", period, " ", pattern); setalert = 0; } } // End of for loop return(0); } //+------------------------------------------------------------------+ string GetName(int shift) { return(DoubleToStr(Time[shift],0)); }