ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Reg. rolling my own Exponential moving average with the financhart.
Posted by Jan K. Nielsen on May-03-2024 17:26
Hello

I try to create my own exponential moving average(EMA).
I am able to calculate all the values needed and show the graph.
As the start EMA I use a 10 days simple moving average and an Alpha
that is adjustable. The problem is that I need to move the line 10 days to the right.

I have experimentet but seem to be stuck and feel that Its just a little thing that needs
to be added. To put it short the EMA grapha is not at an alignment with the buildin closing price line.

Any suggestions ?


Best regards, Jan.

  Re: Reg. rolling my own Exponential moving average with the financhart.
Posted by Peter Kwan on May-05-2024 00:29
Hi Jan K,

Are you using the ArrayMath utility to calculate the EMA?

The ArrayMath calculate the EMA using the standard method. All EMA data points should align with the corresponding closing price data point.

My understanding is that you want to initialize the first EMA value to equal to the 10 days SMA value. As the 10 days SMA value is for the 10th data point, using it as the 1st EMA value causes it not to align with the first data point. Your requirement is to shift the EMA so that the first EMA value is plotted at the 10th data point, and I assume it means the first 9 EMA value are not used any more.

You may try to using ArrayMath.trim to remove the first 10 EMA values, then use ArrayMath.insert2 to add the SMA value to the beginning of the EMA, then use ArrayMath.insert2 to add 9 Chart.NoValue values. As 10 values are remove and 10 values are inserted, the array length is unchanged, but the first 10 elements are replaced with 9 Chart.NoValue plus your SMA. The first visible point is at point 10, and it aligns with the closing data at point 10.

Note the the above is in .NET/Java syntax. The Chart.NoValue may have different syntax in other programming languages.

Best Regards
Peter Kwan