Strategy vault / Trend following
SUPERTREND Trend following Long Position with Stop loss and Take profit Strategy
This strategy utilizes the Supertrend indicator to determine entry and exit points for trades. Supertrend is a trend-following indicator that combines the concepts of dynamic support/resistance and price breakouts…

Overview
This strategy utilizes the Supertrend indicator to determine entry and exit points for trades. Supertrend is a trend-following indicator that combines the concepts of dynamic support/resistance and price breakouts. The strategy aims to capture strong uptrends while strictly controlling risk, and it trades with a 1:5 risk-reward ratio. When the price breaks above the Supertrend upper band, it enters a long position and sets a stop-loss and take-profit price based on the predefined risk-reward ratio. Once the price breaks below the Supertrend lower band, the strategy closes the long position.
Strategy Principles
- Calculate the upper and lower bands of the Supertrend indicator. Supertrend uses ATR (Average True Range) and a factor to calculate dynamic support and resistance levels.
- Check for long entry conditions: When the closing price breaks above the Supertrend upper band, enter a long position.
- Calculate stop-loss and take-profit prices: Based on the current closing price and the predefined risk-reward ratio (e.g., 1:5), calculate the stop-loss and take-profit prices.
- Submit a long order: Open a long position with the calculated stop-loss and take-profit prices.
- Check for long exit conditions: When the closing price breaks below the Supertrend lower band, close the long position.
Advantage Analysis
- Trend-following: The Supertrend indicator can effectively capture strong trends, helping the strategy profit from uptrends.
- Dynamic stop-loss: By using ATR to calculate dynamic support and resistance levels, Supertrend provides a dynamic stop-loss for the strategy to control risk.
- Risk-reward control: The strategy allows users to predefine a risk-reward ratio (e.g., 1:5) to control the risk and potential reward for each trade.
- Simplicity: The strategy logic is straightforward and easy to understand and implement.
Risk Analysis
- Trend reversals: In sudden trend reversals, the strategy may suffer losses as it relies on the continuity of the trend.
- Parameter sensitivity: The strategy's performance may be sensitive to the parameters of the Supertrend, such as the ATR factor and ATR length. Inappropriate parameters may lead to false signals.
- Lack of volatility: In low volatility market conditions, the strategy may underperform as prices may oscillate between the upper and lower bands, leading to frequent trades and losses due to slippage and commissions.
Optimization Directions
- Dynamic parameter optimization: Implement a parameter optimization routine to dynamically adjust Supertrend parameters based on different market conditions. This can improve the adaptability and robustness of the strategy.
- Combine with other indicators: Incorporate other technical indicators, such as RSI or MACD, to confirm trend strength and filter out false signals.
- Market condition adaptation: Develop logic to identify different market conditions (e.g., trending, ranging) and adjust strategy parameters or disable the strategy accordingly.
- Money management optimization: Optimize position sizing and risk management rules to improve the risk-adjusted returns of the strategy.
Summary
This strategy leverages the Supertrend indicator to follow strong uptrends while strictly controlling risk. It provides a simple yet effective framework for capturing trending opportunities. However, the strategy may face risks such as trend reversals and parameter sensitivity. Further improvements can be made through dynamic parameter optimization, combining with other indicators, adapting to market conditions, and optimizing money management. Overall, this Supertrend strategy offers a solid foundation for trend-following trading.
Source Pine Script
/*backtest
start: 2024-05-01 00:00:00
end: 2024-05-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Supertrend Strategy with 1:5 Risk Reward", overlay=true)
// Supertrend Indicator
factor = input(3.0, title="ATR Factor")
atrLength = input(10, title="ATR Length")
[supertrendUp, supertrendDown] = ta.supertrend(factor, atrLength)
supertrend = ta.crossover(ta.lowest(close, 1), supertrendDown) ? supertrendDown : supertrendUp
plot(supertrend, title="Supertrend", color=supertrend == supertrendUp ? color.green : color.red, linewidth=2, style=plot.style_line)
// Strategy parameters
risk = input(1.0, title="Risk in %")
reward = input(5.0, title="Reward in %")
riskRewardRatio = reward / risk
// Entry and exit conditions
longCondition = ta.crossover(close, supertrendUp)
if (longCondition)
// Calculate stop loss and take profit levels
stopLossPrice = close * (1 - (risk / 100))
takeProfitPrice = close * (1 + (reward / 100))
// Submit long order
strategy.entry("Long", strategy.long, stop=stopLossPrice, limit=takeProfitPrice)
// Exit conditions
shortCondition = ta.crossunder(close, supertrendDown)
if (shortCondition)
strategy.close("Long")
Published by ChaoZhang on the FMZ strategy square · last modified 2024-06-17. 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-Long-Position-with-Stop-loss-and-Take-profit-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
- 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
- Triple Supertrend Ichimoku Cloud Quantitative Trading StrategyPine Script · Trend following · 1d
- Heiken Ashi Trend Following Strategy Multi Timeframe Trend Identification System with Multi Layer Stop Loss MechanismPine Script · Trend following · 1d