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

Re: adaptive stochastic oscillator



PureBytes Links

Trading Reference Links

Are you not putting a variable into the data array portion of HHV?

Al Taglavore

----------
> From: Dave Nadeau <dave.nadeau@xxxxxxxx>
> To: metastock@xxxxxxxxxxxxx
> Subject: Re: adaptive stochastic oscillator
> Date: Thursday, June 29, 2000 2:40 PM
> 
Here's what I come up with.  It doesn't work, and I've run into this issue
when trying to solve some other problems. 
Does anyone have any ideas for circumventing the problem of putting a
variable into the "periods" part of the HHV or LLV functions? 
This gives an error when you try to put the code below into Metastock (in
blue): 
----------------------------------------------------------------------------
---------------------- 
{-- © 2K Tushar Chande; Adaptive Stochastic Oscillator --} 
        vars: v1(0), v2(0), v3(0), v4(0) ; 
        vars: lenmax(28), lenmin(7), currlen(0) ; 
        vars: hh(0), ll(0), stoch(0), stochma(0) ; 
lenmax:= 28; 
lenmin:= 7; 
currlen:= 0; 
{-- Calculate 20-day std. Dev. And its 20-day range --} 
        v1 = stddev(c,20) ; 
        v2 = highest(v1, 20) ; 
        v3 = lowest(v1, 20) ; 
v1:= Stdev(Close, 20); 
v2:= HHV(v1,20); 
v3:= LLV(v1,20); 
 
{-- Create v4: stochastic oscillator for 20-day std. dev. --} 
{-- if v1=v2 (highest level) => v4 = 1; if v1=v3 (lowest level) => v4=0 --}

        if (v2-v3) > 0 then v4 = ((v1 - v3)/(v2-v3)) Else v4 = 0 ; 
v4:=If((v2-v3)>0,((v1 - v3)/(v2-v3)),0); 
{-- Calculate current effective length; if v4 = 1, then length = mininum
--} 
 
        currlen = IntPortion(lenmin + (lenmax-lenmin)*(1-v4)) ; 
currlen:= If(v4=1,lenmin,(Int(lenmin + (lenmax-lenmin)*(1-v4)))); 
{-- Calculate stochastic oscillator and its 3-day exponential average --} 
        hh = highest(h, currlen) ; 
        ll = lowest(l, currlen) ; 
        if (hh-ll) > 0 then stoch = ((close - ll)/(hh - ll)) * 100 ; 
        if currentbar = 1 then stochma = 0 else 
               stochma = 0.5*stoch + 0.5*stochma[1] ; 
hh:= HHV(High, currlen); 
ll:= LLV(Low, currlen); 
stoch:=If(((hh-ll)>0,((close - ll)/(hh - ll)) * 100,50) {I set the error
condition to a stochastic midpoint...I'm open to any other ideas???} 
stochma:= (.5*stoch)+(.5*Ref(stoch,-1)) 
 
{-- Plot data --} 
        plot1(stoch, "adapt_stoch") ; 
        plot2(stochma, "stochma") ; 
        plot3(80, "hi_ref") ; 
        plot4(20, "lo_ref") ; 
stoch; stochma; 80; 20; 
{ -- End of code --} 
---------------------------------- 
Dave Nadeau