Support Board
Date/Time: Sat, 01 Mar 2025 08:16:29 +0000
Post From: How to apply EMA to an SMA in C++ and correctly warm-up with historical data.
[2021-09-21 15:20:26] |
ForgivingComputers.com - Posts: 1015 |
The SMA needs 5 bars to calculate its first value, and the EMA needs 5 bars of the SMA, so you will want to avoid calculating the SMA if not on bar 5 or higher, and the EMA unless on bar 10 or higher: SCSubgraphRef sma = sc.Subgraph[0];
SCSubgraphRef ema_of_sma = sc.Subgraph[1]; if (sc.Index < 5) return; sc.MovingAverage(sc.Close, sma, MOVAVGTYPE_SIMPLE, 5); if (sc.Index < 10) return; sc.MovingAverage(sma, ema_of_sma, MOVAVGTYPE_EXPONENTIAL, 5); |