Strategy vault / Trend following
Supertrend BarUpDn Fusion Strategy
The Supertrend BarUpDn Fusion strategy is a strategy that fuses the Supertrend indicator and the BarUpDn indicator. The strategy will go long if either the Supertrend or BarUpDn indicator gives a long signal, and…

Overview
The Supertrend BarUpDn Fusion strategy is a strategy that fuses the Supertrend indicator and the BarUpDn indicator. The strategy will go long if either the Supertrend or BarUpDn indicator gives a long signal, and will go short if either indicator gives a short signal.
Strategy Principle
The strategy mainly utilizes two indicators:
Supertrend Indicator: This indicator determines the trend direction based on Average True Range and a factor. It gives long signals when price is in an uptrend channel and short signals when price is in a downtrend channel.
BarUpDn Indicator: This indicator judges if the current bar is a bullish bar (close higher than open) or bearish bar (open higher than close). It returns 1 for bullish bars and -1 for bearish bars.
The main logic of the strategy is:
Go long when Supertrend is long and BarUpDn is bullish.
Go short when Supertrend is short and BarUpDn is bearish.
Close positions timely when Supertrend changes direction.
Through this fusion, the strategy can utilize both the trend judging capability of Supertrend and the short-term judging capability of BarUpDn to achieve better entry timing.
Advantage Analysis
The main advantages of this strategy are:
Improved accuracy by fusing multiple indicators. Utilizing both the trend judging of Supertrend and the short-term judging of BarUpDn can improve entry timing accuracy.
Timely stop loss. Quickly cutting losses when the main indicator Supertrend changes direction can avoid enlarging losses.
Simple and easy to use. The strategy only uses a combination of two common indicators, making it very simple and easy to use.
Strong adaptability. Supertrend itself has adjustable parameters to adapt to different products and timeframes.
Risk Analysis
There are also some risks with this strategy:
Incorrect judging from improper fusion may cause misjudging. Timely stop loss when indicators give inconsistent signals.
Improper parameter tuning affects performance. Supertrend's ATR Length and Factor need to be adjusted for different products.
Short-term reversals may cause minor losses. Small losses may occur during short-term price reversals before Supertrend turns direction.
Optimization Directions
The strategy can be optimized from the following aspects:
Add stop loss strategies like moving stop loss, time stop loss, breakout stop loss etc. to further control risks.
Optimize parameters of Supertrend to find the best parameter combinations for different products and timeframes, e.g. via machine learning.
Add more indicator fusion to build a voting mechanism and improve judging stability.
Incorporate more market factors like volume change, spread change etc. to judge signal reliability and filter misleading signals.
Summary
The Supertrend BarUpDn Fusion Strategy fuses trend judging and short-term judging by combining simple indicators, improving entry timing accuracy while keeping simplicity and ease of use. The strategy can be further enhanced by parameter optimization, stop loss optimization, indicator voting etc.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 10 | ATR Length |
| v_input_2 | 3 | Factor |
Source Pine Script
/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Supertrend and BarUpDn Indicator Fusion", overlay=true)
// Supertrend indicator
atrLength = input(10, title="ATR Length")
factor = input(3.0, title="Factor")
[supertrend, direction] = ta.supertrend(factor, atrLength)
lastBar = 0
// BarUpDn indicator
barUpDn = close > open and open > close[1] ? 1 : close < open and open < close[1] ? -1 : 0
if (barUpDn == 1)
lastBar := 1
else if barUpDn == -1
lastBar := -1
// Determine long or short position
longCondition = (direction > 0 and barUpDn > 0) or (direction > 0 and lastBar == 1)
shortCondition = (direction < 0 and barUpDn < 0) or (direction < 0 and lastBar == -1)
// Enter long or short position
if (longCondition)
strategy.entry("Long", strategy.long)
lastBar := 1
else if (shortCondition)
strategy.entry("Short", strategy.short)
lastBar := -1
if (direction < 0 and barUpDn > 0)
strategy.entry("Long", strategy.long)
// Exit long or short position
if (direction > 0 and barUpDn < 0)
strategy.entry("Short", strategy.short)
// Exit long or short position
// if (direction < 0 and barUpDn > 0 or direction > 0 and barUpDn < 0)
// strategy.close_all()
Published by ChaoZhang on the FMZ strategy square · last modified 2024-01-31. 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-BarUpDn-Fusion-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