Trend Indicators
Trend indicators help identify the direction of price movements - whether the market is in an uptrend, downtrend, or moving sideways. These indicators smooth out price data to help traders spot the overall trend.
💡 How to use these examples
- Each example shows real code you can copy and use
- Try the interactive demo by adding your own values to see how the indicator responds
- Values marked with "—" indicate not enough data has been provided yet (indicator not stable)
- Click "Reset" to restore the default example values
Simple Moving Average (SMA)
Calculates the average of a specified number of prices
Code Example
import { SMA } from 'trading-signals';
const sma = new SMA(5);
sma.add(81);
sma.add(24);
sma.add(75);
sma.add(21);
sma.add(34);
console.log(sma.getResult()); // 47
Interactive Demo
Exponential Moving Average (EMA)
Gives more weight to recent prices, reacting faster to price changes
Code Example
import { EMA } from 'trading-signals';
const ema = new EMA(5);
ema.add(81);
ema.add(24);
ema.add(75);
ema.add(21);
ema.add(34);
console.log(ema.getResult());
Interactive Demo
Double Exponential Moving Average (DEMA)
Reduces lag by applying EMA twice, providing faster signals
Code Example
import { DEMA } from 'trading-signals';
const dema = new DEMA(5);
for (const price of prices) {
dema.add(price);
}
console.log(dema.getResult());
Interactive Demo
Weighted Moving Average (WMA)
Assigns higher weights to recent data points
Code Example
import { WMA } from 'trading-signals';
const wma = new WMA(5);
wma.add(91);
wma.add(90);
wma.add(89);
wma.add(88);
wma.add(90);
console.log(wma.getResult());
Interactive Demo
MACD (Moving Average Convergence Divergence)
Shows the relationship between two moving averages
Code Example
import { EMA, MACD } from 'trading-signals';
// MACD expects indicator instances, not numbers
const macd = new MACD(
new EMA(12), // short
new EMA(26), // long
new EMA(9) // signal
);
for (const price of prices) {
macd.add(price);
}
const result = macd.getResult();
console.log('MACD:', result?.macd);
console.log('Signal:', result?.signal);
console.log('Histogram:', result?.histogram);
Interactive Demo
Other Trend Indicators
ADX
Average Directional Index - measures trend strength
PSAR
Parabolic SAR - identifies potential reversal points
VWAP
Volume Weighted Average Price - average price weighted by volume
DMA
Dual Moving Average - compares two moving averages
RMA
Relative Moving Average - smoothed moving average (Wilder's method)
WSMA
Wilder's Smoothed Moving Average
DX
Directional Movement Index
⚠️ Important Disclaimer
Signals by technical trading indicators are not guarantees. Always use proper risk management, confirm signals with multiple indicators, and never rely on a single indicator for trading decisions. This library is for educational purposes and does not constitute financial advice.