Strategy vault / Trend following
Sunny Supertrend Strategy
The Sunny Supertrend strategy is a trend-following strategy based on the ATR and SuperTrend indicators. It can accurately predict trend reversals and works perfectly as a timing indicator. The strategy can increase…

Overview
The Sunny Supertrend strategy is a trend-following strategy based on the ATR and SuperTrend indicators. It can accurately predict trend reversals and works perfectly as a timing indicator. The strategy can increase patience and help traders enter and exit the markets at the right time.
Strategy Logic
The strategy uses the SuperTrend indicator to determine the current trend direction. When the SuperTrend indicator changes direction, we think a trend reversal may occur. In addition, the strategy also uses the direction of candlestick bodies for auxiliary judgment. When a potential reversal signal appears and the candlestick body direction is consistent with the previous one, the invalid signal is filtered out.
Specifically, the strategy generates trading signals according to the following logic:
- Use the SuperTrend indicator to determine the main trend direction
- When the SuperTrend indicator direction changes, a potential reversal signal is generated
- If the candlestick body direction is consistent with the previous one at this time, the reversal signal is filtered out
- If the candlestick body direction changes, the reversal signal is confirmed and a trading signal is generated
Advantage Analysis
- Based on the Supertrend indicator, it can accurately determine trend reversal points
- Filter out invalid signals by combining candlestick body directions to improve signal quality
- Suitable as a timing indicator to guide investors to choose reasonable entry and exit time
- Widely applicable to any timeframe and different varieties with strong adaptability
Risks and Solutions
The Supertrend indicator tends to generate redundant signals which need to be filtered Solution: This strategy uses the candlestick body direction for auxiliary judgment to effectively filter out invalid signals
Supertrend parameters are prone to over-optimization
Solution: Use default parameters to avoid manual tweaking and over-optimizationUnable to process ultra-fast trend reversals Solution: Adjust the ATR period parameter appropriately to cope with faster market movements
Optimization Directions
- Try different combinations of ATR period parameters
- Add Volume or volatility indicators to help filter signals
- Combine with other systems to improve strategy performance
- Develop stop loss mechanisms to control single loss
Conclusion
The Sunny Supertrend strategy is an efficient trend reversal strategy based on the SuperTrend indicator. It combines candlestick body directions for auxiliary judgment, which can effectively filter out invalid signals and improve signal quality. This strategy is simple to operate, highly adaptable, and can be widely used across multiple products and timeframes. By reasonably optimizing parameters and increasing stop loss mechanisms, the strategy's performance can be further enhanced.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 10 | ATR Length |
| v_input_float_1 | 3 | Factor |
| v_input_int_1 | true | Start Date |
| v_input_int_2 | true | Start Month |
| v_input_int_3 | 2021 | Start Year |
| v_input_int_4 | true | End Date |
| v_input_int_5 | 2 | End Month |
| v_input_int_6 | 2021 | End Year |
Source Pine Script
/*backtest
start: 2023-11-12 00:00:00
end: 2023-12-12 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Sunny Supertrend Strategy", overlay=true, default_qty_type=strategy.percent_of_equity)
atrPeriod = input(10, "ATR Length")
factor = input.float(3.0, "Factor", step = 0.01)
[_, direction] = ta.supertrend(factor, atrPeriod)
shor= close > open and close[1] > open[1] and close[2] > open[2]
lon = open > close and open[1] > close[1] and open[2] > close[2]
tt= ta.change(direction) < 0
ss= ta.change(direction) > 0
long= tt
longexit = lon or ss
short= ss
shortexit = shor or tt
longPosMem = false
longexitPosMem = false
shortPosMem = false
shortexitPosMem = false
longPosMem := long ? true : short ? false : longPosMem[1]
longexitPosMem := longexit ? true : shortexit ? false : longexitPosMem[1]
shortPosMem := short ? true : long ? false : shortPosMem[1]
shortexitPosMem := shortexit ? true : longexit ? false : shortexitPosMem[1]
longy = long and not(longPosMem[1])
longexity = longexit and not(longexitPosMem[1])
shorty = short and not(shortPosMem[1])
shortexity = shortexit and not(shortexitPosMem[1])
//Use this to customize the look of the arrows to suit your needs.
plotshape(longy, location=location.abovebar, color=color.green, style=shape.arrowup, text="Buy")
plotshape(longexity, location=location.top, color=color.green, style=shape.xcross, text="Buy exit")
plotshape(shorty, location=location.belowbar, color=color.red, style=shape.arrowdown, text="Sell")
plotshape(shortexity, location=location.bottom, color=color.red, style=shape.xcross, text="Sell exit")
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)
// STEP 1:
// Make input options that configure backtest date range
startDate = input.int(title="Start Date", defval=1, minval=1, maxval=31)
startMonth = input.int(title="Start Month",
defval=1, minval=1, maxval=12)
startYear = input.int(title="Start Year",
defval=2021, minval=1800, maxval=2100)
endDate = input.int(title="End Date",
defval=1, minval=1, maxval=31)
endMonth = input.int(title="End Month",
defval=2, minval=1, maxval=12)
endYear = input.int(title="End Year",
defval=2021, minval=1800, maxval=2100)
// STEP 2:
// Look if the close time of the current bar
// falls inside the date range
inDateRange = true
// STEP 3:
// Submit entry orders, but only when bar is inside date range
if (inDateRange and longy)
strategy.entry("enter long",strategy.long,when= longy)
strategy.close("long",when=longexity)
if (inDateRange and shorty)
strategy.entry("enter short",strategy.short,when = shorty)
strategy.close("short", when=shortexity)
Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-13. 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/Sunny-Supertrend-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