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

adaptive stochastic oscillator



PureBytes Links

Trading Reference Links

<x-html><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META content="MSHTML 5.00.3018.900" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Has any one been able to code the "adaptive 
stochastic oscillator " as mentioned in page 10 of the S&amp;C July 
issue.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Here's the tradestation code as written by Tushar 
Chande:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>
<P>I was the first to propose adaptive indicators, and my article "Stochastic 
RSI And Dynamic Momentum Index" (S<FONT size=-1>TOCKS</FONT> &amp; C<FONT 
size=-1>OMMODITIES</FONT>, December 1992) explains how to do it. My book <I>The 
New Technical Trader </I>(John Wiley &amp; Sons) also contains a good 
explanation of it. The strategy is to change the lookback length of the 
indicator by connecting it to market volatility. We would like the indicator to 
have a long lookback period when prices are in a trading range (volatility is 
low). Conversely, we want a short lookback length when prices are moving 
rapidly. I feel that changing the lookback length for calculating indicators is 
more responsive than smoothing them with adaptive moving averages. The actual 
definition of long and short lookback lengths depends on your trading horizon. 
<P>Here is some simple TradeStation code to create an adaptive stochastic 
oscillator that uses the 20-day standard deviation of closing prices to vary the 
length between seven and 28 days. First, determine if the 20-day standard 
deviation is at its highest level. To do so, compute a stochastic oscillator 
using the 20-day standard deviation (variables v1 through v4). If the 20-day 
standard deviation is at its highest level (v1=v2), then v4=1 and the oscillator 
length is set at its shortest value, that is, set to the variable lenmin (=7 
days). If the 20-day standard deviation is at its lowest value (v1=v3), then 
v4=0 and the current length is set to the maximum length, that is, the variable 
lenmax (= 28 days). All that remains is to calculate the stochastic oscillator, 
Stoch, for the close and smooth it using a three-day exponential moving average. 
The same approach can be used to develop other adaptive indicators or averages. 
<P>
<HR width="100%">

<H3><B>TRADESTATION CODE FOR ADAPTIVE STOCHASTIC 
OSCILLATOR</B></H3><B>Editor,</B> <BR>&nbsp; <PRE>{-- © 2K Tushar Chande; Adaptive Stochastic Oscillator --}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vars: v1(0), v2(0), v3(0), v4(0) ;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vars: lenmax(28), lenmin(7), currlen(0) ;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vars: hh(0), ll(0), stoch(0), stochma(0) ;

{-- Calculate 20-day std. Dev. And its 20-day range --}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v1 = stddev(c,20) ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v2 = highest(v1, 20) ;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v3 = lowest(v1, 20) ;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{-- Create v4: stochastic oscillator for 20-day std. dev. --}
{-- if v1=v2 (highest level) =&gt; v4 = 1; if v1=v3 (lowest level) =&gt; v4=0 --}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (v2-v3) &gt; 0 then v4 = ((v1 - v3)/(v2-v3)) Else v4 = 0 ;

{-- Calculate current effective length; if v4 = 1, then length = mininum --}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; currlen = IntPortion(lenmin + (lenmax-lenmin)*(1-v4)) ;

{-- Calculate stochastic oscillator and its 3-day exponential average --}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hh = highest(h, currlen) ;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ll = lowest(l, currlen) ;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (hh-ll) &gt; 0 then stoch = ((close - ll)/(hh - ll)) * 100 ;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if currentbar = 1 then stochma = 0 else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stochma = 0.5*stoch + 0.5*stochma[1] ;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{-- Plot data --}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; plot1(stoch, "adapt_stoch") ;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; plot2(stochma, "stochma") ;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; plot3(80, "hi_ref") ;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; plot4(20, "lo_ref") ;

{ -- End of code --}</PRE></FONT></DIV></BODY></HTML>
</x-html>From ???@??? Wed Jun 28 20:36:50 2000
Return-Path: <majordom@xxxxxxxxxxxxxxxxxx>
Received: from listserv.equis.com (listserv.equis.com [204.246.137.2])
	by purebytes.com (8.9.3/8.9.3) with ESMTP id UAA15468
	for <neal@xxxxxxxxxxxxx>; Wed, 28 Jun 2000 20:30:49 -0700
Received: (from majordom@xxxxxxxxx)
	by listserv.equis.com (8.8.7/8.8.7) id UAA23473
	for metastock-outgoing; Wed, 28 Jun 2000 20:53:08 -0600
X-Authentication-Warning: listserv.equis.com: majordom set sender to owner-metastock@xxxxxxxxxxxxx using -f
Received: from freeze.metastock.com (freeze.metastock.com [204.246.137.5])
	by listserv.equis.com (8.8.7/8.8.7) with ESMTP id UAA23470
	for <metastock@xxxxxxxxxxxxxxxxxx>; Wed, 28 Jun 2000 20:53:05 -0600
