Strategy vault / Trend following
Trend Following Strategy Based on MBO Indicator
This strategy implements a simple trend following trading system based on the MBO indicator. The MBO indicator is similar to the MACD indicator, using the difference between fast and slow moving averages as trading…
Overview
This strategy implements a simple trend following trading system based on the MBO indicator. The MBO indicator is similar to the MACD indicator, using the difference between fast and slow moving averages as trading signals. It goes long when the fast moving average crosses above the slow one, and goes short when the fast crosses below the slow one. The strategy follows the trend of the MBO indicator to trade.
Strategy Logic
The strategy generates trading signals primarily based on the MBO indicator. The MBO indicator was developed by Bryan Strain and Mark Whitley. The indicator is calculated as:
MBO = 25-day Simple Moving Average - 200-day Simple Moving Average
The MBO line is then smoothed by calculating the 18-day Simple Moving Average of MBO, called SMAMBO.
When MBO crosses above SMAMBO, go long. When MBO crosses below SMAMBO, go short.
The key steps in the strategy logic are:
Calculate the 25-day and 200-day SMA, assigned to xFastAvg and xSlowAvg.
Calculate the MBO value: MBO = xFastAvg - xSlowAvg
Calculate the 18-day SMA of MBO, called SMAMBO.
Compare MBO and SMAMBO to generate trading signals pos:
If MBO > SMAMBO, pos = 1, go long
If MBO < SMAMBO, pos = -1, go short
Enter and exit trades based on the value of pos.
The strategy follows the trend exhibited by the MBO indicator. It is a typical trend following strategy.
Advantage Analysis
The advantages of this strategy include:
Lower trading frequency and avoid unnecessary stops by following medium/long term trends.
Flexible MBO parameters adaptable to different market conditions.
Simple and clear logic, easy to understand and implement, good for beginners.
Visual indicator clearly shows trend changes to support decisions.
High extensibility to optimize with stops, etc.
Risk Analysis
The risks of the strategy:
Trend following tends to vertical rallies/selloffs that can produce large losses.
Fails to exit in a timely manner when trend reverses, potentially increasing losses.
Inappropriate parameters may cause too frequent trading or inaccurate signals.
Susceptible to false breakout signals, needs filter mechanisms.
No stop loss mechanism results in unlimited loss potential.
Solutions:
Use reasonable SMA parameters, not too sensitive.
Add trend reversal indicator, exit quickly after reversal signaled.
Optimize parameters for accurate signals.
Add filters to avoid false breakouts.
Implement stop loss to control loss per trade.
Optimization Directions
The strategy can be improved in the following ways:
Add trend reversal indicator, implement timely stop loss after reversal.
Optimize SMA parameters to balance trade frequency and signal quality.
Add ATR stop loss to set reasonable stop levels to control loss.
Incorporate other indicators to filter false breakouts.
Implement position sizing based on trend strength.
Consider requiring triple confirmation before entry.
Build parameter optimization mechanism to adjust to different markets.
Summary
The strategy captures trends using a simple MBO indicator for trend following trading. The advantages are being simple, intuitive visuals, and beginner friendly. But risks like chasing rallies and inability to stop loss exist. We can optimize it by adding reversal signals, optimizing parameters, implementing stops etc, to build a robust trend following system. Overall it is a great introductory trend following strategy, and can become a practical daily trading tool after optimization.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 25 | Fastavg |
| v_input_2 | 200 | Slowavg |
| v_input_3 | 18 | Length |
| v_input_4 | false | Trade reverse |
Source Pine Script
/*backtest
start: 2023-09-08 00:00:00
end: 2023-10-08 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
////////////////////////////////////////////////////////////
// Copyright by HPotter v1.0 16/08/2018
// MBO indicator is the third component of TFS trading system. This indicator
// was developed by Bryan Strain and Mark Whitley.
// The idea of MBO is similar to moving average convergence/divergence (MACD)
// indicator. It is calculated by subtracting the 200-day moving average from
// the 25-day moving average.
//
// You can change long to short in the Input Settings
// WARNING:
// - For purpose educate only
// - This script to change bars colors.
////////////////////////////////////////////////////////////
strategy(title="TFS: MBO Backtest", shorttitle="TFS: MBO indicator")
Fastavg = input(25, minval=1)
Slowavg = input(200, minval=1)
Length = input(18, minval=1)
reverse = input(false, title="Trade reverse")
hline(0, color=blue, linestyle=line)
xFastAvg = sma(close, Fastavg)
xSlowAvg = sma(close, Slowavg)
nMBO = xFastAvg - xSlowAvg
xSMAMBO = sma(nMBO, Length)
pos = iff(nMBO > xSMAMBO, 1,
iff(nMBO < xSMAMBO, -1, nz(pos[1], 0)))
possig = iff(reverse and pos == 1, -1,
iff(reverse and pos == -1, 1, pos))
if (possig == 1)
strategy.entry("Long", strategy.long)
if (possig == -1)
strategy.entry("Short", strategy.short)
barcolor(possig == -1 ? red: possig == 1 ? green : blue )
plot(nMBO, color=red, style = histogram, title="TFS: MBO indicator")
plot(xSMAMBO, color=blue, title="SMA")Published by ChaoZhang on the FMZ strategy square · last modified 2023-10-09. 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/Trend-Following-Strategy-Based-on-MBO-Indicator.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
- Bollinger Bands and RSI Trend Following StrategyPine Script · Trend following · 1h
- Dual ATR Channel Trend Following StrategyPine Script · Trend following · 15m
- Dual MA Crossover Trend Tracking StrategyPine Script · Trend following · 1h
- Dual Moving Average Convergence Trend Tracking StrategyPine Script · Trend following · 1d
- Dual Moving Average Crossover Strategy with Stop Loss and Take ProfitPine Script · Trend following · 4h
- Dual SMA Crossover StrategyPine Script · Trend following · 5m