Posts

Showing posts with the label Moving Average

What Is an SMA Moving Average? Pine Script v6 Guide to Simple Moving Averages

Image
When analyzing price charts, raw candlestick data can appear noisy and difficult to interpret — the Simple Moving Average (SMA) is one of the most fundamental mathematical tools used to smooth that noise and reveal the underlying directional trend of a market. 1. What Is a Simple Moving Average (SMA)? A Simple Moving Average is a statistical calculation that computes the arithmetic mean of a price series over a fixed number of periods. At each bar, the SMA sums the most recent N closing prices and divides by N , producing a single smoothed value that "rolls" forward with each new bar. Mathematical Definition For a window of length $N$, the SMA at time $t$ is defined as: $$\text{SMA}_t = \frac{1}{N} \sum_{i=0}^{N-1} P_{t-i}$$ Where $P_{t-i}$ is the price at bar $t - i$. Every observation within the window receives an equal weight of $\frac{1}{N}$. Numerical Example Consider 5 consecutive closing prices: 10, 12, 11, 13,...

Why Do Traders Use EMA? Exponential Moving Average Explained with Pine Script v6

Image
When price moves sharply, a Simple Moving Average (SMA) reacts slowly because it weights every bar in its window equally. The Exponential Moving Average (EMA) solves this by applying a geometrically decaying multiplier, giving the most recent bars a heavier influence and allowing the line to track price changes more responsively. This article dissects the EMA formula mathematically, compares it to SMA behavior, and implements both from scratch in Pine Script v6. 1. The Mathematics Behind EMA The EMA is defined by a recursive formula. Given a smoothing factor k and a source series P : $$k = \frac{2}{n + 1}$$ $$\text{EMA}_t = P_t \cdot k + \text{EMA}_{t-1} \cdot (1 - k)$$ Where n is the period length. The multiplier k determines how aggressively the EMA responds to new data. A smaller n produces a larger k , meaning the EMA reacts faster. A larger n produces a smaller k , smoothing out noise more aggressively. Weight Distribution...