Received: from mtiwmhc21.worldnet.att.net (mtiwmhc21.worldnet.att.net [204.127.131.46])
	by freeze.metastock.com (8.8.5/8.8.5) with ESMTP id VAA15596
	for <metastock@xxxxxxxxxxxxx>; Wed, 28 Jun 2000 21:13:57 -0600 (MDT)
Received: from oemcomputer ([12.73.102.227]) by mtiwmhc21.worldnet.att.net
          (InterMail vM.4.01.02.39 201-229-119-122) with SMTP
          id <20000629025604.DLKN1264.mtiwmhc21.worldnet.att.net@xxxxxxxxxxx>
          for <metastock@xxxxxxxxxxxxx>; Thu, 29 Jun 2000 02:56:04 +0000
Message-ID: <002501bfe175$f57a00e0$e366490c@xxxxxxxxxxx>
From: "Michael Gilbert" <tradermike@xxxxxxxxxxxxxxxx>
To: <metastock@xxxxxxxxxxxxx>
References: <003701bfe16f$d92a22e0$0c8958ca@xxxxxxxxxxx>
Subject: Re: adaptive stochastic oscillator 
Date: Wed, 28 Jun 2000 19:58:27 -0700
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_NextPart_000_0019_01BFE13B.39DA6F80"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 5.00.2919.6600
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600
Sender: owner-metastock@xxxxxxxxxxxxx
Precedence: bulk
Reply-To: metastock@xxxxxxxxxxxxx
Status:   

<x-html><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META content="MSHTML 5.00.2722.2800" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>isn't this a METASTOCK list????</FONT></DIV>
<BLOCKQUOTE 
style="BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
  <DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV 
  style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B> 
  Anil Chugani 
  </DIV>
  <DIV style="FONT: 10pt arial"><B>To:</B> <A 
  href="mailto:metastock@xxxxxxxxxxxxx"; title=metastock@xxxxxxxxxxxxx>metastock 
  list</A> </DIV>
  <DIV style="FONT: 10pt arial"><B>Sent:</B> Wednesday, June 28, 2000 7:15 
  PM</DIV>
  <DIV style="FONT: 10pt arial"><B>Subject:</B> adaptive stochastic oscillator 
  </DIV>
  <DIV><BR></DIV>
  <DIV><FONT face=Arial size=2>Has any one been able to code the "adaptive 
  stochastic oscillator " as mentioned in page 10 of the S&amp;C July 
  issue.</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>Here's the tradestation code as written by Tushar 
  Chande:</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>
  <P>I was the first to propose adaptive indicators, and my article "Stochastic 
  RSI And Dynamic Momentum Index" (S<FONT size=-1>TOCKS</FONT> &amp; C<FONT 
  size=-1>OMMODITIES</FONT>, December 1992) explains how to do it. My book 
  <I>The New Technical Trader </I>(John Wiley &amp; Sons) also contains a good 
  explanation of it. The strategy is to change the lookback length of the 
  indicator by connecting it to market volatility. We would like the indicator 
  to have a long lookback period when prices are in a trading range (volatility 
  is low). Conversely, we want a short lookback length when prices are moving 
  rapidly. I feel that changing the lookback length for calculating indicators 
  is more responsive than smoothing them with adaptive moving averages. The 
  actual definition of long and short lookback lengths depends on your trading 
  horizon. 
  <P>Here is some simple TradeStation code to create an adaptive stochastic 
  oscillator that uses the 20-day standard deviation of closing prices to vary 
  the length between seven and 28 days. First, determine if the 20-day standard 
  deviation is at its highest level. To do so, compute a stochastic oscillator 
  using the 20-day standard deviation (variables v1 through v4). If the 20-day 
  standard deviation is at its highest level (v1=v2), then v4=1 and the 
  oscillator length is set at its shortest value, that is, set to the variable 
  lenmin (=7 days). If the 20-day standard deviation is at its lowest value 
  (v1=v3), then v4=0 and the current length is set to the maximum length, that 
  is, the variable lenmax (= 28 days). All that remains is to calculate the 
  stochastic oscillator, Stoch, for the close and smooth it using a three-day 
  exponential moving average. The same approach can be used to develop other 
  adaptive indicators or averages. 
  <P>
  <HR width="100%">

  <H3><B>TRADESTATION CODE FOR ADAPTIVE STOCHASTIC 
  OSCILLATOR</B></H3><B>Editor,</B> <BR>&nbsp; <PRE>{-- © 2K Tushar Chande; Adaptive Stochastic Oscillator --}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vars: v1(0), v2(0), v3(0), v4(0) ;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vars: lenmax(28), lenmin(7), currlen(0) ;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vars: hh(0), ll(0), stoch(0), stochma(0) ;

