Strategy vault / Trend following
Multiple Timeframe Trend Strategy
This strategy is a trading strategy that utilizes multiple timeframes. It mainly uses the long-term timeframe to determine the trend direction, medium-term timeframe to determine momentum direction, and short-term…

Overview
This strategy is a trading strategy that utilizes multiple timeframes. It mainly uses the long-term timeframe to determine the trend direction, medium-term timeframe to determine momentum direction, and short-term timeframe to locate specific entry points. The overall idea is to make decisions based on trend, momentum and entry timing in three different time spans.
Principles
The strategy is implemented mainly through the following:
Define different timeframes
- Long term (daily): to determine overall trend
- Medium term (4-hour): to determine momentum direction
- Short term (custom): to locate entry points
Determine long-term trend
- Use SMA to determine long-term trend direction
- If close is above SMA, define as uptrend
- If close is below SMA, define as downtrend
Determine medium-term momentum
- Use Stoch K and D lines
- When K line is above D line, define as upward momentum
- When K line is below D line, define as downward momentum
Locate entry points
- Long entry: long-term uptrend, medium-term Stoch upwards, short-term MA golden cross
- Short entry: long-term downtrend, medium-term Stoch downwards, short-term MA dead cross
Exit points
- Long exit: medium-term Stoch K line crosses below D line
- Short exit: medium-term Stoch K line crosses above D line
In summary, this strategy makes full use of information across timeframes, judging trend and timing from different dimensions, which can effectively filter false breakouts and select high probability entry points along the trend.
Advantages
The advantages of this strategy include:
The multiple timeframe design is scientific and meticulous, allowing for more accurate market trend judgment and avoiding being misled by short-term market noise.
Comprehensive conditions considering trend, momentum and entry timing help filter out many false signals.
Using Stoch to determine medium-term momentum is very precise and helps capture true market reversals.
The strict entry criteria avoid most false breakouts from price spikes.
Defined stop loss exit points effectively control risk for each trade.
Applicable to various market environments without being constrained by specific market conditions.
There is room for optimizing capital management, such as fixed stop loss percentage, dynamic position sizing etc.
Risks
There are also some risks to note for this strategy:
In ranging markets, there may be multiple stop loss hits.
Trend changes may not be captured in time, leading to improper trades.
Relying solely on Stoch for momentum judgment has limitations.
The strict entry criteria may cause missing out some trends.
The profit potential is relatively limited, unable to capture huge trends.
Some ways to mitigate the risks:
Fine tune parameters to lower error rates.
Add trend indicators to establish combined judgment.
Incorporate more indicators like MACD for momentum judgment.
Optimize stop loss to use trailing stop etc.
Promptly adjust stop loss and position size when major trend changes.
Optimization
Some ways to optimize the strategy:
Parameter optimization such as MA periods, Stoch settings to improve signal accuracy.
Add more indicators such as MACD, Bollinger Bands for enhanced judgment.
Optimize entry criteria, allow more trades at acceptable risk levels.
Use trailing stop loss or ATR-based stops.
Actively adjust position sizing when major trend changes.
Utilize machine learning to auto optimize parameters and rules.
Consider fundamentals, use key data releases to further confirm signals.
Test effectiveness across different products like forex, metals etc.
Conclusion
In summary, the core idea of this multiple timeframe trend strategy is to make decisions based on long-, medium- and short-term dimensions. The advantages lie in strict conditions and controllable risks, but parameters and rules need optimization for specific markets. Going forward, this strategy can be further enhanced by incorporating more indicators, optimizing stops, adding machine learning etc.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 5 | Entry timeframe (minutes) |
| v_input_2 | 50 | Moving Average Period (Trend) |
| v_input_3 | 18 | Stoch Length |
| v_input_4 | 80 | Stoch OB |
| v_input_5 | 20 | Stoch OS |
| v_input_6 | 14 | Stoch SmoothK |
| v_input_7 | 14 | Stoch SmoothD |
| v_input_8 | 7 | Moving Avg SM |
| v_input_9 | 21 | Moving Avg MD |
Source Pine Script
/*backtest
start: 2023-10-15 00:00:00
end: 2023-10-22 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
strategy("TUX MTF", overlay=true)
// MULTIPLE TIME FRAME STRATEGY
// LONG TERM --- TREND
// MED TERM --- MOMENTUM
// SHORT TERM --- ENTRY
// ENTRY POSITION TIMEFRAME
entry_position = input(title="Entry timeframe (minutes)", defval=5, minval=1, maxval=1440)
med_term = entry_position * 4
long_term = med_term * 4
// GLOBAL VARIABLES
ma_trend = input(title="Moving Average Period (Trend)", defval=50, minval=5, maxval=200)
// RSI
length = input(title="Stoch Length", defval=18, minval=5, maxval=200)
OverBought = input(title="Stoch OB", defval=80, minval=60, maxval=100)
OverSold = input(title="Stoch OS", defval=20, minval=5, maxval=40)
smoothK = input(title="Stoch SmoothK", defval=14, minval=1, maxval=40)
smoothD = input(title="Stoch SmoothD", defval=14, minval=1, maxval=40)
maSm = input(title="Moving Avg SM", defval=7, minval=5, maxval=50)
maMed = input(title="Moving Avg MD", defval=21, minval=13, maxval=200)
// LONG TERM TREND
long_term_trend = request.security(syminfo.ticker, tostring(long_term), sma(close,ma_trend)) > request.security(syminfo.ticker, tostring(long_term), close)
plot(request.security(syminfo.ticker, tostring(long_term), sma(close,ma_trend)), title="Long Term MA", linewidth=2)
// FALSE = BEAR
// TRUE = BULL
// MED TERM MOMENTUM
k = request.security(syminfo.ticker, tostring(med_term), sma(stoch(close, high, low, length), smoothK))
d = request.security(syminfo.ticker, tostring(med_term), sma(k, smoothD))
os = k >= OverBought or d >= OverBought
ob = k <= OverSold or d <= OverSold
// SHORT TERM MA X OVER
bull_entry = long_term_trend == false and os == false and ob == false and k > d and request.security(syminfo.ticker, tostring(entry_position), crossover(sma(close, maSm), sma(close, maMed)))
bear_entry = long_term_trend == true and os == false and ob == false and k < d and request.security(syminfo.ticker, tostring(entry_position), crossunder(sma(close, maSm), sma(close, maMed)))
bull_exit = crossunder(k,d)
bear_exit = crossover(k,d)
if (bull_entry)
strategy.entry("Long", strategy.long)
if (bear_entry)
strategy.entry("Short", strategy.short)
strategy.close("Long", when = bull_exit == true)
strategy.close("Short", when = bear_exit == true)
Published by ChaoZhang on the FMZ strategy square · last modified 2023-10-23. 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/Multiple-Timeframe-Trend-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
- Adaptive Trading Strategy Based on Stochastic RSI Dual Line CrossoverPine Script · Trend following · 4h
- EMA AROON ASHPine Script · Trend following · 3m
- EMA SMA Multi Indicator Comprehensive Trend Following StrategyPine Script · Trend following · 1h
- EMA200 and Stochastic RSI StrategyPine Script · Trend following · 1h
- Gaussian Channel Trend Following with Stochastic RSI Trading StrategyPine Script · Trend following · 1d
- Multi Dimensional Short Term Trend Predictor Technical Analysis and Volatility Adaptive Trading StrategyPine Script · Trend following · 1h