//+------------------------------------------------------------------+ //| Angulation.mq4 | //| Bohdan Kasyanenko | //| https://login.mql5.com/en/users/kasyanenko| //+------------------------------------------------------------------+ #property copyright "2014, Bohdan Kasyanenko" #property link "https://login.mql5.com/en/users/kasyanenko" #property strict #property indicator_chart_window enum AB { J =0, //Only Jaws JT=1, //Average (Jaws+Teeth) }; extern string Comment1 = ""; //Visualisation extern bool Show_Angulation = true; //-> Show angulation lines extern bool Show_degree = true; //-> Show info extern string Comment2 = ""; //Angulation settings extern double Min_angle = 22.0; //-> Minimal angle to filter extern int Bars_to_find_Angulation = 20; //-> Bars to find angulation input AB Base_of_comparison = JT; //-> Base of comparison extern int VHRatio = 60; //-> Vertical-Horizontal ratio extern string Comment4 = ""; //Colors extern color AngClrUp = Green; //-> Color of Angulation lines (Buy) extern color AngClrDown = Red; //-> Color of Angulation lines (Sell) int T1=0, T2=0, i, k, X, Y; int style=0; double P1=0, P2=0, P3=0; double Alpha; double Pi=3.14159265; bool crossup=0,crossdown=0; datetime time1,time2; //+-----------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- TODO: add your code here ObjectDelete("Angulation AB"); ObjectDelete("Angulation AC"); Comment(""); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { if(Show_Angulation) { i=0; while(i=Alligator(i) ) { k=i; break; } i++; } if(k>0) { if(Low[k-1]>Alligator(k-1) && High[k-1]>Alligator(k-1)) {crossup=1;} if(Low[k-1]k) { crossup=0; crossdown=0; } if(crossup || crossdown) { T2=k; if(Base_of_comparison==J) { P1=NormalizeDouble(Alligator(T2),Digits); P2=NormalizeDouble(Alligator(T1),Digits); } if(Base_of_comparison==JT) { P1=NormalizeDouble((Alligator(T2)+iAlligator(NULL,0,13,8,8,5,5,3,MODE_SMMA,PRICE_MEDIAN,MODE_GATORTEETH,T2))/2,Digits); P2=NormalizeDouble((Alligator(T1)+iAlligator(NULL,0,13,8,8,5,5,3,MODE_SMMA,PRICE_MEDIAN,MODE_GATORTEETH,T1))/2,Digits); } if(crossup) { P3=NormalizeDouble(Low[T1],Digits); } if(crossdown) { P3=NormalizeDouble(High[T1],Digits); } Alpha=Angle(P1,P2,P3,T1,T2); time2=iTime(NULL,0,T1); time1=iTime(NULL,0,T2); if(Alpha=Min_angle) style=0; CreateTL("Angulation AB",time1,P1,time2,P2,0,style,AngClrDown,0); CreateTL("Angulation AC",time1,P1,time2,P3,0,style,AngClrDown,0); if(Show_degree) Comment("\n",NormalizeDouble(Alpha,0)," degrees","\n","p1=",P1," p2=",P2," p3=",P3," t1=",T1," t2=",T2); else Comment(""); } if(!crossup && !crossdown) {T2=k; Alpha=0; P1=0; P2=0; P3=0;} } return(0); } //+------------------------------------------------------------------+ //| Alligator | //+------------------------------------------------------------------+ double Alligator(int p) { return(iAlligator(NULL,0,13,8,8,5,5,3,MODE_SMMA,PRICE_MEDIAN,MODE_GATORJAW,p)); } //+------------------------------------------------------------------+ //| Angle | //+------------------------------------------------------------------+ double Angle(double p1,double p2,double p3,int t1,int t2) { Alpha=NormalizeDouble(MathAbs((MathArctan((p3-p1)*MathPow(10.0,Digits)*VHRatio/100/(t2-t1))-MathArctan((p2-p1)*MathPow(10.0,Digits)*VHRatio/100/(t2-t1)))*180/Pi),2); return (Alpha); } //+------------------------------------------------------------------+ //| CreateTL | //+------------------------------------------------------------------+ void CreateTL(string name,datetime t1,double p1,datetime t2,double p2,int Width,int stl,color clr,bool ray) { if(ObjectFind(name)<0) ObjectCreate(name,OBJ_TREND,0,0,0,0,0); ObjectSet(name,OBJPROP_TIME1,t1); ObjectSet(name,OBJPROP_PRICE1,p1); ObjectSet(name,OBJPROP_TIME2,t2); ObjectSet(name,OBJPROP_PRICE2,p2); ObjectSet(name,OBJPROP_COLOR,clr); ObjectSet(name,OBJPROP_RAY,ray); ObjectSet(name,OBJPROP_STYLE,stl); ObjectSet(name,OBJPROP_WIDTH,Width); } //+------------------------------------------------------------------+