Has anyone already translated this Amibroker AFL code into EFS?
The code is posted and discussed here:
The author states: The following AFL code will plot the best-fit parabolic from the last Peak[or Trough] till now. The boundary parabolas will also be plotted, in order to ensure the loop range. I think it is more useful than the parabolic SAR. The most important for the best-fit parabolic method is the quick exit/profit taking. The exit signal occurs BEFORE the upcoming peak/trough, when the first candle is on the right side of the parabola. The exit is premature sometimes, but, it is exactly the profit taking time.
// The last best-fit parabolic trendline, 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);
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")+"="+WriteVa l
(fb,1.4);
Code notes by author:
1. Note that perc is used for peaks/troughs recognition through zig() function. This will introduce a delay, a peak will be recognized as a peak when the price will drop by perc%. When you increase perc, you need more bars to recognize the last peak/trough. I use perc=3 to perc=5 for EOD.
2. Fvar is the parabolic coefficient per bar. It is high in the beginning and then becomes smaller as the days go by. Sometimes it may go up again, when the trend becomes stronger.
Modification Options:
Mod 1:
At the end of the code, add:
Filter = IIf ( g , L > p , H < p ) ;
AddColumn ( g , " g " , 1.0 ) ;
and explore for the n=1 last quotations. The result will give the stocks with the entire last candle above [below] the descending [ascending] best-fit parabolic. g is equal to 1 for the descending parabolic and it is equal to 0 for the ascending one.
Mod 2:
Now, if you want to catch a [Close, parabolic] cross for the very last bar, use:
Filter = IIf ( g , Cross ( C , p ) , Cross ( p , C ) ) ;
AddColumn ( g , " g " , 1.0 ) ;
Mod 3:
To give the bars since the last peak/trough t and the last ROC to estimate the first "jump" after the cross.
Filter = IIf ( g , Cross ( C , p ) , Cross ( p , C ) ) ;
AddColumn ( g , " g " , 1.0 ) ;
AddColumn ( t , " t " , 1.0 ) ;
AddColumn ( ROC ( C , 1 ) , "ROC" , 1.2 ) ;
The t is important to judge the probable change of the trend. If the price cross the best-fit parabolic after 10 or more bars, then the trend has more reasons to change. The best-fit parabolic gives a clear picture for the whole market. Note also that the delay of this whole-market-signal is insignificant.
The code is posted and discussed here:
The author states: The following AFL code will plot the best-fit parabolic from the last Peak[or Trough] till now. The boundary parabolas will also be plotted, in order to ensure the loop range. I think it is more useful than the parabolic SAR. The most important for the best-fit parabolic method is the quick exit/profit taking. The exit signal occurs BEFORE the upcoming peak/trough, when the first candle is on the right side of the parabola. The exit is premature sometimes, but, it is exactly the profit taking time.
// The last best-fit parabolic trendline, 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);
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")+"="+WriteVa l
(fb,1.4);
Code notes by author:
1. Note that perc is used for peaks/troughs recognition through zig() function. This will introduce a delay, a peak will be recognized as a peak when the price will drop by perc%. When you increase perc, you need more bars to recognize the last peak/trough. I use perc=3 to perc=5 for EOD.
2. Fvar is the parabolic coefficient per bar. It is high in the beginning and then becomes smaller as the days go by. Sometimes it may go up again, when the trend becomes stronger.
Modification Options:
Mod 1:
At the end of the code, add:
Filter = IIf ( g , L > p , H < p ) ;
AddColumn ( g , " g " , 1.0 ) ;
and explore for the n=1 last quotations. The result will give the stocks with the entire last candle above [below] the descending [ascending] best-fit parabolic. g is equal to 1 for the descending parabolic and it is equal to 0 for the ascending one.
Mod 2:
Now, if you want to catch a [Close, parabolic] cross for the very last bar, use:
Filter = IIf ( g , Cross ( C , p ) , Cross ( p , C ) ) ;
AddColumn ( g , " g " , 1.0 ) ;
Mod 3:
To give the bars since the last peak/trough t and the last ROC to estimate the first "jump" after the cross.
Filter = IIf ( g , Cross ( C , p ) , Cross ( p , C ) ) ;
AddColumn ( g , " g " , 1.0 ) ;
AddColumn ( t , " t " , 1.0 ) ;
AddColumn ( ROC ( C , 1 ) , "ROC" , 1.2 ) ;
The t is important to judge the probable change of the trend. If the price cross the best-fit parabolic after 10 or more bars, then the trend has more reasons to change. The best-fit parabolic gives a clear picture for the whole market. Note also that the delay of this whole-market-signal is insignificant.
Comment