New Parabolic Trendline |
//www.aflcode.com Plot(C,"C",1,64); perc=3;//sensitivity calibration x=BarIndex();xx=LastValue(x); t1=LastValue(ValueWhen(PeakBars(H,perc)==0,x)); H1=LastValue(ValueWhen(PeakBars(H,perc)==0,H)); t11=LastValue(ValueWhen(TroughBars(L,perc)==0,x)); H11=LastValue(ValueWhen(TroughBars(L,perc)==0,L)); g=t1>t11; shape=IIf(g,shapeDownArrow*(x==t1),shapeUpArrow*(x==t11)); Color=IIf(g,colorRed,colorBrightGreen); PlotShapes(shape,color); t=IIf(g,x-t1,x-t11); diff1=IIf(g,H1*(xx-t1),H11*(xx-t11)); Lma=LastValue(MA(C,50)); f1=0;f2=IIf(Lma<100,1,0)+3*int(log10(Lma)); fa=0;fb=0;step=f2/100; for(f=f1;f<f2;f=f+step) { parabolic=IIf(g,H1-f*t^2,H11+f*t^2); S1=LastValue(Sum(abs(parabolic-H),xx-t1)); S11=LastValue(Sum(abs(parabolic-L),xx-t11)); diff=IIf(g,S1,S11); if(diff<diff1) { diff1=diff;fa=f; } } for(f=Max(fa-step,0);f<fa+step;f=f+0.01*step) { parabolic=IIf(g,H1-f*t^2,H11+f*t^2); S1=LastValue(Sum(abs(parabolic-H),xx-t1)); S11=LastValue(Sum(abs(parabolic-L),xx-t11)); diff=IIf(g,S1,S11); if(diff<diff1) { diff1=diff;fb=f; } } p=IIf(g,H1-fb*t^2,H11+fb*t^2); Plot(IIf(x>Max(t1,t11),p,-1e10),"",color,1); Title=Name()+", "+WriteIf(t1>t11,"f_desc","f_asc")+"="+WriteVal(fb,1.4); /* Old //The best-fit parabolic after the last peak Plot(C,"C",1,64);perc=5; x=BarIndex();xx=LastValue(x); t1=LastValue(ValueWhen(PeakBars(H,perc)==0,x)); H1=LastValue(ValueWhen(PeakBars(H,perc)==0,H)); PlotShapes(shapeDownArrow*(x==t1),colorRed); t=x-t1;diff1=H1*(xx-t1);f1=0;f2=2;fa=0;fb=0;step=0.01; for(f=f1;f<f2;f=f+step) { parabolic=H1-f*t^2; diff=LastValue(Sum(abs(parabolic-H),xx-t1)); if(diff<diff1) { diff1=diff;fa=f; } } for(f=Max(fa-step,0);f<fa+step;f=f+0.1*step) { parabolic=H1-f*t^2; diff=LastValue(Sum(abs(parabolic-H),xx-t1)); if(diff<diff1) { diff1=diff;fb=f; } } Plot(IIf(x>t1,H1-fb*t^2,-1e10),"",colorRed,1); Plot(IIf(x>t1,H1-Max(fa-step,0)*t^2,-1e10),"",colorBlack,1); Plot(IIf(x>t1,H1-(fa+step)*t^2,-1e10),"",colorBlack,1); Title=Name()+", fa="+WriteVal(fa,1.3)+", fb="+WriteVal(fb,1.3); /* fa is the first approximation [2 decimals] AND fb is the most accurate [3 decimals] The [red] best-fit parabola AND the [black] nearest neighbours appear on the price chart.
Sign up here with your email
ConversionConversion EmoticonEmoticon