SMA, EMA, RSI and MACD Explained
These four indicators summarize past prices in different ways. Compare their formulas, define a signal precisely, and test it with costs and a separate evaluation period. Agreement between indicators derived from the same prices is not independent evidence of a profitable trade.
What does each indicator measure?
SMA is an equally weighted average of the selected observations. EMA weights recent observations more heavily. RSI compares smoothed gains and losses. MACD compares two moving averages and then measures their distance from a signal average. Each depends on the input series, timeframe and calculation settings. A level, crossover or divergence describes a condition; it does not establish a future return probability.
How It Works
- 1
SMA: add the last N prices and divide by N. For closes 100, 102 and 104, a 3-period SMA is 102. If the next close is 108, the window becomes 102, 104 and 108, giving 104.67. A price above that average is a relative position, not proof of an uptrend.
- 2
EMA: with alpha = 2/(N+1), the next EMA is alpha times the new price plus (1-alpha) times the prior EMA. With N=3, prior EMA=102 and next close=108, the new EMA is 105. Initial seeding and available history affect early values; EMA does not necessarily cross or turn before SMA in every price path.
- 3
RSI: use Wilder-smoothed average gains and losses. With average gain 2 and average loss 1, RS=2 and RSI=100-100/(1+2)=66.67. A 14-period lookback and 70/30 reference levels are common settings, not universal thresholds. Divergence can persist without reversal.
- 4
MACD: a common configuration subtracts EMA(26) from EMA(12), uses EMA(9) of that difference as the signal, and subtracts signal from MACD for the histogram. If the fast EMA is 105, slow EMA 102 and signal 2, MACD=3 and histogram=1. A positive MACD and a rising histogram describe different conditions.
Separate the learning and testing steps
| Feature | Pineify Coding Agent | Indicator on a chart | Strategy backtest |
|---|---|---|---|
| Purpose | Draft source from a specified rule | Display the calculation on chosen data | Simulate explicit entries, exits and sizing |
| Required inputs | Formula, timeframe, timing and missing-data rules | Symbol, history and indicator settings | Execution assumptions, costs and test period |
| What it does not establish | Generated code is not proof of correctness | A plotted crossover is not a broker fill | Historical performance is not a future guarantee |
Example Research Tasks
Verify an SMA window
Example question
“How does replacing one observation change the SMA?”
Illustrative response
Illustrative values: replacing 100 with 108 in [100,102,104] changes the average from 102 to 104.67. Check the exact same window before comparing platforms.
Distinguish MACD signs
Example question
“Can MACD be positive while the histogram is negative?”
Illustrative response
Yes. If MACD is 3 and its signal is 4, the histogram is -1. The fast average remains above the slow average while MACD is below its signal.
Specify an SMA-RSI rule
Example question
“Draft a strategy for a confirmed 20-SMA cross above 50-SMA with RSI(14)>50.”
Illustrative response
Define exits, position sizing, commissions, slippage and the evaluation period before generating code. Review syntax and inspect individual simulated trades; no backtest result is supplied here.
Sample Questions to Try
Frequently Asked Questions
Sources
This content is for educational and informational purposes only and does not constitute financial advice.