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

Re: [amibroker] Re: Ehler's Instantaneous Trendline & Sinewave Indicator - S&C issue May 2000



PureBytes Links

Trading Reference Links

Thanks for your comments. I went through the code and had to change
radians to degrees , back and forth a couple of times. Now the graphs
look similar to what they look like in the article. Still, if someone
can compare with MetaStock , it will give confirmation. Then I can put
in the AFL library.

Here is the code.

Mohan

DIMITRIS TSOKAKIS wrote:
> 
> Mohan,
> As I see you keep degs in following calculations, so it would be
> better
> to change p1 once.
> Instead of
> p1 = atan( abs(quad+Ref(quad,-1) ) / abs(inphase+Ref(inphase,-1) ) );
> 
> you may write
> 
> pp1=atan( abs(quad+Ref(quad,-1) ) / abs(inphase+Ref(inphase,-1) ) );
> p1=180*pp1/(4*atan(1));
> 
> [where atan(1) is equal to pi/4, hence pi=4*atan(1)]
> Now the new p1 is in degs and will not disturb following calculations.
> Dimitris Tsokakis
>
/* Hilbert Study Instantaneous Trendline & SineWave Indicator */

EnableScript("VBScript");

PI= 4*atan(1);

TWO_PI = 2 * PI;

pr = (H+L)/2;

value1=((H+L)/2) - Ref(((H+L)/2),-6);

value2= Ref(value1,-3);

value3=0.75*(value1-Ref(value1,-6)) +

0.25*(Ref(value1,-2)-Ref(value1,-4));

<%

value1 = AFL("Value1")

value2 = AFL("Value2")

value3 = AFL("Value3")

Close = AFL("Close")

inphase = Close

quad = inphase

Call Setup()

Function Setup()

for i = 1 to Ubound(Close)

inphase(i) = 0.33 * value2(i) + (0.67 * inphase(i-1) ) 

quad(i) = 0.20 * value3(i) + ( 0.8 * quad(i-1) )

next

End Function

AFL.Var("inphase") = inphase

AFL.Var("quad") = quad

%>

pp1 = atan( abs(quad+Ref(quad,-1) ) / abs(inphase+Ref(inphase,-1) ) );

p1=180*pp1/(4*atan(1)); /* Converted to degrees */

phase = IIf(inphase<0 AND quad>0, 180-p1, 

IIf(inphase<0 AND quad<0, 180+p1,

IIf(inphase>0 AND quad<0, 360-p1,p1)));

dp = IIf(Ref(phase,-1)<90 AND phase>270,

360+Ref(phase,-1)-phase,Ref(phase,-1)-phase);

dp2 = IIf(dp < 1, 1, IIf(dp > 60, 60, dp));

//Graph0 = dp2;

HilbertCyclePeriod1a = dp2; // dp2 is in degrees

value = dp2;

HCycleCount1a=

IIf(Sum(value,6)>=360 AND Sum(value,5)<360 ,6,0) +

IIf(Sum(value,7)>=360 AND Sum(value,6)<360 ,7,0) +

IIf(Sum(value,8)>=360 AND Sum(value,7)<360 ,8,0) +

IIf(Sum(value,9)>=360 AND Sum(value,8)<360 ,9,0) +

IIf(Sum(value,10)>=360 AND Sum(value,9)<360 ,10,0) +

IIf(Sum(value,11)>=360 AND Sum(value,10)<360 ,11,0) +

IIf(Sum(value,12)>=360 AND Sum(value,11)<360 ,12,0) +

IIf(Sum(value,13)>=360 AND Sum(value,12)<360 ,13,0) +

IIf(Sum(value,14)>=360 AND Sum(value,13)<360 ,14,0) +

IIf(Sum(value,15)>=360 AND Sum(value,14)<360 ,15,0);

HCycleCount2a =

IIf(Sum(value,16)>=360 AND Sum(value,15)<360 ,16,0) +

IIf(Sum(value,17)>=360 AND Sum(value,16)<360 ,17,0) +

IIf(Sum(value,18)>=360 AND Sum(value,17)<360 ,18,0) +

IIf(Sum(value,19)>=360 AND Sum(value,18)<360 ,19,0) +

IIf(Sum(value,20)>=360 AND Sum(value,19)<360 ,20,0) +

IIf(Sum(value,21)>=360 AND Sum(value,20)<360 ,21,0) +

IIf(Sum(value,22)>=360 AND Sum(value,21)<360 ,22,0) +

