Strategy vault / Trend following
SuperTrend Trend Following Strategy
This strategy uses the SuperTrend indicator to determine price trend direction and generate trading signals, belonging to the trend following strategy category. It is specifically tested on Tesla (TSLA) 1-minute…
Overview
This strategy uses the SuperTrend indicator to determine price trend direction and generate trading signals, belonging to the trend following strategy category. It is specifically tested on Tesla (TSLA) 1-minute chart with decent results.
Strategy Logic
Calculate ATR and average of highest high and lowest low to determine SuperTrend upper and lower bands based on multiplier.
Determine if price breaks above upper band or below lower band to identify SuperTrend direction.
Long signal when price crosses above lower band. Short signal when price crosses below upper band.
Can choose to enter on next bar's open when signal is triggered, or immediately when price hits SuperTrend bands.
Advantages
SuperTrend clearly identifies trends, easy to program.
Flexible entry options suit different trader preferences.
Can quickly capture medium-term trends, suitable for trend following.
Frequent trading allows expansions and enhancements.
Risks
SuperTrend lags potentially missing best entries.
High trading frequency leads to larger slippage costs.
No risk control tools like stop loss.
Backtest solely on Tesla 1-min data, hard to prove strategy validity.
Possible Solutions:
Adjust parameters to reduce lag.
Add slippage control to limit costs.
Incorporate stop loss to control loss per trade.
Backtest across more products and timeframes for robustness.
Optimization Directions
Test different parameter sets to reduce lag.
Add filters to avoid whipsaws.
Optimize money management for higher efficiency.
Incorporate machine learning to predict SuperTrend direction.
Add other indicators to verify signals and improve stability.
Summary
This strategy uses SuperTrend to identify medium-term trend direction for trading signals, typical of trend following strategies. The overall framework is simple and effective, but can be further improved in areas like entry opportunities, risk management, parameter selection etc. With more historical data across products and integrated techniques like machine learning, it can be significantly enhanced in stability and profitability.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 3 | SuperTrend Multiplier |
| v_input_2 | 120 | SuperTrend Period |
Source Pine Script
/*backtest
start: 2023-08-24 00:00:00
end: 2023-09-23 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("QuantNomad - SuperTrend - TSLA - 1m", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)
// INPUTS //
st_mult = input(3, title = 'SuperTrend Multiplier', minval = 0, maxval = 100, step = 0.01)
st_period = input(120, title = 'SuperTrend Period', minval = 1)
// CALCULATIONS //
up_lev = hl2 - (st_mult * atr(st_period))
dn_lev = hl2 + (st_mult * atr(st_period))
up_trend = 0.0
up_trend := close[1] > up_trend[1] ? max(up_lev, up_trend[1]) : up_lev
down_trend = 0.0
down_trend := close[1] < down_trend[1] ? min(dn_lev, down_trend[1]) : dn_lev
// Calculate trend var
trend = 0
trend := close > down_trend[1] ? 1: close < up_trend[1] ? -1 : nz(trend[1], 1)
// Calculate SuperTrend Line
st_line = trend ==1 ? up_trend : down_trend
// Plotting
plot(st_line, color = trend == 1 ? color.green : color.red , style = plot.style_line, linewidth = 2, title = "SuperTrend")
plotshape(crossover( close, st_line), location = location.belowbar, color = color.green)
plotshape(crossunder(close, st_line), location = location.abovebar, color = color.red)
// Strategy with "when"
//strategy.entry("long", true, when = crossover( close, down_trend[1]))
//strategy.entry("short", false, when = crossunder(close, up_trend[1]))
// Strategy with stop orders
strategy.entry("long", true, stop = down_trend[1])
strategy.entry("short", false, stop = up_trend[1])Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-24. 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/SuperTrend-Trend-Following-Strategy.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