//+------------------------------------------------------------------+ //| ProjectName | //| Copyright 2018, CompanyName | //| http://www.companyname.net | //+------------------------------------------------------------------+ #property copyright "Nikos" #property link "" #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Yellow #property indicator_color2 Yellow //Bullish Patterns //Single Candle Patterns extern bool Display_Hammer = true; extern bool Display_Inverted_Hammer = true; extern bool Display_Dragonfly_Doji = true; extern bool Display_Bullish_Spinning_Top = true; //Two Candle Patterns extern bool Display_Bullish_Engulfing = true; extern bool Display_Bullish_Harami = true; extern bool Display_Piercing_Line = true; extern bool Display_Tweezer_Bottom = true; //Three Candle Patterns extern bool Display_Morning_Star = true; extern bool Display_Three_White_Soldiers = true; extern bool Display_ThreeLine_Strike = true; //Neutral Patterns extern bool Display_Doji = false; //Bearish Patterns extern bool Display_Bearish_Engulfing = false; string LabelID = "CS_"; //---- buffers double upArrow[]; double downArrow[]; string PatternText[5000]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int init() { deleteObjects(); SetIndexStyle(0,DRAW_ARROW, EMPTY,2); SetIndexArrow(0,234); SetIndexBuffer(0, downArrow); SetIndexStyle(1,DRAW_ARROW, EMPTY,2); SetIndexArrow(1,233); SetIndexBuffer(1, upArrow); return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { Comment(""); deleteObjects(); return(0); } void deleteObjects() { string lookFor = LabelID; int lookForLength = StringLen(lookFor); for (int i=ObjectsTotal()-1; i>=0; i--) { string objectName = ObjectName(i); if (StringSubstr(objectName,0,lookForLength) == lookFor) ObjectDelete(objectName); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void myObjectCreate() { } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { double Range, AvgRange; int counter; static datetime prevtime = 0; int shift; int shift1; int shift2; int shift3; int shift4; //int shift5; string pattern, period; int setPattern = 0; //int arrowShift; //int textShift; double O, O1, O2, O3, C, C1, C2, C3, L, L1, L2, L3, H, H1, H2, H3; double Body; double Lowest_Low, Lowest_Low1, Lowest_Low2; double Lowest_High; double atr; double lowBand, lowBand1, lowBand2; if(prevtime == Time[0]) { return(0); } prevtime = Time[0]; for(int j = 0; j < Bars; j++) { PatternText[j] = "pattern-" + j; } for(shift = 0; shift < Bars; shift++) { 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]; O3 = Open[shift4]; 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]; Lowest_Low = Low[iLowest(NULL, PERIOD_CURRENT, MODE_LOW, 6, shift1)]; //lowest low of current shift candle Lowest_Low1 = Low[iLowest(NULL, PERIOD_CURRENT, MODE_LOW, 6, shift2)]; //lowest low of current shift candle Lowest_Low2 = Low[iLowest(NULL, PERIOD_CURRENT, MODE_LOW, 6, shift3)]; //lowest low of current shift candle Lowest_High = High[iLowest(NULL, PERIOD_CURRENT, MODE_HIGH, 3, shift1)]; //lowest high of current shift candle atr = iATR(NULL,PERIOD_CURRENT,14,shift1); //atr of current shift candle lowBand = iBands(NULL,PERIOD_CURRENT,20,2,0,PRICE_CLOSE,2,shift1); lowBand1 = iBands(NULL,PERIOD_CURRENT,20,2,0,PRICE_CLOSE,2,shift2); lowBand2 = iBands(NULL,PERIOD_CURRENT,20,2,0,PRICE_CLOSE,2,shift3); Body = MathAbs(C-O); int font_size = 12; // Bearish Patterns // Check for Bearish Engulfing pattern if((C1>O1)&&(C=C1)&&(C<=O1)) { if(Display_Bearish_Engulfing == true) { WindowRedraw(); ObjectCreate(LabelID + PatternText[shift], OBJ_TEXT, 0, Time[shift1], High[shift1] + Range*1.5); ObjectSetText(LabelID + PatternText[shift], "Bearish Engulfing", font_size, "Times New Roman", Yellow); downArrow[shift1] = High[shift1] + Range*0.5; } } // End of Bearish Patterns // Bullish Patterns // Check for Bullish Engulfing pattern if( (C1O) &&(O<=C1) &&(C>=O1) && ( (L<=Lowest_Low) || (L1<=Lowest_Low1) ) && ( (L<= lowBand) || (L1<= lowBand1) ) ) { if(Display_Bullish_Engulfing) { WindowRedraw(); ObjectCreate(LabelID + PatternText[shift], OBJ_TEXT, 0, Time[shift1], Low[shift1] - Range*1.5); ObjectSetText(LabelID + PatternText[shift], "Bullish Engulfing", font_size, "Times New Roman", Yellow); upArrow[shift1] = Low[shift1] - Range*0.5; } } //Check for Hammer if( ( (H-L) > 2* (O-C) && (C-L) / (H-L) > 0.5 && (O-L) / (H-L) > 0.5 // && (H-L) >= (atr * 0.5) && (L<= lowBand) && (L<=Lowest_Low) && (H <= Lowest_High) ) ) { if(Display_Hammer == true) { WindowRedraw(); ObjectCreate(LabelID + PatternText[shift], OBJ_TEXT, 0, Time[shift1], Low[shift1] - Range*1.5); ObjectSetText(LabelID + PatternText[shift], "Hammer", font_size, "Times New Roman", Yellow); upArrow[shift1] = Low[shift1] - Range*0.5; } } //Check for Inverted Hammer if( ((H-L)>2*(O-C)) && (H-C)/(H-L)>0.5 && ((H-O)/(H-L)>0.5) // && (H-L) >= (atr * 0.5) && L<= lowBand && (L<=Lowest_Low) && (H <= Lowest_High) ) { if(Display_Inverted_Hammer == true) { WindowRedraw(); ObjectCreate(LabelID + PatternText[shift], OBJ_TEXT, 0, Time[shift1], Low[shift1] - Range*1.5); ObjectSetText(LabelID + PatternText[shift], "Inverted Hammer", font_size, "Times New Roman", Yellow); upArrow[shift1] = Low[shift1] - Range*0.5; } } //Check for Dragonfly Doji if( ( (MathAbs(O-C))/(H-L) < 0.5 && C>=(H-((H-L)*0.5)) && O>=(H-((H-L))*0.5) // && (H-L) >= (atr * 0.5) && (L<= lowBand) && (L<=Lowest_Low) && (H <= Lowest_High) ) ) { if(Display_Dragonfly_Doji == true) { WindowRedraw(); ObjectCreate(LabelID + PatternText[shift], OBJ_TEXT, 0, Time[shift1], Low[shift1] - Range*1.5); ObjectSetText(LabelID + PatternText[shift], "Dragonfly Doji", font_size, "Times New Roman", Yellow); upArrow[shift1] = Low[shift1] - Range*0.5; } } //Check for Bullish Spinning Top if( ( ((C>O) && ((H-L)>(3*(C-O))) && ((((H-C)/(H-L))<0.5) && (((O-L)/H-L))<0.5)) // && (H-L) >= (atr * 0.5) && (L<= lowBand) && (L<=Lowest_Low) && (H <= Lowest_High) ) ) { if(Display_Bullish_Spinning_Top == true) { ObjectCreate(LabelID + PatternText[shift], OBJ_TEXT, 0, Time[shift1], Low[shift1] - Range*1.5); ObjectSetText(LabelID + PatternText[shift], "Bullish Spinning Top", font_size, "Times New Roman", Yellow); upArrow[shift1] = Low[shift1] - Range*0.5; } } //Check for Three Line Strike if( ( (O3>C3) && (O2>C2) && (O1>C1) && (L1O3) && (L<=Lowest_Low) && (L<= lowBand) ) ) { if(Display_ThreeLine_Strike == true) { ObjectCreate(LabelID + PatternText[shift], OBJ_TEXT, 0, Time[shift1], Low[shift1] - Range*1.5); ObjectSetText(LabelID + PatternText[shift], "Three Line Strike", font_size, "Times New Roman", Yellow); upArrow[shift1] = Low[shift1] - Range*0.5; } } //Check for Three White Soldiers if( ( (O>O1) && (OO2) && (O1O) && (C1>O1) && (C2>O2) && (L2<= lowBand2) && (L2<= Lowest_Low2) ) ) { if(Display_Three_White_Soldiers == true) { ObjectCreate(LabelID + PatternText[shift], OBJ_TEXT, 0, Time[shift1], Low[shift1] - Range*1.5); ObjectSetText(LabelID + PatternText[shift], "Three White Soldiers", font_size, "Times New Roman", Yellow); upArrow[shift1] = Low[shift1] - Range*0.5; } } //Check for Tweezer Bottom if( ( (C1.5) && (L==L1) && (C>C1) && ( (L<=Lowest_Low) || (L1<=Lowest_Low1) ) && ( (L<= lowBand) || (L1<= lowBand1) ) ) ) { if(Display_Tweezer_Bottom == true) { ObjectCreate(LabelID + PatternText[shift], OBJ_TEXT, 0, Time[shift1], Low[shift1] - Range*1.5); ObjectSetText(LabelID + PatternText[shift], "Tweezer Bottom", font_size, "Times New Roman", Yellow); upArrow[shift1] = Low[shift1] - Range*0.5; } } //Check for Bullish Harami if( ( (O1>C1) && ((O1-C1)/(H1-L1)>.5) && (C>O) && (C<= O1) && (C1<= O) && ((C-O)<(O1-C1)) && (L1<= lowBand1) && (L1<=Lowest_Low1) ) ) { if(Display_Bullish_Harami == true) { ObjectCreate(LabelID + PatternText[shift], OBJ_TEXT, 0, Time[shift1], Low[shift1] - Range*1.5); ObjectSetText(LabelID + PatternText[shift], "Bullish Harami", font_size, "Times New Roman", Yellow); upArrow[shift1] = Low[shift1] - Range*0.5; } } //Check for Piercing Line if( ( (C1C2) && (C>H1) && C>O && C>(((O2-C2)/2)+C2) &&(L1<= lowBand1) &&(L1<=Lowest_Low1) ) ) { if(Display_Morning_Star == true) { ObjectCreate(LabelID + PatternText[shift], OBJ_TEXT, 0, Time[shift1], Low[shift1] - Range*1.5); ObjectSetText(LabelID + PatternText[shift], "Morning Star", font_size, "Times New Roman", Yellow); upArrow[shift1] = Low[shift1] - Range*0.5; } } //Check for Doji and Near Doji if( ( (MathAbs(O-C) <= ((H-L)*0.5)) && L<= lowBand && (L<=Lowest_Low) ) ) { if(Display_Doji == true) { ObjectCreate(LabelID + PatternText[shift], OBJ_TEXT, 0, Time[shift1], Low[shift1] - Range*1.5); ObjectSetText(LabelID + PatternText[shift], "Doji", font_size, "Times New Roman", Yellow); upArrow[shift1] = Low[shift1] - Range*0.5; } } } // End of for loop return(0); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+