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

Re: adaptive stochastic oscillator



PureBytes Links

Trading Reference Links

Glen and Ken, Thank you!  The LastValue() will really help many of my coding challenges!  That's what I needed.  To try to solve this or other problems, I just start reading through the functions section of my users manual.  I got very wrapped around trying to get creative with the HIGHESTSINCE function and the SUM function, but ended up with the same difficulties.  This has been a great learning process. I agree with the smoothing function.  It does a lot better. Dave Nadeau Glen Wallace wrote: Dave: A couple comments.  You can get around the problem with variables in the HHV and LLV functions by using LastValue(currlen) rather than just currlen.  Also, the smoothing in the definition of stochma will give you a simple moving average instead of exponential.  Instead, try stochma:= Mov(stoch, 3, Exponential); You also need a different variable name for stoch, since this is also a function name. Regards. 
----- Original Message -----
From: Dave Nadeau To: metastock@xxxxxxxxxxxxx Sent: Thursday, June 29, 2000 12:40 PM Subject: Re: adaptive stochastic oscillator  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