Here is this month's selection of Traders' Tips, contributed by various developers of technical analysis software to help readers more easily implement some of the strategies presented in this issue.You can copy these formulas and programs for easy use in your spreadsheet or analysis software. Simply "select" the desired text by highlighting as you would in any word processing program, then use your standard key command for copy or choose "copy" from the browser menu. The copied text can then be "pasted" into any open spreadsheet or other software by selecting an insertion point and executing a paste command. By toggling back and forth between an application window and the open Web page, data can be transferred with ease.
This month's tips include formulas and programs for:
TRADESTATION / SUPERCHARTS
METASTOCK
TECHNIFILTER PLUS
WAVEWI$E MARKET SPREADSHEET
SMARTRADERor return to MARCH 1998 Contents
The adaptive moving average that was discussed in the interview with Perry Kaufman in the 1998 STOCKS & COMMODITIES Bonus Issue (the article originally appeared in March 1995) is an excellent alternative to standard moving average calculations. In this month's Traders' Tips, I will present two Easy Language studies and an Easy Language system that are based on the adaptive moving average.The adaptive moving average calculation that is used in the studies and system in TradeStation or SuperCharts is performed primarily by a function referred to as "AMA." Another function referred to as "AMAF" is used to calculate the adaptive moving average filter. As always, the functions should be created prior to the development of the studies/system.
Type: FunctionOnce you have successfully created both functions, you can then create the two studies and the system. The first indicator displays the adaptive moving average line, with an optional twist. The twist is that the AMA line can be smoothed using linear regression. Thus, I have included in the indicator an input named "smooth" that allows you to determine if the AMA line should be smoothed or not. A "Y" as the input value smoothes the calculation. An "N" simply plots the raw AMA line. This indicator should be scaled to "Same as price data."
Name: AMAInputs: Period(Numeric);
Vars: Noise(0), Signal(0), Diff(0), efRatio(0), Smooth(1), Fastest(.6667), Slowest(.0645), AdaptMA(0);
Diff = AbsValue(Close - Close[1]);
IF CurrentBar <= Period Then AdaptMA = Close;
IF CurrentBar > Period Then Begin
Signal = AbsValue(Close - Close[Period]);End;Noise = Summation(Diff, Period);
efRatio = Signal / Noise;
Smooth = Power(efRatio * (Fastest - Slowest) + Slowest, 2);
AdaptMA = AdaptMA[1] + Smooth * (Close - AdaptMA[1]);
AMA = AdaptMA;
Type: Function
Name: AMAFInputs: Period(Numeric), Pcnt(Numeric);
Vars: Noise(0), Signal(0), Diff(0), efRatio(0), Smooth(1), Fastest(.6667), Slowest(.0645), AdaptMA(0), AMAFltr(0);
Diff = AbsValue(Close - Close[1]);
IF CurrentBar <= Period Then AdaptMA = Close;
IF CurrentBar > Period Then Begin
Signal = AbsValue(Close - Close[Period]);End;Noise = Summation(Diff, Period);
efRatio = Signal / Noise;
Smooth = Power(efRatio * (Fastest - Slowest) + Slowest, 2);
AdaptMA = AdaptMA[1] + Smooth * (Close - AdaptMA[1]);
AMAFltr = StdDev(AdaptMA-AdaptMA[1], Period) * Pcnt;
AMAF = AMAFltr;
Type: IndicatorThe second indicator, "Mov Avg Adaptive Fltr," takes the filtering concept and applies it to an indicator. Based on the filtered adaptive moving average (AMAF) parameters, this indicator will plot a vertical blue or red line, depending on the condition that is met. The values reflected by the vertical lines reflect the value of the AMA filter calculation. Some suggested format settings are given after the indicator code.
Name: MovAvg AdaptiveInputs: Period(10), Smooth("Y");
IF UpperStr(Smooth) = "Y" Then
Plot1(LinearRegValue(AMA(Period), Period, 0), "Smooth AMA")ElsePlot2(AMA(Period), "Adaptive MA");Type: IndicatorThe "MovAvg Adaptive Fltr" system below is based on the rules set forth for entries based on the filtered adaptive moving average calculation.
Name: MovAvg Adaptive FltrInputs: Period(10), Pcnt(.15);
Vars: AMAVal(0), AMAFVal(0), AMALs(0), AMAHs(0);
AMAVal = AMA(Period);
AMAFVAl = AMAF(Period, Pcnt);
IF CurrentBar = 1 Then Begin
AMALs = AMAVal;End Else BeginAMAHs = AMAVal;
IF AMAVal < AMAVal[1] ThenEnd;AMALs = AMAVal;IF AMAVal > AMAVal[1] ThenAMAHs = AMAVal;IF AMAVal - AMALs > AMAFVal Then BeginPlot1(AMAFVal, "Buy");End ElseIF Plot1[1] = 0 Then
Alert = True;IF AMAHs - AMAVal > AMAFVal Then BeginPlot3(AMAFVal, "AMAFilter");Plot2(AMAFVal, "Sell");End;IF Plot2[1] = 0 Then
Alert = True;Style:
Scaling: ScreenPlot Name Type Color Weight Plot1 Buy Histogram Blue Thinnest Plot2 Sell Histogram Red Thinnest Plot3 AMAFilter Line Magenta ThinnestType: SystemThis code is also available at Omega Research's Web site. The name of the file is "AMA.ELA." Please note that all Traders' Tips analysis techniques posted at Omega Research's Web site can be utilized by both TradeStation and SuperCharts. Whenever possible, the posted analysis techniques will include both Quick Editor and Power Editor formats.Name: MovAvg Adaptive Fltr
Inputs: Period(10), Pcnt(.15);
Vars: AMAVal(0), AMAFVal(0), AMALs(0), AMAHs(0);
AMAVal = AMA(Period);
AMAFVAl = AMAF(Period, Pcnt);
IF CurrentBar = 1 Then Begin
AMALs = AMAVal;End Else BeginAMAHs = AMAVal;
IF AMAVal < AMAVal[1] ThenEnd;AMALs = AMAVal;IF AMAVal > AMAVal[1] ThenAMAHs = AMAVal;IF AMAVal - AMALs Crosses Above AMAFVal ThenBuy This Bar on Close;IF AMAHs - AMAVal Crosses Above AMAFVal ThenSell This Bar on Close;-- Gaston Sanchez, Omega Research
800 422-8587, 305 270-1095
Internet: https://www/omegaresearch.comBack to List
In MetaStock 6.5, you can easily create the adaptive moving average system discussed by Perry Kaufman in the interview appearing in the 1998 Bonus Issue. With MetaStock 6.5 running, choose "Indicator Builder" from the Tools menu and then click on the New button. Enter the following formulas:Adaptive Moving Average Binary Wave
Periods := Input("Time Periods",1,1000, 10);
Direction := CLOSE - Ref(CLOSE,-periods);
Volatility := Sum(Abs(ROC(CLOSE,1,$)),periods);
ER := Abs(Direction/Volatility);
FastSC := 2/(2 + 1);
SlowSC := 2/(30 + 1);
SSC := ER * (FastSC - SlowSC) + SlowSC;
Constant := Pwr(SSC,2);
AMA := If(Cum(1) = periods +1, ref(Close,-1) + constant * (CLOSE - ref(Close,-1)),Prev + constant * (CLOSE - PREV));
FilterPercent := Input("Filter Percentage", 0,100,15)/100;
Filter := FilterPercent * Std(AMA - Ref(AMA,-1),Periods);
AMALow := If(AMA < Ref(AMA,-1),AMA,PREV);
AMAHigh := If(AMA > Ref(AMA,-1),AMA,PREV);
If(AMA - AMALow > Filter, 1 {Buy Signal}, If(AMAHigh - AMA > Filter, -1 { Sell Signal}, 0 {No Signal}))
Adaptive Moving Average
Periods := Input("Time Periods",1,1000, 10);
Direction := CLOSE - Ref(CLOSE,-periods);
Volatility := Sum(Abs(ROC(CLOSE,1,$)),periods);
ER := Abs(Direction/Volatility);
FastSC := 2/(2 + 1);
SlowSC := 2/(30 + 1);
SSC := ER * (FastSC - SlowSC) + SlowSC;
Constant := Pwr(SSC,2);
AMA := If(Cum(1) = periods +1, ref(Close,-1) + constant * (CLOSE - ref(Close,-1)),Prev + constant * (CLOSE - PREV));
AMA
If you want to see the adaptive moving average, just plot it on any chart in MetaStock. If you want to see the buy and sell signals from the adaptive moving average system, plot the adaptive moving average binary wave. This binary wave plots a "1" when there's a buy signal, a "-1" for a sell signal and a zero when there's no signal.
--Allan J. McNichol, EQUIS International
800 882-3040, 801 265-8886
Internet: https://www.equis.comBack to List
Here's a TechniFilter Plus, version 8, formula for the adaptive moving average (AMA) discussed by Perry Kaufman in the 1998 Bonus Issue.AMA is an exponential average where the multiplier weight can vary each day between a maximum and minimum value. As the prices form a strong trend, this variable weight approaches its maximum value, causing the AMA to track the price curve more closely. When the prices are zigzagging, the variable weight approaches its minimum value, causing the AMA to flatten. Kaufman uses a ratio of price change to price variation to scale the variable weight.
The formula uses three parameters: 2, 30 and 10. The first parameter, 2, indicates that a two-day exponential average is the fastest average for the variable average. The second parameter, 30, indicates that a 30-day average is the slowest average for the variable average. The third parameter, 10, indicates the lookback period for computing how the weight will change.
Perry Kaufman's Adaptive Moving Average Formula
NAME: ama
SWITCHES: multiline recursive
PARAMETERS: 2,30,10
INITIAL VALUE: C
FORMULA:
[1]: 2/(&1+1) { FAST WEIGHT } [2]: 2/(&2+1) { SLOW WEIGHT } [3]: C-CY&3 { DIRECTION } [4]: (C-CY1)U0F&3 { VOLATILITY } [5]: ([3]/[4])U0 { EFF RATIO } [6]: [2] + [5] * ([1]-[2]) { SCALED CONSTANT } [7]: [6]*[6] { SQUARED } [8]: CU13<&3 { INSUFFICIENT DATA } [9]: [8] * C + ([8]=0) * ([7] * C + (1-[7]) * TY1)This TechniFilter Plus strategy and the reports, strategies and formulas of earlier Traders' Tips can be downloaded from RTR's Web site.--Clay Burch, RTR Software
919 510-0608, E-mail: rtrsoft@aol.com
Internet: https://www.rtrsoftware.comBack to List
Here is a WAVE WI$E program implementation of Perry Kaufman's adaptive moving average (AMA), discussed in the STOCKS & COMMODITIES 1998 Bonus Issue interview presentation.WAVE WI$E Spreadsheet Formulas A: Date @TC2000(c:\tc2000\data,DJ-30,DOW JONES INDUSTRIALS,D) B: Price C: Diff PRICE - PRICE[-10] D: IDP @ABS(PRICE - PRICE[-1]) E: VT @ADD(IDP,10) F: ERT @ABS(DIFF/VT) G: Constant @INIT(1,2/(2+1), 2/(30+1), 0.15) H: Smooth (ERT*(G$1-G$2)+G$2)^2 I: AMA @IF(@ROW()<=10, PRICE, AMA[-1]+SMOOTH*(PRICE - AMA[-1])) J: DAMA AMA-AMA[-1] K: Filter @STD(DAMA,10)*G$3 L: Lows @IF(AMA<AMA[-1],AMA,LOWS[-1]) M: Highs @IF(AMA>AMA[-1],AMA,HIGHS[-1]) N: Buys @IF((AMA - LOWS)>FILTER,BUY) O: Sells @IF((HIGHS - AMA)>FILTER,SELL) P: Color @IF(BUYS=BUY,GREEN, @IF(SELLS=SELL,RED,YELLOW)) Q: ==========End Formulas--Peter Di Girolamo, Jerome Technology
908 369-7503, E-mail: jtiware@aol.com
Internet: https://members.aol.com/jtiwareBack to List
Perry Kaufman's adaptive moving average (STOCKS & COMMODITIES, 1998 Bonus Issue) serves as a good example for applying the user formula capability in SMARTrader. The key to creating the adaptive moving average (AMA) is the ability to write recursive, or self-referencing, formulas. I'll point those out as we proceed.Row 4, labeled "offset," is used in conjunction with row 15 to "seed" the values manually entered in the spreadsheet example in cells I5 through I14. Direction is determined in row 5 using a 10-period momentum study. Rows 6, 7 and 8 calculate the volatility by first calculating a one-period momentum, then taking the absolute value of momentum and finally summing a 10-period series. Rows 9 and 10 calculate the ER value and its absolute value. Rows 11 and 12 are coefficients containing the exponent values representing two and 30 periods, respectively. Row 13 calculates the ssc value. Row 14 squares ssc, giving c.
Row 16 calculates the actual AMA and is the first row that is recursive. Row 17, also recursive, calculates the difference of the current and previous AMA. Row 18, AMAdiff, uses an if statement to avoid reporting an invalid result in column 1, since there is nothing prior to column 1 to yield a valid calculation.
Row 19 calculates the 10-period standard deviation of AMAdiff. Row 20 is a coefficient containing the percentage value. Row 21 calculates the filter value. Rows 22 and 23 are recursive user rows that track the AMA lows and AMA highs.
Rows 23 and 24 are the buy/sell rules, respectively.
Figure 1: SMARTRADER. This SMARTrader SpecSheet implements Perry Kaufman's adaptive moving average from the 1998 Bonus Issue. This specsheet is also available at Stratagem's Web site.
--Jim Ritter, Stratagem Software International
504 885-7353, E-mail: Stratagem1@aol.com
Internet: https://members.aol.com/stratagem1Back to List