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 |