← Back to Library
Strategies

Supertrend + MACD Strategy

A Pine Script v6 Trend Following strategy. Combines Supertrend for direction and MACD for momentum.

Pine Script V6
//@version=6
strategy("Supertrend + MACD Strategy [Codon.pro]", overlay=true, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
st_factor = input.float(3.0, "Supertrend Factor")
st_pd = input.int(10, "Supertrend Period")
fast_len = input.int(12, "MACD Fast Length")
slow_len = input.int(26, "MACD Slow Length")
sig_len = input.int(9, "MACD Signal Length")
[supertrend, direction] = ta.supertrend(st_factor, st_pd)
[macdLine, signalLine, _] = ta.macd(close, fast_len, slow_len, sig_len)
is_uptrend = direction < 0
is_downtrend = direction > 0
macd_bullish = macdLine > signalLine
if is_uptrend and macd_bullish
    strategy.entry("Long", strategy.long)
if is_downtrend
    strategy.close("Long")
plot(supertrend, color = direction < 0 ? color.green : color.red, linewidth=2, title="Supertrend")