Strategy vault / Trend following
SuperTrend Multi Timeframe Backtest Strategy
The main idea of this strategy is to generate trading signals using the Supertrend indicator across multiple timeframes, and combine it with an intraday filter to square off open positions during the day, in order to…

Overview
The main idea of this strategy is to generate trading signals using the Supertrend indicator across multiple timeframes, and combine it with an intraday filter to square off open positions during the day, in order to implement multi-timeframe trading and improve signal quality.
Strategy Logic
The strategy first calls the supertrend function, passing in the parameters mult and len, to generate the Supertrend line superTrend and direction dir. Then it plots the Supertrend line chart. The input parameter intrady controls whether to square off open positions intraday. If intrady is true, intraday open positions will be squared off after 2:45pm.
The signal generation rules are: when the close price is above the Supertrend line, a buy signal is generated; when the close price is below the Supertrend line, a sell signal is generated. When a buy signal is received, a buy order will be executed to open a long position; when a sell signal is received, a sell order will be executed to open a short position. If the intraday filter intrady is enabled, i.e. set to true, all open long and short positions will be closed after 2:45pm every day.
Advantage Analysis
The biggest advantage of this strategy is that it uses the simple but practical Supertrend indicator to implement multi-timeframe trading signals generation. Supertrend itself already has good win rate and return. In addition, this strategy includes an intraday filter to avoid losses caused by intense intraday fluctuations.
In addition, the strategy is very concise, it implements the core logic with very little code, which is easy to understand, modify and expand. This provides great flexibility for users to adjust parameters or add other indicators etc. according to their own needs.
Risk Analysis
The main risk of this strategy is that the Supertrend indicator has some lag, which may lead to additional losses. In addition, the fixed multi-timeframe trading may also miss trading opportunities in the short term.
To mitigate these risks, it's recommended to optimize the Supertrend parameters mult and len to find the optimal parameter combination. Other indicators can also be tested to complement Supertrend and utilize more factors to enhance the stability of the strategy. Furthermore, the fixed intraday square-off time can be removed and a dynamic mechanism can be used to determine the square-off timing based on volatility conditions.
Optimization Directions
The main optimization directions for this strategy includes:
Test multiple sets of Supertrend parameters to find the optimal parameter combination.
Add other technical indicators like candlestick patterns, moving average etc. to filter signals with more factors.
Optimize and dynamically adjust the specific intraday square-off timing to reduce premature square-off.
Add stop loss mechanisms like fixed percentage stop loss or ATR stop loss.
Test suitable capital utilization ratio and position sizing strategies.
Backtest longer time period to verify parameter robustness.
Conclusion
In summary, this Supertrend multi-timeframe backtest strategy is very practical. It implements multi-timeframe trading with the simple Supertrend indicator and controls losses with the intraday filter. There is large room for optimization and users can adjust parameters or combine with other technical indicators according to their needs. The backtest performance is also relatively stable and reliable. Overall speaking, this strategy is suitable for medium-long term trend trading, and is also good for beginner to learn and practice modifications.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 3 | mult |
| v_input_2 | 5 | len |
| v_input_3 | false | Do you want to exit intrday position |
Source Pine Script
/*backtest
start: 2023-11-27 00:00:00
end: 2023-12-04 00:00:00
period: 45m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
//@Gurjant_Singh IISMA-Indian Institute of stock Market Analysis
strategy("SupterTrend ", overlay=true, initial_capital=100000, default_qty_type=strategy.percent_of_equity, default_qty_value=300, calc_on_order_fills=false, calc_on_every_tick=false)
mult = input(type=input.float, defval=3)
len = input(type=input.integer, defval=5)
[superTrend, dir] = supertrend(mult, len)
plot(superTrend)
intrady = input(false, "Do you want to exit intrday position", type = input.bool)
IntraDay_SquareOff = minute >= 45 and hour >= 14
buy = close > superTrend
sell = close < superTrend
if buy
strategy.entry("Buy", true)
if sell
strategy.entry("sell", false)
if intrady and IntraDay_SquareOff
strategy.close("buy")
strategy.close("sell")
Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-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/SuperTrend-Multi-Timeframe-Backtest-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