{-- Calculate 20-day std. Dev. And its 20-day range --}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v1 = stddev(c,20) ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v2 = highest(v1, 20) ;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v3 = lowest(v1, 20) ;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{-- Create v4: stochastic oscillator for 20-day std. dev. --}
{-- if v1=v2 (highest level) =&gt; v4 = 1; if v1=v3 (lowest level) =&gt; v4=0 --}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (v2-v3) &gt; 0 then v4 = ((v1 - v3)/(v2-v3)) Else v4 = 0 ;

{-- Calculate current effective length; if v4 = 1, then length = mininum --}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; currlen = IntPortion(lenmin + (lenmax-lenmin)*(1-v4)) ;

{-- Calculate stochastic oscillator and its 3-day exponential average --}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hh = highest(h, currlen) ;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ll = lowest(l, currlen) ;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (hh-ll) &gt; 0 then stoch = ((close - ll)/(hh - ll)) * 100 ;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if currentbar = 1 then stochma = 0 else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stochma = 0.5*stoch + 0.5*stochma[1] ;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{-- Plot data --}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; plot1(stoch, "adapt_stoch") ;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; plot2(stochma, "stochma") ;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; plot3(80, "hi_ref") ;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; plot4(20, "lo_ref") ;

{ -- End of code --}</PRE></FONT></DIV></BLOCKQUOTE></BODY></HTML>
</x-html>From ???@??? Thu Jun 29 00:02:22 2000
Return-Path: <majordom@xxxxxxxxxxxxxxxxxx>
Received: from listserv.equis.com (listserv.equis.com [204.246.137.2])
	by purebytes.com (8.9.3/8.9.3) with ESMTP id VAA17761
	for <neal@xxxxxxxxxxxxx>; Wed, 28 Jun 2000 21:46:59 -0700
Received: (from majordom@xxxxxxxxx)
	by listserv.equis.com (8.8.7/8.8.7) id VAA24007
	for metastock-outgoing; Wed, 28 Jun 2000 21:55:55 -0600
X-Authentication-Warning: listserv.equis.com: majordom set sender to owner-metastock@xxxxxxxxxxxxx using -f
Received: from freeze.metastock.com (freeze.metastock.com [204.246.137.5])
	by listserv.equis.com (8.8.7/8.8.7) with ESMTP id VAA24002
	for <metastock@xxxxxxxxxxxxxxxxxx>; Wed, 28 Jun 2000 21:55:52 -0600
Received: from hotmail.com (f85.law4.hotmail.com [216.33.149.85])
	by freeze.metastock.com (8.8.5/8.8.5) with SMTP id WAA15623
	for <metastock@xxxxxxxxxxxxx>; Wed, 28 Jun 2000 22:16:45 -0600 (MDT)
Received: (qmail 22839 invoked by uid 0); 29 Jun 2000 03:58:53 -0000
Message-ID: <20000629035853.22838.qmail@xxxxxxxxxxx>
Received: from 209.214.201.73 by www.hotmail.com with HTTP;
	Wed, 28 Jun 2000 20:58:53 PDT
X-Originating-IP: [209.214.201.73]
From: "j seed" <jseed_10@xxxxxxxxxxx>
To: metastock@xxxxxxxxxxxxx
Subject: Re: adaptive stochastic oscillator
Date: Thu, 29 Jun 2000 03:58:53 GMT
Mime-Version: 1.0
Content-Type: text/plain; format=flowed
Sender: owner-metastock@xxxxxxxxxxxxx
Precedence: bulk
Reply-To: metastock@xxxxxxxxxxxxx
Status:   

Michael,
I believe he is asking for the Metastock code. I understand that it can be 
converted with MSDK.
J.


>From: "Michael Gilbert" <tradermike@xxxxxxxxxxxxxxxx>
>Reply-To: metastock@xxxxxxxxxxxxx
>To: <metastock@xxxxxxxxxxxxx>
>Subject: Re: adaptive stochastic oscillator
>Date: Wed, 28 Jun 2000 19:58:27 -0700
>
>isn't this a METASTOCK list????
>   ----- Original Message -----
>   From: Anil Chugani
>   To: metastock list
>   Sent: Wednesday, June 28, 2000 7:15 PM
>   Subject: adaptive stochastic oscillator
>
>
>   Has any one been able to code the "adaptive stochastic oscillator " as 
>mentioned in page 10 of the S&C July issue.
>

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com