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

RE: [Metastockusers] Re: ATR - how to make it better?



PureBytes Links

Trading Reference Links

Jose,

Let me try your fml for a few days and see how it looks. Meanwhile, if you 
can somehow conjure up a fml that uses Std Dev and also eliminates the 
outliers, I will really appreciate it (as per Std Deviation theory, Mean +/- 
1 Std Dev covers 65% of the range of values; for a 20-period time frame, 
that would mean 13 periods. I want to eliminate those 7 values in a 
20-period that are outliers and calculate the ATR from the remaining 13 
values. If its problematic to eliminate 7 values because its an odd number, 
then I will settle for eliminating 6 values - 3 lowest and 3 highest.)

JD
====================================================

From: "Jose" <josesilva22@xxxxxxxxx>
Reply-To: Metastockusers@xxxxxxxxxxxxxxx
To: Metastockusers@xxxxxxxxxxxxxxx
Subject: [Metastockusers] Re: ATR - how to make it better?
Date: Sun, 29 Feb 2004 04:14:49 -0000

John,

This version of ATR has both normalizing (i.e. converts output into an
oscillator) and sine-weighted smoothing functions.

Also note some possibly interesting relationships between normal &
reverse ATRs (option 3).

jose '-)

====================
ATR - True & Reverse
====================
---8<--------------------------------

{ True, Reverse & MetaStock ATR v3.0 }
{ ©Copyright 2004 Jose Silva }
{ josesilva22@xxxxxxxxx }

{ Reverse True Range is the the *smallest*
   of the following for each period:
   * The distance from today's High
     to today's Low;
   * The distance from yesterday's Close
     to today's High;
   * The distance from yesterday's Close
     to today's Low.}

{ user input }
plot:=Input("[1]True ATR,  [2]Reverse ATR,  [3]Both,  [4]MS-ATR",1,4,
1);
pds:=Input("Average True Range periods",
  1,252,10);
smooth:=Input("Sine-weighted smoothing?  [1]Yes,  [0]No",0,1,0);
pdsN:=Input("normalizing periods (1=none)",
  1,2520,1);

{ define True Range }
x1:=ValueWhen(2,1,C);
TrueRange:=Max(H-L,Max(Abs(x1-H),Abs(x1-L)));
RevTrueRange:=Min(H-L,Min(Abs(x1-H),Abs(x1-L)));

{ average True Range }
ATRtrue:=Mov(TrueRange,pds,E);
ATRrev:=Mov(RevTrueRange,pds,E);
ATRmeta:=Mov(TrueRange,pds*2-1,E);

{ normalize ATR }
ATRraw:=If(plot=1,ATRtrue,If(plot=2,ATRrev,
  If(plot=4,ATRmeta,ATRtrue)));
ATRnorm:=100*(ATRraw-LLV(ATRraw,pdsN))
  /(HHV(ATRraw,pdsN)-LLV(ATRraw,pdsN)+.000001);
ATRplot:=If(pdsN<2,ATRraw,ATRnorm);
rATRnorm:=100*(ATRrev-LLV(ATRrev,pdsN))
  /(HHV(ATRrev,pdsN)-LLV(ATRrev,pdsN)+.000001);
rATRplot:=If(pdsN<2,RevTrueRange,rATRnorm);

{ optional sine-weighted smoothing }
ATRplot:=If(smooth=1,(Sin(30)*ATRplot
  +Sin(60)*Ref(ATRplot,-1)
  +Sin(90)*Ref(ATRplot,-2)
  +Sin(60)*Ref(ATRplot,-3)
  +Sin(30)*Ref(ATRplot,-4))
/(Sin(30)*2+Sin(60)*2+Sin(90)),ATRplot);
rATRplot:=If(smooth=1,(Sin(30)*rATRplot
  +Sin(60)*Ref(rATRplot,-1)
  +Sin(90)*Ref(rATRplot,-2)
  +Sin(60)*Ref(rATRplot,-3)
  +Sin(30)*Ref(rATRplot,-4))
/(Sin(30)*2+Sin(60)*2+Sin(90)),rATRplot);

{ plot ATR }
If(plot=3,rATRplot,ATRplot);
ATRplot

---8<--------------------------------


--- In Metastockusers@xxxxxxxxxxxxxxx, "John Doe" <ms001122@xxxx>
wrote:
 > Jose and others,
 >
 > Keeping aside the point how MS calculates ATR, the fact is that ATR
is an
 > extremely volatile indicator - its value (over, say, 20 bars) can
range from
 > a low of zero (theoretically) to several times what its average
value for
 > that period might be. e.g. a 20-bar ATR, as calculated by MS, may be
1.5 and
 > the ATR(1) range over those 20bars might be 0.2 - 5.8!!! Clearly,
some form
 > of averaging needs to be used to come up with a workable number -
one can
 > use simple, exponential, weighted, etc. - the latter two will make
it more
 > sensitive to recent values.
 >
 > When a stock is not trending steeply, one can use any form of
averaging -
 > their value will tend to be clustered closely. However, when a stock
is in a
 > steep rise or decline, the simple avarage will underestimate the
"true" ATR
 > in an uptrend and overestimate it in a downtrend. Lest one think
that one
 > should therefore use Wtd or Expo averages, it should be noted that a
large
 > ATR value for the last bar will unduly influence them. One can see
the
 > results visually by plotting the ATR values in a chart - just
calculate and
 > plot the 20bar simple, expo, and wtd ATRs and one can appreciate
their
 > clustering in a nontrending stock and the generally more volatile
nature of
 > Expo & Wtd ATRs.
 >
 > I have struggled with the problem of getting a "reasonable" value
for the
 > 20-period ATR for quite some time now, in the process concocting
some
 > (strange) formulas that would "dampen" the fluctuations in its
value. My
 > current thinking is that I should be using Standard Deviation of the
 > 20-period mean (simple average) in some fashion. Since I don't have
a PhD in
 > mathematics, I have been stuck.
 >
 > Can you think of a formula to implement std dev (or some other
mathematical
 > function) to calculate the 20-period ATR, and in the process weeding
out the
 > "outlying values" (both high and low)? Any help will be appreciated.
 >
 > JD

_________________________________________________________________
Take off on a romantic weekend or a family adventure to these great U.S. 
locations. http://special.msn.com/local/hotdestinations.armx



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/Metastockusers/

<*> To unsubscribe from this group, send an email to:
     Metastockusers-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/