Strategy vault / Trend following
Quant Trading Strategy Based on SuperTrend Channel
This strategy generates Entries and Exits signals based on the SuperTrend channel indicator to realize automated quant trading. The SuperTrend channel indicator can identify breakout points and support/resistance…

Overview
This strategy generates Entries and Exits signals based on the SuperTrend channel indicator to realize automated quant trading. The SuperTrend channel indicator can identify breakout points and support/resistance levels clearly to determine the trend direction. This strategy incorporates the advantages of this indicator to conduct both long and short trading.
Strategy Principle
This strategy uses ATR and Donchian Channel to calculate two stop-loss lines for long and short positions. Specifically, it computes the ATR value using the ATR period and multiplier parameters, then adds and subtracts it from the average of highest high and lowest low to obtain the long and short stop-loss lines. When the closing price breaks above the long stop-loss line upwards, a long signal is generated. When the closing price breaks below the short stop-loss line downwards, a short signal is triggered.
After taking long or short positions, the stop-loss lines are updated dynamically to lock in profits. The new stop-loss line will not be lower or higher than the previous one, avoiding stop-loss penetration. When a new high or low appears between the current and previous stop-loss line, the stop-loss line is adjusted to the latest price.
Advantage Analysis
The biggest advantage of this strategy is that the SuperTrend channel indicator can clearly identify the trend direction and key support/resistance levels. Together with the dynamic ATR stop-loss, it can effectively control single trade loss.
Specifically, the two stop-loss lines in the SuperTrend channel indicator represent the position cost basis and the latest support/resistance. They offer very clear guidance for Entries and Exits. Meanwhile, the stop-loss line updates dynamically to lock in profits and prevent stop-loss penetration.
In general, this strategy enters timely when the trend is determined, controls risk via dynamic stop-loss, making it a relatively robust quantitative trading strategy.
Risk Analysis
The major risk of this strategy lies in the possibility of stop-loss penetration. When price fluctuates violently, the new stop-loss line may become lower or higher than the previous one, causing stop-loss penetration and increased losses.
Besides, the Entries signals generated by the SuperTrend channel indicator do not work well in ranging markets, leading to wrong trades occasionally. Manual intervention is required to determine the trend direction before enabling the strategy.
Optimization Directions
This strategy can be optimized in the following aspects:
Optimize the ATR period and multiplier parameters to find the best combination through backtesting various values and analyzing metrics like return and Sharpe ratio.
Add other indicators for signal filtration to avoid wrong Entries in ranging markets. Moving averages, Bollinger Bands etc. can be used to determine the trend direction.
Incorporate volume indicators to fine tune the stop-loss position. Stop-loss lines can be adjusted based on volume surges to further lock in profits.
Introduce machine learning models for adaptive parameter optimization. Techniques like RNN and LSTM can be leveraged to predict optimal parameter values dynamically.
Conclusion
This strategy originates from the SuperTrend channel indicator with a clear judgment of trend direction and relatively high winning rate. It also applies dynamic ATR tracking stop-loss to control single trade loss. Performance can be further improved through parameter optimization, indicator optimization etc. In general, it is a robust strategy suitable for automated quant trading.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 7 | ATR Period |
| v_input_2 | 7 | ATR Multiplier |
| v_input_3 | true | Show Buy/Sell Labels ? |
Source Pine Script
/*backtest
start: 2024-01-05 00:00:00
end: 2024-02-04 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
//EU ESCREVI ISSO TUDO, PARA FICAR BEM CLARO
strategy("SuperTrend Strategy", overlay=true)
//AQUI OS INPUTS PARA A SUPERTREND
length = input(title="ATR Period", type=input.integer, defval=7)
mult = input(title="ATR Multiplier", type=input.float, step=0.1, defval=7)
showLabels = input(title="Show Buy/Sell Labels ?", type=input.bool, defval=true)
//AQUI O CALCULO DO ATR STOPS
atr = mult * atr(length)
//AQUI A TRANSFORMAÇÃO DO ATR STOPS EM SUPERTREND
//-
//A LÓGICA PARA LONGSTOP
longStop = hl2 - atr
longStopPrev = nz(longStop[1], longStop)
longStop := close[1] > longStopPrev ? max(longStop, longStopPrev) : longStop
//A LÓGICA PARA SELLSTOP
shortStop = hl2 + atr
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := close[1] < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop
//DIREÇÃO DO INDICADOR
dir = 1
dir := nz(dir[1], dir)
dir := dir == -1 and close > shortStopPrev ? 1 :
dir == 1 and close < longStopPrev ? -1 : dir
//DEFININDO AS CORES DAS LINHAS DA SUPERTREND
longColor = color.lime
shortColor = color.red
//PLOTANDO NO GRÁFICO A SUPERTREND E A ESTRATÉGIA
plot(dir == 1 ? longStop : na, title="Long Stop", style=plot.style_linebr, linewidth=3, color=longColor)
buySignal = dir == 1 and dir[1] == -1
plot(dir == 1 ? na : shortStop, title="Short Stop", style=plot.style_linebr, linewidth=3, color=shortColor)
sellSignal = dir == -1 and dir[1] == 1
//DEFININDO AS FUNÇÕES DE COMPRA E VENDA
strategy.entry("long", strategy.long, when = buySignal)
strategy.entry("short", strategy.short, when = sellSignal)
Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-05. 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/Quant-Trading-Strategy-Based-on-SuperTrend-Channel.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
- Triple Supertrend Ichimoku Cloud Quantitative Trading StrategyPine Script · Trend following · 1d
- Multitimeframe Trend Hunter StrategyPine Script · Trend following · 1h
- Multi Indicator Dynamic Trend Following Strategy Based on EMA and SMAPine Script · Trend following · 1d
- SuperTrend Dynamic Take Profit with Time Filter Strategy Volatility Adaptive Quantitative Trading SystemPine Script · Trend following · 2h
- Trend Following Strategy Based on PMax IndicatorPine Script · Trend following · 5m
- Trend Tracking and Short term Trading Strategy Based on ADX IndicatorPine Script · Trend following · 1d