Codice su Tradestation dell’indicatore Adaptive Exponential Moving Average, pubblicato sul TASC di Aprile del 2018 di Vitali Apirine.
Indicator: Adaptive Exponential Moving Average
// Adaptive EMA Indicator
// TASC APR 2018
// Vitali Apirine
inputs:
Period( 10 ),
PDS( 10 ) ;
variables:
AEMA( 0 ) ;
AEMA = _AEMA( Period, PDS ) ;
Plot1( AEMA, “AEMA” ) ;
Strategy: Adaptive Exponential Moving Average
// Adaptive EMA Strategy
// TASC APR 2018
// Vitali Apirine
inputs:
Period( 10 ),
PDS( 10 ),
EMALength( 10 ) ;
variables:
AEMA( 0 ),
EMA( 0 ) ;
AEMA = _AEMA( Period, PDS ) ;
EMA = XAverage( Close, EMALength ) ;
if AEMA crosses over EMA then
Buy next bar at Market
else if EMA crosses over AEMA then
SellShort next bar at Market ;
Function: _AEMA
// Adaptive EMA Function
// TASC APR 2018
// Vitali Apirine
inputs:
Periods( numericsimple ),
PDS( numericsimple ) ;
variables:
MLTP1( 2 / ( Periods + 1 ) ),
MLTP2( 0 ),
Rate( 0 ) ;
MLTP2 = AbsValue( ( Close – Lowest( Low, PDS ) )
– ( Highest( High, PDS ) – Close )) / ( Highest( High, PDS )
– Lowest( Low, PDS ) ) ;
Rate = MLTP1 * ( 1 + MLTP2 ) ;
if CurrentBar <= Periods then
_AEMA = Average( Close, Periods )
else
_AEMA = _AEMA[1] + Rate * ( Close - _AEMA[1] ) ;