IIf(Sum(value,23)>=360 AND Sum(value,22)<360 ,23,0) +

IIf(Sum(value,24)>=360 AND Sum(value,23)<360 ,24,0) +

IIf(Sum(value,25)>=360 AND Sum(value,24)<360 ,25,0);

HCyclecount3a = 

IIf(Sum(value,26)>=360 AND Sum(value,25)<360 ,26,0) +

IIf(Sum(value,27)>=360 AND Sum(value,26)<360 ,27,0) +

IIf(Sum(value,28)>=360 AND Sum(value,27)<360 ,28,0) +

IIf(Sum(value,29)>=360 AND Sum(value,28)<360 ,29,0) +

IIf(Sum(value,30)>=360 AND Sum(value,29)<360 ,30,0) +

IIf(Sum(value,31)>=360 AND Sum(value,30)<360 ,31,0) +

IIf(Sum(value,32)>=360 AND Sum(value,31)<360 ,32,0) +

IIf(Sum(value,33)>=360 AND Sum(value,32)<360 ,33,0) +

IIf(Sum(value,34)>=360 AND Sum(value,33)<360 ,34,0) +

IIf(Sum(value,35)>=360 AND Sum(value,34)<360 ,35,0);

c1= HCycleCount1a + HCycleCount2a + HCycleCount3a; // degrees

/* Graph0 = HCyclecount1a;

Graph1 = HCyclecount2a; 

Graph2 = HCyclecount3a;

Graph0Style=Graph1Style=Graph2Style=5;*/

//Graph0 = C1;

<%

c1 = AFL("c1")

c2 = c1

c3 = c1

for i = 1 to Ubound(c1)

IF c1(i) = 0 then c2(i) = c2(i-1) else c2(i) = c1(i) 

c3(i) = 0.25*c2(i) + 0.75*c3(i-1) 

next

AFL.Var("c3") = c3

%>

HilbertCyclePeriodFa = c3; // degrees

pd = int( c3); //degrees

//Graph0 = pd;

/* Converted the pd value in degrees to radians . the original formula in MetaStock is of
(Cos(360*(1/pd))*Ref(pr,-1) */

HipSum1=

(cos(0)*pr) + (cos( TWO_PI*(1/pd))* Ref(pr,-1)) +

(cos( TWO_PI*(2/pd))* Ref(pr,-2)) +

(cos( TWO_PI*(3/pd))* Ref(pr,-3)) +

(cos( TWO_PI*(4/pd))* Ref(pr,-4)) +

(cos( TWO_PI*(5/pd))* Ref(pr,-5)) +

IIf(pd>6, cos( TWO_PI*(6/pd))* Ref(pr,-6) ,0) +

IIf(pd>7, cos( TWO_PI*(7/pd))* Ref(pr,-7) ,0) +

IIf(pd>8, cos( TWO_PI*(8/pd))* Ref(pr,-8) ,0) +

IIf(pd>9, cos( TWO_PI*(9/pd))* Ref(pr,-9) ,0) +

IIf(pd>10, cos( TWO_PI*(10/pd))* Ref(pr,-10) ,0) +

IIf(pd>11, cos( TWO_PI*(11/pd))* Ref(pr,-11) ,0) +

IIf(pd>12, cos( TWO_PI*(12/pd))* Ref(pr,-12) ,0) +

IIf(pd>13, cos( TWO_PI*(13/pd))* Ref(pr,-13) ,0) +

IIf(pd>14, cos( TWO_PI*(14/pd))* Ref(pr,-14) ,0) ;

HipSum2=

IIf(pd>15, cos( TWO_PI*(15/pd))* Ref(pr,-15) ,0) +

IIf(pd>16, cos( TWO_PI*(16/pd))* Ref(pr,-16) ,0) +

IIf(pd>17, cos( TWO_PI*(17/pd))* Ref(pr,-17) ,0) +

IIf(pd>18, cos( TWO_PI*(18/pd))* Ref(pr,-18) ,0) +

IIf(pd>19, cos( TWO_PI*(19/pd))* Ref(pr,-19) ,0) +

IIf(pd>20, cos( TWO_PI*(20/pd))* Ref(pr,-20) ,0) +

IIf(pd>21, cos( TWO_PI*(21/pd))* Ref(pr,-21) ,0) +

IIf(pd>22, cos( TWO_PI*(22/pd))* Ref(pr,-22) ,0) +

IIf(pd>23, cos( TWO_PI*(23/pd))* Ref(pr,-23) ,0) +

