strategy · on price · open source
Supertrend strategy (ATR 10, factor 3)
Supertrend (ATR 10, factor 3) long-only strategy: plain-English rules, copyable code and a backtest with next-bar fills and costs. Free to run. Deepwick Script runs a subset of Pine Script.
What the Supertrend strategy does
ATR-based Supertrend trend-following: long when the Supertrend flips bullish (green line under price), exit when it flips bearish.
- 10/3 is the canonical setting; raise factor for fewer, longer trends.
- Combine with an ADX > 25 confirmation for strongest setups.
- Plot the Supertrend line on the chart for visual confirmation.
Entry and exit rules
Language reference: Deepwick Script.
Default inputs
| Input | Default | Min | Max |
|---|---|---|---|
ATR Length | 10 | 5 | 50 |
Factor | 3 | 1 | 10 |
Stop Loss % | 2 | 0.5 | 10 |
Take Profit % | 6 | 0 | 20 |
How Deepwick fills this strategy
- Market orders fill at the next bar's open.
- Stops and limits follow the bar's path: open → nearer extreme → farther extreme → close.
- Gaps fill at the open.
- Commission is charged on every fill, and slippage applies to market and stop fills, as set in
strategy().
Source code
Deepwick Script, a subset of Pine Script · read-only
//@version=6
strategy("Supertrend Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.05)
atrLen = input.int(10, "ATR Length", minval=5, maxval=50, step=1)
factor = input.float(3, "Factor", minval=1, maxval=10, step=0.1)
stopPct = input.float(2, "Stop Loss %", minval=0.5, maxval=10, step=0.1)
tpPct = input.float(6, "Take Profit %", minval=0, maxval=20, step=0.1)
colorUp = input.color("color.green", "Color Up")
colorDown = input.color("color.red", "Color Down")
[st, dir] = ta.supertrend(factor, atrLen)
up = dir < 0
longSignal = strategy.position_size == 0 and up
exitSignal = strategy.position_size > 0 and not up
if longSignal
strategy.entry("Long", strategy.long)
if strategy.position_size > 0
strategy.exit("Risk", stop=stopPct > 0 ? strategy.position_avg_price * (1 - stopPct / 100) : na, limit=tpPct > 0 ? strategy.position_avg_price * (1 + tpPct / 100) : na)
if exitSignal
strategy.close("Long", comment="Supertrend flip")
p_Up_Trend = plot(up ? st : na, "Up Trend", color=colorUp, style=plot.style_linebr, linewidth=2)
p_Down_Trend = plot(up ? na : st, "Down Trend", color=colorDown, style=plot.style_linebr, linewidth=2)
plotshape(longSignal, "Long", style=shape.triangleup, location=location.belowbar, color=colorUp, text="L")
plotshape(exitSignal, "Exit", style=shape.triangledown, location=location.abovebar, color=colorDown, text="X")
alertcondition(longSignal, "Supertrend long entry", "Supertrend flipped bullish")
alertcondition(exitSignal, "Supertrend exit", "Supertrend flipped bearish")
Run it in Deepwick
- Open a chart of any crypto pair or CFD.
- Click “Scripts” and add this strategy.
- Press Run and read the trades in the Strategy Tester.
FAQ
What are the best Supertrend settings?
The script ships with the common ATR 10 / factor 3. A higher factor gives fewer, later signals; a lower one reacts faster but whipsaws more. Test changes with the optimizer and check them out of sample with walk-forward before trusting them.
Does this Supertrend strategy go short?
No. It is long-only: it buys in an uptrend and goes flat when the Supertrend flips down. A short side needs its own strategy.entry with strategy.short.
No comments yet.
Sign in to comment.