How a simple moving average works
An n-period SMA adds the latest n values and divides by n. With five closes of 100, 101, 102, 103 and 104, the 5-period SMA is 102. At the next bar, the oldest value drops out and the new one enters; all values remaining in the window have equal weight.
If the new close is 110, the average of 101, 102, 103, 104 and 110 becomes 104. The change in the SMA depends on both the incoming value and the one leaving the window.
How an exponential moving average works
EMA uses a recursive relationship: new EMA = alpha × new price + (1 − alpha) × previous EMA. Under the common convention, alpha = 2 ÷ (n + 1). For n = 5, alpha is one third. If the previous EMA is 102 and the new price is 110, the new value is approximately 104.67.
The example assumes a previous value is already available. Initialisation can vary between implementations, such as using an initial SMA; a consistent warm-up period is needed when comparing series or platforms. Giving recent data more weight makes EMA more responsive, but does not remove lag or false signals.
Three different rules to keep separate
Price above an average, a rising average, and a fast average above a slow one are different conditions. Price can be above an average that is still falling; two averages can remain crossed while price retraces.
To test a crossover, require the relationship between the two averages to change between two bars. Simply checking that the fast average is above the slow one describes a state, rather than a new event; without another rule, you could generate several entries during the same phase.
A fair comparison of SMA and EMA
Keep the asset, timeframe, applied prices, test period and trade management the same. Change only the averaging method and measure the effect on trade frequency, entry lag, costs and drawdown. A faster response may catch a move earlier but also produce more crossovers during a sideways phase.
If you use an average from a higher timeframe, decide whether to read it only after that bar closes. A daily average calculated using the day’s final close was not available at the start of that day. The TotalTrade catalogue includes Moving Average and Moving Average Exponential; check chart parameters before comparing them.