IIf(pd>24, cos( TWO_PI*(24/pd))* Ref(pr,-24) ,0) ;

HipSum3=

IIf(pd>25, cos( TWO_PI*(25/pd))* Ref(pr,-25) ,0) +

IIf(pd>26, cos( TWO_PI*(26/pd))* Ref(pr,-26) ,0) +

IIf(pd>27, cos( TWO_PI*(27/pd))* Ref(pr,-27) ,0) +

IIf(pd>28, cos( TWO_PI*(28/pd))* Ref(pr,-28) ,0) +

IIf(pd>29, cos( TWO_PI*(29/pd))* Ref(pr,-29) ,0) +

IIf(pd>30, cos( TWO_PI*(30/pd))* Ref(pr,-30) ,0) +

IIf(pd>31, cos( TWO_PI*(31/pd))* Ref(pr,-31) ,0) +

IIf(pd>32, cos( TWO_PI*(32/pd))* Ref(pr,-32) ,0) +

IIf(pd>33, cos( TWO_PI*(33/pd))* Ref(pr,-33) ,0) +

IIf(pd>34, cos( TWO_PI*(34/pd))* Ref(pr,-34) ,0) ;

HrpSum1=

(sin(0)*pr) + (sin( TWO_PI*(1/pd))* Ref(pr,-1)) +

(sin( TWO_PI*(2/pd))* Ref(pr,-2)) +

(sin( TWO_PI*(3/pd))* Ref(pr,-3)) +

(sin( TWO_PI*(4/pd))* Ref(pr,-4)) +

(sin( TWO_PI*(5/pd))* Ref(pr,-5)) +

IIf(pd>6, sin( TWO_PI*(6/pd))* Ref(pr,-6) ,0) +

IIf(pd>7, sin( TWO_PI*(7/pd))* Ref(pr,-7) ,0) +

IIf(pd>8, sin( TWO_PI*(8/pd))* Ref(pr,-8) ,0) +

IIf(pd>9, sin( TWO_PI*(9/pd))* Ref(pr,-9) ,0) +

IIf(pd>10, sin( TWO_PI*(10/pd))* Ref(pr,-10) ,0) +

IIf(pd>11, sin( TWO_PI*(11/pd))* Ref(pr,-11) ,0) +

IIf(pd>12, sin( TWO_PI*(12/pd))* Ref(pr,-12) ,0) +

IIf(pd>13, sin( TWO_PI*(13/pd))* Ref(pr,-13) ,0) +

IIf(pd>14, sin( TWO_PI*(14/pd))* Ref(pr,-14) ,0) ;

HrpSum2=

IIf(pd>15, sin( TWO_PI*(15/pd))* Ref(pr,-15) ,0) +

IIf(pd>16, sin( TWO_PI*(16/pd))* Ref(pr,-16) ,0) +

IIf(pd>17, sin( TWO_PI*(17/pd))* Ref(pr,-17) ,0) +

IIf(pd>18, sin( TWO_PI*(18/pd))* Ref(pr,-18) ,0) +

IIf(pd>19, sin( TWO_PI*(19/pd))* Ref(pr,-19) ,0) +

IIf(pd>20, sin( TWO_PI*(20/pd))* Ref(pr,-20) ,0) +

IIf(pd>21, sin( TWO_PI*(21/pd))* Ref(pr,-21) ,0) +

IIf(pd>22, sin( TWO_PI*(22/pd))* Ref(pr,-22) ,0) +

IIf(pd>23, sin( TWO_PI*(23/pd))* Ref(pr,-23) ,0) +

IIf(pd>24, sin( TWO_PI*(24/pd))* Ref(pr,-24) ,0) ;

HrpSum3=

IIf(pd>25, sin( TWO_PI*(25/pd))* Ref(pr,-25) ,0) +

IIf(pd>26, sin( TWO_PI*(26/pd))* Ref(pr,-26) ,0) +

IIf(pd>27, sin( TWO_PI*(27/pd))* Ref(pr,-27) ,0) +

IIf(pd>28, sin( TWO_PI*(28/pd))* Ref(pr,-28) ,0) +

IIf(pd>29, sin( TWO_PI*(29/pd))* Ref(pr,-29) ,0) +

IIf(pd>30, sin( TWO_PI*(30/pd))* Ref(pr,-30) ,0) +

IIf(pd>31, sin( TWO_PI*(31/pd))* Ref(pr,-31) ,0) +

IIf(pd>32, sin( TWO_PI*(32/pd))* Ref(pr,-32) ,0) +

