//+------------------------------------------------------------------+ //| Golden_section_v2.mq4 | //| Talex | //| tan@gazinter.net | //+------------------------------------------------------------------+ // Very rough English translation by http://translation2.paralink.com/ // Feel free to translate the rest of the comments. #property copyright "Talex" #property link "tan@gazinter.net" #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Lime extern int ExtDepth=8; /* Parameter for ZZ */ /*extern*/ int ExtIndicator=0; /* Defines ? which will search for points for construction of a pattern while only 0 */ extern double ExtDopusk=0.01; /* The parameters of pattern will differ not more than value ExtDopusk */ extern int ExtPoint=3; /* The number of counted points of break, if we make more than 3, then it is possible to construct from any point of break */ extern string ExtComplect="0"; /* This in order to derive several indicators on the graph */ extern int ExtMovePoint=0; /*To move the point of otrisovki of fan from the pitchforks for a quantity of bars indicated of the variable*/ extern bool ExtPitchfork=true; /* Construction with the aid of the pitchforks is used*/ extern bool ExtPitchforkRevers=false; /* Is turned over broom, why? you will ask Vadimcha */ extern bool ExtBack=true; /*If true, then objects will be shown in the background regime */ extern bool ExtFan=true; /* If true, then fibovenik will be brought out to the graph */ extern bool ExtRec=true; /* If true, then rectangle will be brought out to the graph */ extern bool ExtArc=true; /* If true, then fiboarka will be brought out to the graph */ extern bool ExtLeftChannel=false; /* If true, then the lines of channel will be brought out to the graph */ extern bool ExtRightChannel=false; /* If true, then the lines of channel will be brought out to the graph */ extern double ExtFiboLeftChannel=1.618; /* Is established fibo the point of the construction of the left lines */ extern double ExtFiboRightChannel=1.618; /* Is established fibo the point of the construction of the right lines */ extern bool ExtSave=false; /* If true, then constructions will be preserved on the graph */ extern double ExtScale=0; /* The scale of the arc is established */ extern int ExtFanStyle=0; /* Is established the style of the lines of fibovenika */ extern int ExtFanWidth=1; /* Is established the width of the lines of fibovenika */ extern color ExtFanColor=DeepPink; /* the color of fibovenikov */ extern int ExtRecStyle=4; /* The style of the lines of the rectangle is established */ extern int ExtRecWidth=1; /* The width of thêàe lines of the rectangle is established */ extern color ExtRecColor=Yellow; /* The color of the rectangle */ extern int ExtArcStyle=0; /* Is established the style of the lines of fiboarki */ extern int ExtArcWidth=1; /* Is established the width of the lines of fiboarki */ extern color ExtArcColor=Red; /* The color of the arc */ extern int ExtChannelStyle=0; /* The style of the lines of the channel is established */ extern int ExtChannelWidth=1; /* The width of the lines of the channel is established */ extern color ExtChannelColor=Blue; /* The color of the lines of the channel */ extern int ExtPitchforkStyle=0; /* The style of the lines of the pitchforks is established */ extern int ExtPitchforkWidth=1; /* The width of the lines of the pitchforks is established */ extern color ExtPitchforkColor=Lime; /* The color of the pitchforks */ /* Below coordinates of points can be introduced by the knobs */ extern datetime TimePointX=0; /* The time of point X in the size '1980.07.19 12:30' */ extern datetime TimePointA=0; /* The time of point A in the size '1980.07.19 12:30' */ extern datetime TimePointB=0; /* The time of point B in the size '1980.07.19 12:30' */ extern double FiboFanMediana1=0.382; extern double FiboFanMediana2=1.272; extern double Fibo1=0.0; extern double Fibo2=0.382; extern double Fibo3=0.5; extern double Fibo4=0.618; extern double Fibo5=0.786; extern double Fibo6=0.886; extern double Fibo7=1.0; extern double Fibo8=1.272; extern double Fibo9=1.618; extern double Fibo10=2.0; extern double Fibo11=2.618; /* Council - nastroyte for itself color, style, the width of the lines of objects, fibo- levels and remove before the appropriate parameters extern */ double zz[]; //+------------------------------------------------------------------+ //| Custom Indicator initialization function | //+------------------------------------------------------------------+ int init() { IndicatorBuffers(1); SetIndexBuffer(0,zz); SetIndexStyle(0,DRAW_SECTION); SetIndexEmptyValue(0,0.0); return(0); } //+------------------------------------------------------------------+ //| Custom Indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- int i; for(i=0;i<=ExtDepth;i++) { ObjectDelete("FiboFan1"+"_"+i+"_"+ExtComplect+"_"); ObjectDelete("FiboFan2"+"_"+i+"_"+ExtComplect+"_"); ObjectDelete("FiboArc"+"_"+i+"_"+ExtComplect+"_"); ObjectDelete("Rectangle"+"_"+i+"_"+ExtComplect+"_"); ObjectDelete("LeftChannel"+"_"+i+"_"+ExtComplect+"_"); ObjectDelete("RightChannel"+"_"+i+"_"+ExtComplect+"_"); ObjectDelete("LeftLine"+"_"+i+"_"+ExtComplect+"_"); ObjectDelete("RightLine"+"_"+i+"_"+ExtComplect+"_"); ObjectDelete("Pitchfork"+"_"+i+"_"+ExtComplect+"_"); ObjectDelete("Mediana"+"_"+i+"_"+ExtComplect+"_"); } //---- return(0); } //+------------------------------------------------------------------+ //| Custom Indicator iteration function | //+------------------------------------------------------------------+ int start() { int PP[]; int i,j,X,A,B; double R0382=0.382, R0786=0.786, retXB, minret, maxret,AutoScale; double p1,p2,p3,p4,p5,p6,p7; datetime t1,t2,t3,t4,t5,t6,t7; string save=""; double tang; if(ExtSave==true) { save=TimeToStr(TimeLocal(),TIME_DATE|TIME_SECONDS); } minret=1-ExtDopusk; maxret=1+ExtDopusk; ArrayResize(PP,ExtPoint); if(TimePointX!=0 && TimePointA!=0 && TimePointB!=0) { ExtPoint=3; PP[0]=iBarShift(NULL,0,TimePointB); PP[1]=iBarShift(NULL,0,TimePointA); PP[2]=iBarShift(NULL,0,TimePointX); if((High[PP[0]]>High[PP[1]] && High[PP[2]]>High[PP[1]]) || (Low[PP[0]]>Low[PP[1]] && Low[PP[2]]>Low[PP[1]])) { zz[PP[0]]=High[PP[0]]; zz[PP[1]]=Low[PP[1]]; zz[PP[2]]=High[PP[2]]; }else { zz[PP[0]]=Low[PP[0]]; zz[PP[1]]=High[PP[1]]; zz[PP[2]]=Low[PP[2]]; } } else { switch (ExtIndicator) { case 0: {ZZTalex(ExtDepth); break;} /*Here it is possible to add functions according to the calculation of the points of the patterns*/ default:{ZZTalex(ExtDepth); break;} } if(ExtIndicator==0) { j=0; for(i=0;izz[PP[ExtPoint-3]] && zz[PP[ExtPoint-3]]>zz[PP[ExtPoint-2]])) { retXB=(zz[PP[ExtPoint-2]]-zz[PP[ExtPoint-3]])/(zz[PP[ExtPoint-2]]-zz[PP[ExtPoint-1]]+0.000001); if(retXB>=R0382*minret && retXB<=R0786*maxret) { t1=Time[PP[ExtPoint-1]];p1=zz[PP[ExtPoint-1]]; t2=Time[PP[ExtPoint-3]];p2=zz[PP[ExtPoint-3]]; if(2*PP[ExtPoint-3]-PP[ExtPoint-1]<=0) { t3=Time[0]-(2*PP[ExtPoint-3]-PP[ExtPoint-1])*Period()*60;p3=zz[PP[ExtPoint-3]]-(zz[PP[ExtPoint-1]]-zz[PP[ExtPoint-3]]); } else {t3=Time[2*PP[ExtPoint-3]-PP[ExtPoint-1]];p3=zz[PP[ExtPoint-3]]-(zz[PP[ExtPoint-1]]-zz[PP[ExtPoint-3]]);} } } if(ExtScale==0) {/* Calculation AutoScale proposed Vadimcha to it all questions */ AutoScale=MathAbs((p1-p3)*MathPow(10,Digits)/(2*(PP[ExtPoint-1]-PP[ExtPoint-3]))); }else AutoScale=ExtScale; CreateObject(p1,p2,p3,t1,t2,t3,save,AutoScale); } if(ExtPitchfork) { t1=Time[PP[ExtPoint-1]];p1=zz[PP[ExtPoint-1]]; t2=Time[PP[ExtPoint-2]];p2=zz[PP[ExtPoint-2]]; t3=Time[PP[ExtPoint-3]];p3=zz[PP[ExtPoint-3]]; p4=(zz[PP[ExtPoint-2]]+zz[PP[ExtPoint-3]])/2; ObjectCreate("Pitchfork"+"_"+ExtDepth+"_"+ExtComplect+"_"+save,OBJ_PITCHFORK,0,t1,p1,t2,p2,t3,p3); ObjectSet("Pitchfork"+"_"+ExtDepth+"_"+ExtComplect+"_"+save,OBJPROP_BACK,ExtBack); ObjectSet("Pitchfork"+"_"+ExtDepth+"_"+ExtComplect+"_"+save,OBJPROP_COLOR,ExtPitchforkColor); ObjectSet("Pitchfork"+"_"+ExtDepth+"_"+ExtComplect+"_"+save,OBJPROP_STYLE,ExtPitchforkStyle); ObjectSet("Pitchfork"+"_"+ExtDepth+"_"+ExtComplect+"_"+save,OBJPROP_WIDTH,ExtPitchforkWidth); tang=(p1-p4)/(PP[ExtPoint-1]-(PP[ExtPoint-2]-(PP[ExtPoint-2]-PP[ExtPoint-3])/2.0)); t5=t3; p5=p1-tang*(PP[ExtPoint-1]-PP[ExtPoint-3]); ObjectCreate("Mediana"+"_"+ExtDepth+"_"+ExtComplect+"_"+save,OBJ_TREND,0,t1,p1,t5,p5); ObjectSet("Mediana"+"_"+ExtDepth+"_"+ExtComplect+"_"+save,OBJPROP_BACK,ExtBack); ObjectSet("Mediana"+"_"+ExtDepth+"_"+ExtComplect+"_"+save,OBJPROP_COLOR,ExtPitchforkColor); if((p1p2 && p1>p4)) { /* In this case the levels of less than 100% will coincide */ p6=(p5-p3)/FiboFanMediana1+p3;//-tang*ExtMovePoint; if(ObjectGetShiftByValue("Mediana"+"_"+ExtDepth+"_"+ExtComplect+"_"+save,p6)<-100) { Alert("The point for construction of a fan to be too far, try to use greater value for FiboFanMediana1"); } if(ObjectGetShiftByValue("Mediana"+"_"+ExtDepth+"_"+ExtComplect+"_"+save,p6)>0) { t6=Time[ObjectGetShiftByValue("Mediana"+"_"+ExtDepth+"_"+ExtComplect+"_"+save,p6)]+ExtMovePoint*Period()*60; } else t6=Time[0]-ObjectGetShiftByValue("Mediana"+"_"+ExtDepth+"_"+ExtComplect+"_"+save,p6)*Period()*60+ExtMovePoint*Period()*60; } if((p1p4) || (p1>p2 && p1=0) { t6=Time[ObjectGetShiftByValue("Mediana"+"_"+ExtDepth+"_"+ExtComplect+"_"+save,p6)]+ExtMovePoint*Period()*60; } else t6=Time[0]-ObjectGetShiftByValue("Mediana"+"_"+ExtDepth+"_"+ExtComplect+"_"+save,p6)*Period()*60+ExtMovePoint*Period()*60; } if(2*ObjectGetShiftByValue("Mediana"+"_"+ExtDepth+"_"+ExtComplect+"_"+save,p6)-PP[ExtPoint-3]-2*ExtMovePoint>=0) { t7=Time[2*ObjectGetShiftByValue("Mediana"+"_"+ExtDepth+"_"+ExtComplect+"_"+save,p6)-PP[ExtPoint-3]-2*ExtMovePoint]; } else t7=t6+(PP[ExtPoint-3]-ObjectGetShiftByValue("Mediana"+"_"+ExtDepth+"_"+ExtComplect+"_"+save,p6))*Period()*60+ExtMovePoint*Period()*60; /* the correction of price p6*/ p6=ObjectGetValueByShift("Mediana"+"_"+ExtDepth+"_"+ExtComplect+"_"+save,ObjectGetShiftByValue("Mediana"+"_"+ExtDepth+"_"+ExtComplect+"_"+save,p6)); p7=2*p6-p3; //Print("t6=",TimeToStr(t6,TIME_DATE),"; p6=",p6,"; NbarMediana=",ObjectGetShiftByValue("Mediana"+"_"+ExtDepth+"_"+ExtComplect+"_"+save,p6)); //Print("t3=",TimeToStr(t3,TIME_DATE),"; p3=",p3,"; t7=",TimeToStr(t7,TIME_DATE),"; p7=",p7); if(p1==p4) { Alert("Fan to construct it is impossible."); p3=0;p6=0;p7=0;t3=0;t6=0;t7=0; } if(ExtScale==0) { AutoScale=MathAbs((p7-p3)*MathPow(10,Digits)/(2*(PP[ExtPoint-3]-ObjectGetShiftByValue("Mediana"+"_"+ExtDepth+"_"+ExtComplect+"_"+save,p6)))); }else AutoScale=ExtScale; CreateObject(p3,p6,p7,t3,t6,t7,save,AutoScale); } //---- //---- return(0); } /*------------------------------------------------------------------------------------------------------------------------------------+ | ZigZag_.Talex, searches for the points of break on the graph. A quantity of points is assigned by the external parameter ExtPoint | +------------------------------------------------------------------------------------------------------------------------------------*/ void ZZTalex(int n) { /* Variables */ int i,j,k,zzbarlow,zzbarhigh,curbar,curbar1,curbar2,EP,Mbar[]; double curpr,Mprice[]; bool flag,fd; static int endbar; static double endpr; /* The beginning */ for(i=0;i<=Bars-1;i++) {zz[i]=0.0;} EP=ExtPoint; zzbarlow=iLowest(NULL,0,MODE_LOW,n,0); zzbarhigh=iHighest(NULL,0,MODE_HIGH,n,0); if(zzbarlowzzbarhigh) {curbar=zzbarhigh; curpr=High[zzbarhigh];} if(zzbarlow==zzbarhigh){curbar=zzbarlow;curpr=funk1(zzbarlow, n);} ArrayResize(Mbar,ExtPoint); ArrayResize(Mprice,ExtPoint); j=0; endpr=curpr; endbar=curbar; Mbar[j]=curbar; Mprice[j]=curpr; EP--; if(curpr==Low[curbar]) flag=true; else flag=false; i=curbar+1; while(EP>0) { if(flag) { while(i<=Bars-1) { curbar1=iHighest(NULL,0,MODE_HIGH,n,i); curbar2=iHighest(NULL,0,MODE_HIGH,n,curbar1); if(curbar1==curbar2){curbar=curbar1;curpr=High[curbar];flag=false;i=curbar+1;j++;break;} else i=curbar2; } Mbar[j]=curbar; Mprice[j]=curpr; EP--; } if(EP==0) break; if(!flag) { while(i<=Bars-1) { curbar1=iLowest(NULL,0,MODE_LOW,n,i); curbar2=iLowest(NULL,0,MODE_LOW,n,curbar1); if(curbar1==curbar2){curbar=curbar1;curpr=Low[curbar];flag=true;i=curbar+1;j++;break;} else i=curbar2; } Mbar[j]=curbar; Mprice[j]=curpr; EP--; } } /* The correction of the apexes */ if(Mprice[0]==Low[Mbar[0]])fd=true; else fd=false; for(k=0;k<=ExtPoint-1;k++) { if(k==0) { if(fd==true) { Mbar[k]=iLowest(NULL,0,MODE_LOW,Mbar[k+1]-Mbar[k],Mbar[k]);Mprice[k]=Low[Mbar[k]];endbar=ExtDepth; } if(fd==false) { Mbar[k]=iHighest(NULL,0,MODE_HIGH,Mbar[k+1]-Mbar[k],Mbar[k]);Mprice[k]=High[Mbar[k]];endbar=ExtDepth; } } if(k