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 EASYLANGUAGE TRADESTATION EASYLANGUAGE METASTOCK FOR WINDOWS NEUROSHELL TRADER TRADINGSOLUTIONS BYTE INTO THE MARKET WEALTH-LAB.COM TECHNIFILTER PLUS or return to April 2001 Contents
TRADESTATION EASYLANGUAGE
Here is some EasyLanguage code I developed to compute the filters presented in my article in this issue, "Nonlinear Ehlers Filters." First is the code for the nonlinear Ehlers filter:NONLINEAR EHLERS FILTER EASYLANGUAGE
GO BACKThis exemplary filter has 15 coefficients ["Length(15)"], although the array of coefficients is dimensioned to 25 ["Coef[25]"] to allow experimentation using a longer filter. If you want a filter longer than 25, the dimension of the Coef array must be increased accordingly.Inputs: Price((H+L)/2), Length(15); Vars: count(0), SumCoef(0), Num(0), Filt(0); Array: Coef[25](0); {Coefficients can be computed using any statistic of choice ---- ---- a five-bar momentum is used as an example} For count = 0 to Length - 1 begin Coef[count] = AbsValue(Price[count] - Price[Count + 5]); {The line above is all that needs to be changed to use other statistics. For example: Coef[count]=AbsValue(Price[count]-Filt[count+1]);} end; {Sum across the numerator and across all coefficients} Num = 0; SumCoef =0; For count = 0 to Length -1 begin Num = Num + Coef[count]*Price[count]; SumCoef = SumCoef + Coef[count]; end; Filt = Num / SumCoef; Plot1(Filt, "Ehlers");In the first calculation, you find each coefficient in the filter as the five-bar momentum. The next computation is to sum the numerator ["NUM"] as the product of each coefficient and the price (the x's in the general equation) at each corresponding sample, and then sum the coefficients alone. Finally, the filter is completed by taking the ratio of the numerator to the coefficient sum. The performance of this filter is shown in Figure 2 in the article.
If you'd rather use a spreadsheet, an example done in Microsoft Excel is shown in Figure 1.
Next is the EasyLanguage code to compute the distance coefficient Ehlers filter also presented in my article in this issue, "Nonlinear Ehlers Filters":FIGURE 1: EXCEL SPREADSHEET. Starting from the prices on the left, here is a way to compute a nonlinear Ehlers filter using a five-day momentum as the embedded filter. DISTANCE COEFFICIENT EHLERS FILTER
Inputs: Price((H+L)/2), Length(15); Vars: count(0), LookBack(0), SumCoef(0), Num(0), Filt(0); Array: Coef[25](0), Distance2[25](0); For count = 0 to Length - 1 begin Distance2[count] = 0; For LookBack = 1 to Length begin Distance2[count] = Distance2[count] + (Price[count] - Price[count + LookBack])*(Price[count] - Price[count + LookBack]); end; Coef[count] = Distance2[count]; end; Num = 0; SumCoef =0; For count = 0 to Length -1 begin Num = Num + Coef[count]*Price[count]; SumCoef = SumCoef + Coef[count]; end; If SumCoef <> 0 then Filt = Num / SumCoef; Plot1(Filt, "Ehlers");The TradeStation code for a distance coefficient can also be used in the nonlinear Ehlers filter. If you'd rather use a spreadsheet, an example of the TradeStation code for a distance coefficient can be seen in Excel form in Figure 2.FIGURE 2: DISTANCE COEFFICIENT. This spreadsheet computes the squared difference between the current price and the price five bars back, and then squares it to get a more responsive Ehlers filter value.
MICROSOFT EXCELTo compute the filter in Excel, first compute the squared differences from the current price as:
As soon as you have five values of the squared difference, compute, in F11:E7 = (D7-D6)^2+(D7-D5)^2+(D7-D4)^2+(D7-D3)^2+(D7-D2)^2Then,F11 =D7*E7+D8*E8+D9*E9+D10*E10+D11*E11Copy all the row 11 values downward and check the values against those in Figure 2.G11 =SUM(E7:E11)H11 =F11/G11--John Ehlers
TRADESTATION EASYLANGUAGE
Here is a generic EasyLanguage version of the nonlinear Ehlers filter, based on John Ehlers's article in this issue, "Nonlinear Ehlers Filters." This EasyLanguage filter accepts the coefficients statistic as an input.In the following EasyLanguage indicator code, the Coef input is set to AbsValue( MedianPrice - MedianPrice[5] ), and the price input is set to MedianPrice. MedianPrice is a built-in function in EasyLanguage that returns (H + L) / 2. With these values for the inputs, the indicator is equivalent to the momentum-based Ehlers filter, for which a specific EasyLanguage version has been developed by John Ehlers and is given at the top of this Traders' Tips section.
To derive the distance coefficient Ehlers filter, which is also described in Ehlers's article, the Coef input value in the following EasyLanguage can be replaced with DistanceSqrd( MedianPrice, 15 ). DistanceSqrd is a custom function, and the code for that follows the indicator code.
INDICATOR: Ehlers Filter
GO BACKFUNCTION: DistanceSqrdnputs: Coef( AbsValue( MedianPrice - MedianPrice[5] ) ), Price( MedianPrice ), Length( 15 ) ; variables: Num( 0 ), SumCoef( 0 ), Count( 0 ), Filt( 0 ) ; Num = 0 ; SumCoef = 0 ; for Count = 0 to Length - 1 begin Num = Num + Coef[Count] * Price[Count] ; SumCoef = SumCoef + Coef[Count] ; end ; if SumCoef <> 0 then Filt = Num / SumCoef ; Plot1( Filt, "Ehlers" ) ;The EasyLanguage for both the function and indicator will be available for download at www.tradestation.com. Look for the file "EhlersFilter.ELS."inputs: Price( numericseries ), Length( numericsimple ) ; variables: DSqrd( 0 ), LookBack( 0 ) ; DSqrd = 0 ; for LookBack = 1 to Length begin DSqrd = DSqrd + Square( Price - Price[LookBack] ) ; end ; DistanceSqrd = DSqrd ;-- Ramesh Dhingra, Product Manager, EasyLanguage
TradeStation Technologies, Inc. (formerly Omega Research, Inc.)
A wholly owned subsidiary of TradeStation Group, Inc.
https://www.TradeStation.com
METASTOCK FOR WINDOWS
The formulas discussed by John Ehlers in his article in this issue, "Nonlinear Ehlers Filters," can be recreated in MetaStock 6.52 or higher. To set up these indicators, select the Indicator Builder from the Tools menu. Then click "New" and enter the formulas as listed here:Name: Ehlers Filters Formula: ti:= 15; pr:= MP(); coef:= Abs(pr - Ref(pr,-5)); Sum(coef*pr,ti)/Sum(coef,ti) Name: Distant Coefficient Ehlers Filter Formula: ti:= 15; pr:= MP(); coef:=Sum(Power(Ref(LastValue(pr+PREV-PREV)-pr,-1),2),ti); Sum(coef*pr,ti)/Sum(coef,ti)
GO BACK-- Cheryl C. Abram, Equis International, Inc.
www.equis.com
NEUROSHELL TRADER
The Ehlers filter can be easily implemented in NeuroShell Trader by combining a few of the built-in indicators (of which there are more than 800). We've done this for you already and have created custom indicators that you can download from the NeuroShell Trader free technical support website.However, we wanted to show you how easy it is to implement the Ehlers filter in NeuroShell Trader. To do so, select "New Indicator É" from the Insert menu and follow these steps:
1 Select the volume-weighted moving average from the Volume Weighted Moving Average category.You should end up with something that looks like this:
2 Change the time series and the volume variables to the values you wish to use.
GO BACKIn Ehlers's first example, he sets:VolWgtMovAvg(X, Y, 5) where: X = The time series you wish to filter [Ehlers uses (High+Low)/2 or the Average2(High, Low)] Y = The coefficients you wish to use (as Ehlers points out, coefficients can be computed using any statistic of choice).Users of NeuroShell Trader can go to the STOCKS & COMMODITIES section of the NeuroShell Trader free technical support website to download a copy of the Ehlers filter (Figure 3), as well as an example chart (Figure 4).X = Average2(High, Low) Y = Absolute Value(Momentum(Average2(High,Low), 5)FIGURE 3: NEUROSHELL TRADER. Here's how to add the Ehlers filter custom indicators using NeuroShell Trader's Indicator Wizard. The custom indicators can be downloaded from NeuroShell Trader's free technical support website.
FIGURE 4: NEUROSHELL TRADER. Here's a sample NeuroShell Trader chart that graphically depicts the Ehlers filters.
For more information on NeuroShell Trader, visit www.NeuroShell.com.--Marge Sherald, Ward Systems Group, Inc.
301 662-7950, sales@wardsystems.com
www.neuroshell.com
TRADINGSOLUTIONS
In "Nonlinear Ehlers Filters," John Ehlers presents a general filter that can be used with any coefficient statistic to produce a value that can be used like a simple moving average, but with less lag during sharp transitions. The general formula for this filter can be entered in TradingSolutions as follows:Using this general function, the sample five-bar momentum version of the Ehlers filter can be entered like this:Ehlers Filter (General) Short Name: Ehlers Inputs: Price, Coefficient, Length Div ( Sum ( Mult ( Coefficient , Price ) , Length ) , Sum ( Coefficient , Length ) )Ehlers Filter (Momentum) Short Name: EhlersMom Inputs: Price, Length Ehlers ( Price , Abs ( Change ( Price , 5 ) ) , Length )
Implementing the distance coefficient is slightly more complex, since it subtracts multiple previous prices from the current price. This can be accomplished in TradingSolutions with the following formula:To produce the value "Current: Ident ( Price )," insert the Price input into the formula. Then select it and view the Special Processing page. Press the Add Level button to add the surrounding Identity function and then select "Use the current value of the selected function for all values in the surrounding array function." This tells TradingSolutions to use the current price value for each iteration of the surrounding summation. (See sample chart in Figure 5.)Ehlers Filter (Distance) Short Name : EhlersDist Inputs: Price, Length Ehlers (Price, Sum(Pow(Sub(Current: Ident(Price), Lag(Price, 1)), 2), Length), Length) These functions are available in a function file that can be downloaded from our website in the Solution Library section. It can then be imported into TradingSolutions using "Import Functions..." from the File menu.FIGURE 5: TRADINGSOLUTIONS. Here's a sample TradingSolutions chart of the median price of EMC with the 15-period moving average, Ehlers's momentum filter, and Ehlers's distance filter. To apply one of these imported functions to a stock or group of stocks, select "Add New Field..." from the context menu for the stock or group, select "Calculate a value...," then select the desired function from the "Traders Tips Functions" group.
GO BACK--Gary Geniesse, TradingSolutions Project Lead
NeuroDimension, Inc., 800 634-3327, 352 377-5144
info@tradingsolutions.com, www.tradingsolutions.com
BYTE INTO THE MARKET
The Byte Into The Market (BITM) formula to compute the Ehlers filter from John Ehlers's article, "Nonlinear Ehlers Filters," is shown in Figure 6. Figure 7 shows the formula to calculate the distance coefficient Ehlers filter. In the distance filter formula, we used the momentum icon (same as a simple difference over a specified period). The momentum is of the median price ((high+low)/2). Clicking a momentum icon in the formula editor displays the icon parameter graphical controls (Figure 8).FIGURE 6: BYTE INTO THE MARKET. The Byte Into The Market formula to compute the Ehlers filter is shown.
FIGURE 7: BYTE INTO THE MARKET. Here's the formula to calculate the distance coefficient Ehlers filter.
FIGURE 8: BYTE INTO THE MARKET. Clicking a momentum icon in the formula editor displays the icon parameter graphical controls.
These filter formulas are also available in a downloadable zip file from Tarn Software's website at https://www.tarnsoft.com/filter.zip.
GO BACK--Tom Kohl, Tarn Software
303-794-4184, bitm@tarnsoft.com
www.tarnsoft.com
WEALTH-LAB.COM
In "Nonlinear Ehlers Filters," John Ehlers presented the code for creating a nonlinear, finite impulse response filter (FIR). The resulting indicator is similar to a moving average but provides better smoothing in sideways markets and less lag in trending markets.We've programmed this as a Wealth-Lab.com ChartScript that you can try out against any stock that you wish. Just point your browser to www.wealth-lab.com and click the "Public ChartScripts" link. There, you'll find a ChartScript named "Ehlers Filter." This particular script is a good example of how to create a custom indicator in Wealth-Lab's scripting language, WealthScript, and how to work with functions that manipulate entire price series.
Here is the code for the Ehlers Filter ChartScript.
{ Create a Price Series to hold Absolute 5 day momentum } AbsMom5 := CreateSeries(); { Populate the Price Series } for Bar := 6 to BarCount() - 1 do SetSeriesValue( Bar, AbsMom5, Abs( PriceAverage( Bar ) - PriceAverage( Bar - 5 ) ) ); { Obtain 5 day Abs Momentum multipled by Average Price } PriceTimesMomentum5 := MultiplySeries( PriceAverage(), AbsMom5 ); { Create Price Series to hold Ehlers Filter } EhlersFilter := CreateSeries(); { Populate Ehlers Filter Price Series } for Bar := 25 to BarCount() - 1 do begin xSumPM := Sum( Bar, PriceTimesMomentum5, 15 ); xSumM := Sum( Bar, AbsMom5, 15 ); SetSeriesValue( Bar, EhlersFilter, xSumPM / xSumM ); end; { Plot it } PlotSeries( EhlersFilter, 0, #Teal, 2 ); DrawText( ÔEhlers Filter', 0, 4, 34, #Teal, 8 );
GO BACK--Dion Kurczek, Wealth-Lab.com
773 883-9047, dionkk@ix.netcom.com
www.wealth-lab.com
TECHNIFILTER PLUS
Here are the two filtered average formulas from John Ehlers's article in this issue, "Nonlinear Ehlers Filters." In each formula, line 2 calculates the coefficients used in the calculation. The calculation on line 2 in the second formula is algebraically equivalent to the one given by Ehlers; this different form of the formula better fits TechniFilter Plus's algebra.Visit RTR's website at https://www.rtrsoftware.com to download this formula as well as program updates.Formula for Ehlers' filter NAME: Ehlers_Filter SWITCHES: multiline PARAMETERS: 15 FORMULA: [1]: (H+L)/2 { Price } [2]: ([1]-[1]Y5)U0 { Coefficient } [3]: [2]F&1 { SumCoef } [4]: ([1] * [2])F&1 { Num } [5]: [4] / [3] { Filt } Formula for Ehlers Filter using distance coefficients NAME: Ehlers_Filter_Dist_Coef SWITCHES: multiline FORMULA: [1]: (H+L)/2 { Price } [2]: 5*[1]*[1] - 2*[1]*[1]Y1F5 + ([1]Y1*[1]Y1)F5 [3]: [2]F5 { SumCoef } [4]: ([1] * [2])F5 { Num } [5]: [4] / [3] { Filt }
GO BACK--Clay Burch, RTR Software
919 510-0608, E-mail: rtrsoft@aol.com
www.rtrsoftware.com
All rights reserved. © Copyright 2001, Technical
Analysis, Inc.