IIf(pd>33, sin( TWO_PI*(33/pd))* Ref(pr,-33) ,0) +

IIf(pd>34, sin( TWO_PI*(34/pd))* Ref(pr,-34) ,0) ;

pd1 = int(C3);



HTLSum1=

IIf(pd1==6, MA(pr,8),0) +

IIf(pd1==7, MA(pr,9) ,0) +

IIf(pd1==8, MA(pr, 10) ,0) +

IIf(pd1==9, MA(pr, 11) ,0) +

IIf(pd1==10, MA(pr, 12) ,0) +

IIf(pd1==11, MA(pr, 13) ,0) +

IIf(pd1==12, MA(pr, 14) ,0) +

IIf(pd1==13, MA(pr, 15) ,0) +

IIf(pd1==14, MA(pr, 16) ,0) +

IIf(pd1==15, MA(pr, 17) ,0) ;

HTLSum2=

IIf(pd==16, MA(pr,18),0) +

IIf(pd==17, MA(pr,19) ,0) +

IIf(pd==18, MA(pr, 20) ,0) +

IIf(pd==19, MA(pr, 21) ,0) +

IIf(pd==20, MA(pr, 22) ,0) +

IIf(pd==21, MA(pr, 23 ),0) +

IIf(pd==22, MA(pr, 24 ),0) +

IIf(pd==23, MA(pr, 25) ,0) +

IIf(pd==24, MA(pr, 26) ,0) +

IIf(pd==25, MA(pr, 27 ),0) ;

HTLSum3=

IIf(pd==26, MA(pr,28),0) +

IIf(pd==27, MA(pr,29) ,0) +

IIf(pd==28, MA(pr, 30) ,0) +

IIf(pd==29, MA(pr, 31) ,0) +

IIf(pd==30, MA(pr, 32) ,0) +

IIf(pd==31, MA(pr, 33) ,0) +

IIf(pd==32, MA(pr, 34),0) +

IIf(pd==33, MA(pr, 35) ,0) +

IIf(pd==34, MA(pr, 36) ,0) +

IIf(pd==35, MA(pr, 37 ),0) ;

TR = HTLSum1 + HTLSum2 + HTLSum3;

//Graph0= TR;

<%

pr = AFL("pr")

ZL = pr

for i =4 to Ubound(pr)

ZL(i) = 0.33*(pr(i) + (0.5*(pr(i) - pr(i -3)))) + 0.67 * ZL(i-1)

next

AFL.Var("ZL") = ZL

%>

graphXspace = 1;

/*Graph0 = Close;

Graph1 =TR;

Graph2 =ZL;

Graph0Style=64;

Graph1Style=Graph2Style=4;*/

/* SineWave Indicator */

cp = c3; // degrees

ip = HipSum1 + HipSum2 + HipSum3 ; // a number

rp = HrpSum1 + HrpSum2 + HrpSum3 ; // a number

dc1= IIf(abs(ip)>0.001, atan(rp/ip)*180/3.1416, 90* IIf(rp>=0,1,-1));

dc2= IIf(pd<30 and cp>0, dc1 + ((6.818/cp-0.227)*360),dc1);

dc3= IIf(ip<0, dc2+270, dc2+90);

dcp=IIf(dc3>315, dc3-360, dc3);

dcpr = dcp * 3.1416/180 ; /* convert to radians */

dcpr1 = dcpr + 45 * 3.1416/180;



/* Short oscillations indicate congestion, while longer cycles show trends. Redline ( sin(dcpr))
above blue line (sin(dcpr1)) indicates uptrend. Blue line above redline indicates downtrend. Always
confirm with the Instantaneous Trendline */

Graph0=sin(dcpr);

Graph1=sin(dcpr1);

/*Graph0 = quad;

Graph1=inphase;*/

/*Graph0 =atan(rp/ip);

Graph1 = dcpr1;*/

/* Title Bar */

ch= (Close-(Ref(Close,-1)));

chpct=ch/Ref(C,-1)*100;

Title ="InstTL "+Date()+" "+Name()+" Open "+WriteVal(O,format=1.2)+" High "+WriteVal(H,format=1.2)+" Low
"+WriteVal(L,format=1.2)+" Close " + WriteVal(C,format=1.2) + " Previous Close " +

WriteVal((Ref(C,-1)),format=1.2) + " Change= " +
WriteVal(ch,format=1.2)+"("+WriteVal(chpct,format=1.2)+"%)"+" Vol "+WriteVal(V,format=1.0);