 MetaStock™ Zone Forum & FAQ Artykuły Linki Elliott Waves EasyLanguage™ Zone

 A B C D E F G H I J K L M N O P R S T U V W Y Z #

Chande's Adaptive Stochastic Oscillator
---- Original Message -----
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 ;
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 --}
plot2(stochma, "stochma") ;
plot3(80, "hi_ref") ;
plot4(20, "lo_ref") ;
stoch; stochma; 80; 20;
{ -- End of code --}
----------------------------------

Re: adaptive stochastic oscillator

* To: metastock@xxxxxxxxxxxxx
* Subject: Re: adaptive stochastic oscillator
* Date: Fri, 30 Jun 2000 13:15:16 -0700
* Organization: @Home Network Member
* References: <003701bfe16f\$d92a22e0\$0c8958ca@xxxxxxxxxxx>
* Sender: owner-metastock@xxxxxxxxxxxxx

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



Re: adaptive stochastic oscillator

* To: "MetaStock listserver" <metastock@xxxxxxxxxxxxx>
* Subject: Re: adaptive stochastic oscillator
* From: "Glen Wallace" <gcwallace@xxxxxxxx>
* Date: Fri, 30 Jun 2000 12:00:45 -0700
* References: <003701bfe16f\$d92a22e0\$0c8958ca@xxxxxxxxxxx>
* Sender: owner-metastock@xxxxxxxxxxxxx

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.



Re: adaptive stochastic oscillator

* To: metastock@xxxxxxxxxxxxx
* Subject: Re: adaptive stochastic oscillator
* From: iamken <iamken@xxxxxxxxxxxxxxx>
* Date: Fri, 30 Jun 2000 14:37:01 -0400
* Sender: owner-metastock@xxxxxxxxxxxxx

Re:  Chande's Adaptive Stochastic Oscillator on page 10 of the S&C July issue.

>...I'm open to any other ideas???

Ok, then here's my interpertation, but I can't say for certain that it's right.  Looks like it could stand to be smoothed, so in the second verision (at bottom), it is. By the way, I went ahead and added an input for the volatility lookback period.

Ken



Chande's Adaptive Stochastic Oscillator

n:=Input("**Volatility** lookback length",1,50,20);
lenmax:=28;
lenmin:=7;
v1:=Stdev(C,n);
v2:=HHV(v1,n);
v3:=LLV(v1,n);
v4:=((v1-v3)/(v2-v3));
currlen:=(Int(lenmin+(lenmax-lenmin)*(1-v4)));
hh:=HHV(H,LastValue(currlen));
ll:=LLV(L,LastValue(currlen));
RawStoch:=((C-ll)/(hh-ll))*100;
stochma:=(.5*RawStoch)+(.5*PREV);
20;
80;
stochma;
RawStoch;

Chande's Adaptive Stochastic Oscillator - Smoothed Version

n:=Input("**Volatility** lookback length",1,50,20);
x:=Input("%K smoothing (exponential smoothing)",1,50,3);
y:=Input("%D smoothing (exponential smoothing)",1,50,3);
lenmax:=28;
lenmin:=7;
v1:=Stdev(C,n);
v2:=HHV(v1,n);
v3:=LLV(v1,n);
v4:=((v1-v3)/(v2-v3));
currlen:=(Int(lenmin+(lenmax-lenmin)*(1-v4)));
hh:=HHV(H,LastValue(currlen));
ll:=LLV(L,LastValue(currlen));
RawStochK:=((C-ll)/(hh-ll))*100;
SmoothedStochK:=Mov(RawStochK,x,E);
StochD:=Mov(SmoothedStochK,y,E);
20;
80;
StochD;
SmoothedStochK; Source / From: TOP
http://purebytes.com/archives/metastock/

Equis and MetaStock® and MetaStock Professional® are registered trademarks of Equis International. Achelis Binary Wave®, The DownLoader®,
Expert Advisor®, OptionScope®, Quotecenter® and Smart Charts® are trademarks of Equis International, a Thomson Reuters company.

TradeStation® Pro, TradeStation® 2000i, OptionStation®, SuperCharts®, PowerEditor® and EasyLanguage®
are registered trademarks of TradeStation Technologies, Inc. Other names and marks referred to are the property of their respective owners.

All information provided on this website is for educational purposes only. Trading involves risk, including possible loss of principal and other losses.

Ten i inne materiały na tej stronie zostały zamieszczone zostały jedynie w celach edukacyjnych, nie ponoszę żadnej odpowiedzialności za ich stosowanie.

Gra na giełdzie i rynkach walutowych (FOREX) niesie ze sobą ryzyko poważnych strat finansowych!