John, IIR would not be that convenient . In the att. gif I have plotted 4 representative lines for k=0.1 to 0.4 [it is hard to need more...]. The white line [k=0.1] seems to match the best-fit parabolic. The problem is that k=0.1 is not ideal in other trend sequences. Except if create the best-fit IIR... But, this is another [probably interesting] story. PS1: The AFL code for the lower IIR lines is function IIR2( input, f0, f1, f2 ) { result[ 0 ] = input[ 0 ];result[ 1 ] = input[ 1 ]; for( i = 2; i < BarCount; i++ ) { result[ i ] = f0 * input[ i ]+f1 * result[ i - 1 ]+ f2 * result[ i - 2 ]; } return result; } Plot(C,"C",1,64); C1=L; for(K=0.1;K<0.5;K=K+0.1) { RED=IIR2( C1, 0.3, 1.2+K, -0.5-K); Plot(IIf(DateNum()>=1040831,RED,Null),"\n["+K+"]",10*K+1,8); } and may produce a best-fit IIR2 for Lows [respectively Highs] for further study. I will take a look by the week-end, the sea is still warm in the Aegean. PS2. ...Aristotelians before Newton... Wow !!I wouldnt like to be in their [miserable] place !! [BTW, Isaac Barrows, the teacher on Isaac Newton, was an Aristotelian too, but it was clever enough to give the proper hints to his young student...]
The last best-fit IIR2 does not 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 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. [^VXO graph] If minor troughs[peaks] have already occurred, then the correlation does not make sense, the IIR2 in no more monotonous. [QQQ graph]
I noticed some wrapping problems in the code. See http://finance.groups.yahoo.com/group/amibroker/message/70154 for a better response.
The whole Doji at A [Sept28] was out of the descending parabolic. It was a clear indication for a probable change of the trend. The trading hint was to Buy at next bar Open. The result is already interesting.
You may see the historical values of the parabolic coefficient Fvar at http://finance.groups.yahoo.com/group/amibroker/message/71097 The "normal" behavior is a quasi-exponential line. The exceptions are interesting, they occur when the trend is reinforced [point R]
This Sept29 ^NDX Buy signal was just great: For the whole N100 database, the % gain was negative for 6 stocks and positive for the rest 95. Check, for the n=1 last quotations, with Filter=1; AddColumn(100*(-1+C/Ref(O,-2)),"%gain",1.2); 45 stocks were above +5% in 3 single days. 12 stocks exceeded the +10%.
The whole candle of the ^NDX Oct5 session was on the right side of the parabolic. It was the profit taking time. The N100 market behavior was Ticker %gain SEBL 26.03 VRTS 20.93 CTXS 17.11 MERQ 16.03 PSFT 15.30 CPWR 14.95 MRVL 14.35 NTAP 12.58 MEDI 10.55 KLAC 10.06 SANM 9.79 GRMN 9.73 NVLS 9.55 VRSN 9.40 BEAS 9.30 NXTL 9.09 SNDK 8.88 BRCM 8.71 NVDA 8.65 MOLX 8.53 ATYT 8.45 QCOM 8.45 SUNW 8.35 MXIM 8.32 LRCX 8.22 MCHP 7.96 CHKP 7.88 ISIL 7.87 INTC 7.84 ORCL 7.77 ALTR 7.71 XLNX 7.43 APCC 6.96 GILD 6.93 CMVT 6.67 YHOO 6.65 JNPR 6.60 CMCSA 6.52 QLGC 6.45 ROST 6.41 FISV 6.40 SBUX 6.35 AMAT 6.25 INTU 6.12 SYMC 5.95 CHRW 5.59 ADBE 5.47 PCAR 5.44 EXPD 5.38 PAYX 5.25 BBBY 5.21 ^NDX 5.19 CSCO 5.18 CDWC 5.13 LLTC 4.98 APOL 4.68 XRAY 4.65 COST 4.62 SNPS 4.48 FLEX 4.39 SSCC 4.38 CTAS 4.28 SPLS 4.18 MSFT 4.11 KMRT 3.90 EBAY 3.86 AMZN 3.83 AAPL 3.80 BMET 3.68 PDCO 3.35 TLAB 3.21 BIIB 3.20 PIXR 2.76 JDSU 2.45 FAST 2.30 WFMI 2.26 GNTX 2.18 LVLT 1.90 DELL 1.75 LNCR 1.61 DISH 1.50 CEPH 1.20 SIAL 1.14 FHCC 0.95 PETM 0.69 LAMR 0.62 IVGN 0.61 ESRX 0.52 MLNM 0.46 DLTR 0.33 AMGN -0.12 PTEN -0.41 CECO -0.46 ERTS -0.59 TEVA -1.23 RIMM -2.82 GENZ -3.11 IACI -3.48 HSIC -4.33 RYAAY -6.25 CHIR -14.71 for this movement.
I tried the code that you posted on 9/3 but I get the following error: Line 17, Column 12: 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 { -----------^ Error 23. Syntax error What could be the problem? Alan