Ehlers Deviation-Scaled Moving Average (TASC July 2018)  [SOLVED]

Questions about MultiCharts and user contributed studies.
User avatar
LRP
Posts: 153
Joined: 07 Apr 2008
Location: Switzerland
Has thanked: 96 times
Been thanked: 15 times

Ehlers Deviation-Scaled Moving Average (TASC July 2018)

Postby LRP » 12 Mar 2019

Dear All

May I ask kindly MC-Support or the community for a PowerLanguage conversion of Traders Tip of TASC July 2018?

Code: Select all

Function: EhlersDSMA
// Deviation Scaled Moving Average (DSMA)
// (c) 2013 - 2018 John F. Ehlers
// TASC JUL 2018
// EhlersDSMA function
using elsystem ;

inputs:
Period( numericsimple ) ;

variables:
a1( 0 ),
b1( 0 ),
c1( 0 ),
c2( 0 ),
c3( 0 ),
Zeros( 0 ),
Filt( 0 ),
ScaledFilt( 0 ),
RMS( 0 ),
count( 0 ),
alpha1( 0 ),
DSMA( 0 ) ;

once
begin
if Period <= 0 then
throw Exception.Create( "The 'Period' input to the " +
"EhlersDSMA function must be greater than 0." ) ;

//Smooth with a Super Smoother
a1 = ExpValue( -1.414 * 3.14159 / ( .5 * Period ) ) ;
b1 = 2 * a1 * Cosine( 1.414 * 180 / ( .5 * Period ) ) ;
c2 = b1 ;
c3 = -a1 * a1 ;
c1 = 1 - c2 - c3 ;
end ;

//Produce Nominal zero mean with zeros in the transfer
//response at DC and Nyquist with no spectral distortion
//Nominally whitens the spectrum because of 6 dB
//per octave rolloff
Zeros = Close - Close[2] ;

//SuperSmoother Filter
Filt = c1 * ( Zeros + Zeros[1] ) / 2 + c2 * Filt[1] + c3 * Filt[2] ;

//Compute Standard Deviation
RMS = 0;
For count = 0 to Period - 1
begin
RMS = RMS + Filt[count] * Filt[count] ;
end ;
RMS = SquareRoot( RMS / Period ) ;

//Rescale Filt in terms of Standard Deviations
If RMS <> 0 then
ScaledFilt = Filt / RMS ;

alpha1 = AbsValue( ScaledFilt ) * 5 / Period ;
DSMA = alpha1 * Close + ( 1 - alpha1 ) * DSMA[1] ;

EhlersDSMA = DSMA ;


Indicator: DSMA
// TASC JUL 2018
// Ehlers DSMA
inputs:
Period( 40 ) ;

variables:
DSMAValue( 0 ) ;

DSMAValue = EhlersDSMA( Period ) ;

Plot1( DSMAValue, "DSMA" ) ;

if AlertEnabled then
begin
if Close crosses over DSMAValue then
Alert( "Price crossing over DSMA" )
else if Close crosses under DSMAValue then
Alert( "Price crossing under DSMA" ) ;
end ;


Strategy: DSMA
// TASC JUL 2018
// Ehlers DSMA
inputs:
FastPeriod( 40 ),
SlowPeriod( 100 ) ;

variables:
FastDSMAValue( 0 ),
SlowDSMAValue( 0 ) ;

FastDSMAValue = EhlersDSMA( FastPeriod ) ;
SlowDSMAValue = EhlersDSMA( SlowPeriod ) ;

if FastDSMAValue crosses above SlowDSMAValue then
Buy next bar at Market
else if FastDSMAValue crosses below SlowDSMAValue then
SellShort next bar at Market ;
@ MC-Support: It would be a great service for learning purposes, to provide to the Multicharts community examples of PowerLanguage code from the "Trader's Tips" of the very well known and established TASC Magazine.: http://technical.traders.com/content/ba ... rchive.asp with a large readership.

Tank you very much and
kind regards,
LRP
Last edited by LRP on 15 Mar 2019, edited 3 times in total.

User avatar
ABC
Posts: 718
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Re: Ehlers Deviation-Scaled Moving Average (TASC July 2018)  [SOLVED]

Postby ABC » 12 Mar 2019

Hi LRP,

you should be able to get this code working in Multicharts by changing the conflicting (i.e. not recognized) reserved words/functionalty within the function. Indicator and strategy should work fine already.
1. Remove the using declaration near the top of the function code
2. Change throw Exception.Create to the corresponding PowerLanguage reserved words RaiseRunTimeError

That should do it.

Regards,

ABC

User avatar
LRP
Posts: 153
Joined: 07 Apr 2008
Location: Switzerland
Has thanked: 96 times
Been thanked: 15 times

Re: Ehlers Deviation-Scaled Moving Average (TASC July 2018)

Postby LRP » 12 Mar 2019

Hi ABC,

Thank you very much for this great and fast hints, it works!

Is there a look-up table available, to convert different reserved words from EL to PL replacements with the same functions?

Kind regards,
LRP


Return to “MultiCharts”