#property copyright "1 December 2018, Beerrun" #property link "https://www.forexfactory.com/showthread.php?t=166758" #property description "Indicates an Engulfing bar, then two same direction inside bars, followed by another engulfing bar of equal or greater size to the initial bar. If any errors found please contact me at mql5.com" #property version "1.0" #property strict #property indicator_chart_window enum alerts {none,//None alert,//Alerts only notification,//Notifications only both//Both Alerts and Notifications }; enum yn {no,//No yes//Yes }; input alerts Alerts=both;//Alerts/Notifications input yn AlertForming=yes;//Alert When Pattern is Forming input string possbull ="Possible BULL Pattern Forming";//Message for Bullish pattern Forming input string bullbreak="!BULL Pattern Broken To Upside!";//Message for Bullish Pattern Break input string possbear ="Possible BEAR Pattern Forming";//Message for Bearish Pattern Forming input string bearbreak="!BEAR Pattern Broken To Downside!";//Message for Bearish Pattern Break input color bullboxcolour=clrSteelBlue;//Bull pattern Colour input color bearboxcolour=clrIndigo;//Bear Pattern Colour input color failedboxcolour=C'82,82,82';//Failed Pattern Colour datetime lasttime=0; string name; int initsw=1,boxcnt=0,possbullsw=0,possbearsw=0,i=-1,fail=0,signal=0,bullsig=0,bearsig=0; int start(){ if(lasttime>=iTime(NULL,0,0))return(0); int limit=Bars-IndicatorCounted()-1; lasttime=iTime(NULL,0,0); for(i=limit;i>=0;i--){ comments(); if(possbullsw==0&&possbearsw==0){ if(iClose(NULL,0,i)>iOpen(NULL,0,i)){possbullsw=1;continue;} if(iClose(NULL,0,i)iOpen(NULL,0,i+1)&& iClose(NULL,0,i)iOpen(NULL,0,i+2)&& iClose(NULL,0,i)iOpen(NULL,0,i+2)){ if(AlertForming==1)send(possbull); patternbox(bullboxcolour); possbullsw=3;continue;} else {possbullsw=0;continue;}} if(possbullsw==3){ if(iClose(NULL,0,i)>iOpen(NULL,0,i)&& iOpen(NULL,0,i)<=iClose(NULL,0,i+1)&& iOpen(NULL,0,i)>=iOpen(NULL,0,i+3)&& iClose(NULL,0,i)>=iClose(NULL,0,i+3)){ possbullsw=4; comments(); send(bullbreak); patternbox(bullboxcolour); bullsig++;} else{ ObjectSetString(0,name,OBJPROP_TEXT,"Failed"); if(ObjectSet(name,OBJPROP_COLOR,failedboxcolour)) fail++;} possbullsw=0; continue;} if(possbearsw==1){ if(iClose(NULL,0,i)>iOpen(NULL,0,i)&& iOpen(NULL,0,i)>=iClose(NULL,0,i+1)&& iClose(NULL,0,i)iClose(NULL,0,i+1)){ possbearsw=2;continue;} else {possbearsw=0;continue;}} if(possbearsw==2){ if(iClose(NULL,0,i)>iOpen(NULL,0,i)&& iClose(NULL,0,i)iClose(NULL,0,i+1)&& iOpen(NULL,0,i)=iClose(NULL,0,i+1)&& iOpen(NULL,0,i)<=iOpen(NULL,0,i+3)&& iClose(NULL,0,i)<=iClose(NULL,0,i+3)){ possbearsw=4; send(bearbreak); patternbox(bearboxcolour); bearsig++;} else{ ObjectSetString(0,name,OBJPROP_TEXT,"Failed"); if(ObjectSet(name,OBJPROP_COLOR,failedboxcolour)) fail++;} possbearsw=0; continue;}} initsw=0; return(0);} int deinit(){ Comment(""); for(int ii=ObjectsTotal()-1;ii>=0;ii--){ string _name=ObjectName(ii); if(StringFind(_name," RFT ")>-1){ ObjectDelete(_name); boxcnt--;}} return(0);} void send(string message){ if(Alerts==none||initsw==1)return; string msg=_Symbol+" "+message; if(initsw==0&&i==0){ if(Alerts==1)Alert(msg); if(Alerts==2)SendNotification(msg); if(Alerts==3){Alert(msg);SendNotification(msg);}} return;} void patternbox(color colour){ datetime firstcandle=iTime(Symbol(),Period(),i+2), lastcandle=iTime(Symbol(),Period(),i); double price1=iOpen(NULL,0,i+2),price2=iClose(NULL,0,i+2); if(possbearsw==4||possbullsw==4){ ObjectSet(name,OBJPROP_TIME2,lastcandle); ObjectSetString(0,name,OBJPROP_TEXT,"Successful"); signal++; return;} name=IntegerToString(boxcnt)+" RFT "+_Symbol+" "+IntegerToString(_Period); if(ObjectCreate(name,OBJ_RECTANGLE,0,firstcandle,price2,lastcandle,price1)){ ObjectSet(name,OBJPROP_COLOR,colour); boxcnt+=1;} return;} void comments(){ string nl="\n"; string comm="Rising Falling Two Pattern"+nl+"Total "+IntegerToString(boxcnt)+nl+"Failed "+IntegerToString(fail)+ nl+"Completed "+IntegerToString(signal)+nl+"Bull "+IntegerToString(bullsig)+nl+"Bear "+IntegerToString(bearsig); Comment(comm); if(possbullsw==3||possbearsw==3){ Comment(comm+nl+"*Possible Pattern*");} if(possbullsw==4||possbearsw==4){ Comment(comm+nl+"*Pattern Completed*");} return;}