Calculation of EMA as AB

i tray with different formulas to get the result of EMA as the result of EMA in AB
but it is not working.
i used SMA and i used closing price.

_SECTION_BEGIN("ema test culclation ");
PRESMA = Param( "PRESMA", 14, 2, 200, 1 );

FEMA2=(KEMA*(C-Ref(C,-1)))+Ref(C,-1); // test1 not  as Amibroker_EMA
TESTEMA2=(Sum(FEMA2,PRESMA))/PRESMA; // test2 not  as Amibroker_EMA
FEMA3= (KEMA* Close )+(SMA*(1-KEMA));
TESTEMA3=(Sum(FEMA3,PRESMA))/PRESMA; // test3 not  as Amibroker_EMA
Amibroker_EMA=EMA(Close,PRESMA);// as Amibroker

Plot( FEMA, "FEMA",colorBlack, styleLine | styleThick );
Plot( TESTEMA, "TESTEMA",colorBlack, styleLine | styleThick );
Plot( TESTEMA2, "TESTEMA2",colorBlack, styleLine | styleThick );
Plot( TESTEMA3, "TESTEMA3",colorBlack, styleLine | styleThick );
Plot( Amibroker_EMA, "Amibroker_EMA",colorBlack, styleLine | styleThick );


how to solve it
thank you

Your formula is completely wrong.

Google is your friend just GOOGLE for exponential moving average.
You would get this:

EMA is RECURSIVE calculation. It is first order IIR (infinite impulse response filter) You do not use Sum() and you do not use Ref() for EMA.

If you want to "reinvent the wheel" (why or why???) you have to run a LOOP

expmovavg = input;
smooth = 2 / (periods+1);
for( i = 1; i < BarCount; i++ )
    expmovavg[ i ] = smooth * input[ i ] + ( 1- smooth ) * expmovavg[ i - 1];

See also AMA:


this what i want to avoid

this your formula

EMA Today=(Value Today∗( 1+DaysSmoothing))+EMA Yesterday∗(1−( 1+DaysSmoothing))

what is ( EMA Yesterday)

can i use
ema= sum(EMA Today,14)

this for SMA from AB

sum(C,14) / 14

The formula "sum( CLOSE, 14 )" returns the sum of the preceding 14 closing prices. A 14-period simple moving average could be written "sum(C,14) / 14."

can i use
ema= sum(EMA Today,14) //

ema= sum(EMA Today,14)/14 // this one

when using ( for ) is it loop or not

slow = 2/(30+1);


Filter=1 ;

it is the same result .

when i try to do the formula for any N period i will face one point called (initial value )

like so

With the Efficiency Ratio (ER) and Smoothing Constant (SC), we are now ready to calculate Kaufman's Adaptive Moving Average (KAMA). Since we need an initial value to start the calculation, the first KAMA is just a simple moving average. The following calculations are based on the formula below.

Current KAMA = Prior KAMA + SC x (Price - Prior KAMA)

if it is the first calculation how to do the second.

or after the first step of (initial value ) what the is the second.

thank you

AMA takes care of it, you don’t need to worry about initial value

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.