Strategy vault / Trend following
3 Supertrend Add In This Single Script
1st Supertrend Level 21 1 2nd Supertrend Level 14 2 3rd Supertrend Level 7 3 backtest
1st Supertrend Level 21 1 2nd Supertrend Level 14 2 3rd Supertrend Level 7 3
backtest

Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 21 | ATR Length |
| v_input_float_1 | true | Factor |
| v_input_2 | 14 | ATR Length |
| v_input_float_2 | 2 | Factor |
| v_input_3 | 7 | ATR Length |
| v_input_float_3 | 3 | Factor |
Source Pine Script
/*backtest
start: 2022-05-03 00:00:00
end: 2022-05-09 23:59:00
period: 30m
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
indicator("Supertrend", overlay=true, timeframe="", timeframe_gaps=true)
NEW1_atrPeriod = input(21, "ATR Length")
NEW1_factor = input.float(1.0, "Factor", step = 0.01)
[supertrend_1, direction_1] = ta.supertrend(NEW1_factor, NEW1_atrPeriod)
bodyMiddle_1 = plot((open + close) / 2, display=display.none)
upTrend_1 = plot(direction_1 < 0 ? supertrend_1 : na, "Up Trend", color = color.green, style=plot.style_linebr)
downTrend_1 = plot(direction_1 < 0? na : supertrend_1, "Down Trend", color = color.red, style=plot.style_linebr)
fill(bodyMiddle_1, upTrend_1, color.new(color.green, 90), fillgaps=false)
fill(bodyMiddle_1, downTrend_1, color.new(color.red, 90), fillgaps=false)
NEW2_atrPeriod = input(14, "ATR Length")
NEW2_factor = input.float(2.0, "Factor", step = 0.01)
[supertrend_2, direction_2] = ta.supertrend(NEW2_factor, NEW2_atrPeriod)
bodyMiddle_2 = plot((open + close) / 2, display=display.none)
upTrend_2 = plot(direction_2 < 0 ? supertrend_2 : na, "Up Trend", color = color.green, style=plot.style_linebr)
downTrend_2 = plot(direction_2 < 0? na : supertrend_2, "Down Trend", color = color.red, style=plot.style_linebr)
fill(bodyMiddle_2, upTrend_2, color.new(color.green, 90), fillgaps=false)
fill(bodyMiddle_2, downTrend_2, color.new(color.red, 90), fillgaps=false)
NEW3_atrPeriod = input(7, "ATR Length")
NEW3_factor = input.float(3.0, "Factor", step = 0.01)
[supertrend_3, direction_3] = ta.supertrend(NEW3_factor, NEW3_atrPeriod)
bodyMiddle_3 = plot((open + close) / 2, display=display.none)
upTrend_3 = plot(direction_3 < 0 ? supertrend_3 : na, "Up Trend", color = color.green, style=plot.style_linebr)
downTrend_3 = plot(direction_3 < 0? na : supertrend_3, "Down Trend", color = color.red, style=plot.style_linebr)
fill(bodyMiddle_3, upTrend_3, color.new(color.green, 90), fillgaps=false)
fill(bodyMiddle_3, downTrend_3, color.new(color.red, 90), fillgaps=false)
if direction_1<0 and direction_2 <0 and direction_3 <0
strategy.entry("Enter Long", strategy.long)
else if direction_1>0 and direction_2 >0 and direction_3 >0
strategy.entry("Enter Short", strategy.short)Published by ChaoZhang on the FMZ strategy square · last modified 2022-05-11. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/3-Supertrend-Add-In-This-Single-Script.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- Advanced Supertrend Indicator Trading Mechanism Optimization StrategyPine Script · Trend following · 1d
- Dynamic Trend Following SuperTrend Triple Enhancement StrategyPine Script · Trend following · 1d
- Heiken Ashi and Super Trend Combination StrategyPine Script · Trend following · 1d
- Multi Indicator Dynamic Trend Following Strategy Based on EMA and SMAPine Script · Trend following · 1d
- Multi Period SuperTrend Dynamic Trading StrategyPine Script · Trend following · 1d
- Precision Trading Strategy and Risk Management System Based on SuperTrend IndicatorPine Script · Trend following · 1d