[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Parabolic vs IIR2



PureBytes Links

Trading Reference Links

See the explanatory graphs in
http://www.elitetrader.com/vb/showthread.php?threadid=37727
Dimitris
--- In amibroker@xxxxxxxxxxxxxxx, "Dimitris Tsokakis" <TSOKAKIS@xxxx> 
wrote:
> The last best-fit IIR2 does not always give the solutions the last 
best-fit parabolic can give.
> In the following code I calculate the IIR2 coefficient K for the
> IIR2( C1, 0.3, 1.2+K, -0.5-K);
> in a reasonable range from -0.5 to +0.5, keeping the af0=0.3 to 
avoid undesirable oscillations.
> 
> // The last best-fit parabolic vs the best-fit IIR2, by D. 
Tsokakis, Sept2004
> 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);
> // 1. THE LAST BEST-FIT PARABOLIC
> 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,8);
> //THE LAST BEST-FIT IIR2
> function IIR2( input, af0, af1, af2 )
> {
>   result[ 0 ] = input[ 0 ];result[ 1 ] = input[ 1 ]; 
>   for( i = 2; i < BarCount; i++ )
>   {
>     result[ i ] = af0 * input[ i ] + af1 * result[ i - 1 ] + af2 * 
result[ i - 2 ]; 
>   }
>   return result;
> }
> PER=IIf(g,xx-t1,xx-t11);
> C1=IIf(g,H,L);DIF1=10000;
> K0=-0.5;K00=0.5;STEP=0.01;
> for(K=K0;K<K00;K=K+STEP)
> {
> RED=IIR2( C1, 0.3, 1.2+K, -0.5-K);
> dif=LastValue(Sum(abs(RED-C1),PER));
> if(DIF<DIF1)
> {
> K1=K;
> DIF1=DIF;
> }
> }
> BESTFIT_IIR2=IIR2(C1,0.3,1.2+K1,-0.5-K1);
> Plot(IIf(X>=Max(t1,t11),BESTFIT_IIR2,Null),"",colorYellow,8);
> Title=Name()+
> ", "+WriteIf(t1>t11,"f_desc","f_asc")+"="+
> WriteVal(fb,1.4)+",K_"+WriteIf(t1>t11,"desc","asc")+"="+WriteVal
(k1);
> GraphXSpace=3;
> 
> If the stock is still ascending[descending] since the last trough
[peak], the comparison is probably interesting.
> If minor troughs[peaks] have already occurred, then the correlation 
does not make sense, the IIR2 in no more monotonous.
> Dimitris Tsokakis
> 
> [Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/