Strategy vault / Trend following
Trend Bull Bear Crossover Trading Strategy
This strategy uses the moving average crossover principle to determine the trend direction and generate buy and sell signals. It is simple and reliable, suitable for investors seeking steady returns.
Overview
This strategy uses the moving average crossover principle to determine the trend direction and generate buy and sell signals. It is simple and reliable, suitable for investors seeking steady returns.
Principle
The strategy employs two moving averages, a 7-day MA as the fast line and a 5-month MA as the slow line. The fast line captures price changes swiftly while the slow line filters out noise and determines the trend direction. When the fast line breaks above the slow line from below, it is considered a bullish signal to go long. When the fast line breaks down the slow line from above, it is regarded as a bearish signal to go short.
Specifically, the strategy calculates the 7-day simple moving average (SMA) and 5-month SMA, plotting them on the price chart. When the 7-day line crosses above the 5-month line from below, a buy signal is generated. When the 7-day line crosses below the 5-month line from above, a sell signal is triggered. The strategy also visualizes the signal periods.
Advantages
The strategy has the following advantages:
Simple and reliable theoretical basis, based on the widely known moving average crossover principle.
Only two moving averages are used, with simple parameter selection and easy implementation.
The fast and slow lines work together effectively to identify trends and filter out market noise.
Different timeframes are captured through different period MAs, detecting trend changes on multiple scales.
Simple implementation with clear, easy-to-understand logic.
Visualized signals are clear and intuitive for deciding trades.
Risks
There are also some risks:
Prone to false signals relying solely on MA crosses.
Unable to judge trend strength effectively, causing frequent stop loss in ranging markets.
Fixed MA periods cannot adapt to market changes, requiring parameter optimization.
Entry and exit levels unclear, with some whipsaw risks.
Simplistic theoretical basis may compromise performance and profit potential.
Enhancement
The strategy can be improved in the following aspects:
Add other indicators to determine entry and exit levels, such as KDJ for overbought/oversold.
Implement stop loss mechanisms like trailing stop to limit losses.
Optimize MA periods to adapt to different market cycles.
Add volume filter to avoid false breakouts.
Evaluate trend strength, e.g. MA slope, to scale position size.
Incorporate multiple timeframes for better trend continuity.
Conclusion
The strategy identifies bull/bear trends simply and reliably based on MA crossover theory. The pros are simplicity and ease of use, while the cons are inherent trend-following risks. Fine-tuning parameters, adding auxiliary indicators etc. can improve strategy performance. Investors can choose to use it based on their risk appetite.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1_close | 0 | Kaynak: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4 |
| v_input_2 | 0 | Hareketli Ortlama Tipi: SMA | EMA | WMA |
| v_input_3 | 7 | Günlük Bar Sayısı |
| v_input_4 | 5 | Aylık Bar Sayısı |
| v_input_5 | 2020 | Backtest Başlangıç Tarihi |
| v_input_6 | true | Str. Başlama Tarihi Gün |
| v_input_7 | true | Str. Başlama Tarihi Ay |
| v_input_8 | 2015 | Str. Başlama Tarihi Yıl |
| v_input_9 | true | Str. Bitiş Tarihi Gün |
| v_input_10 | true | Str. Bitiş Tarihi Ay |
| v_input_11 | 9999 | Str. Bitiş Tarihi Yıl |
Source Pine Script
/*backtest
start: 2022-09-30 00:00:00
end: 2023-10-06 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dadashkadir
//@version=4
strategy("Mount MaV - Day MaV CrossOver Strgty", shorttitle="Yusram Str.", overlay=true)
src = input(title= "Kaynak", type=input.source, defval=close)
mav = input(title="Hareketli Ortlama Tipi", defval="SMA", options=["SMA", "EMA", "WMA"])
Gbar = input(title="Günlük Bar Sayısı", defval=7, minval=1, maxval=999)
Abar = input(title="Aylık Bar Sayısı", defval=5, minval=1, maxval=999)
//displacement = input(20, minval=1, title="Displacement")
getMA(src, length) =>
ma = 0.0
if mav == "SMA"
ma := sma(src, length)
ma
if mav == "EMA"
ma := ema(src, length)
ma
if mav == "WMA"
ma := wma(src, length)
ma
ma
long = "M" //Aylık
ln = security(syminfo.ticker, long, src)
lnma = getMA(ln, Abar)
gnma = getMA(src, Gbar)
col1= gnma>gnma[1]
col3= gnma<gnma[1]
colorM = col1 ? color.green : col3 ? color.navy : color.yellow
l1 = plot(lnma, title="MhO", trackprice = true, style=plot.style_line, color=color.red, linewidth=3)
l2 = plot(gnma, title="DhO", trackprice = true, style=plot.style_line, color=colorM, linewidth=3)
fill(l1, l2, color = lnma < gnma ? color.green : color.red, title="Gölgelendirme", transp=90)
zamanaralik = input (2020, title="Backtest Başlangıç Tarihi")
al = crossover (gnma, lnma) and zamanaralik <= year
sat = crossover (lnma, gnma) and zamanaralik <= year
plotshape(al, title = "Giriş", text = 'Al', style = shape.labelup, location = location.belowbar, color= color.green, textcolor = color.white, transp = 0, size = size.tiny)
plotshape(sat, title = "Çıkış", text = 'Sat', style = shape.labeldown, location = location.abovebar, color= color.red, textcolor = color.white, transp = 0, size = size.tiny)
FromDay = input(defval = 1, title = "Str. Başlama Tarihi Gün", minval = 1, maxval = 31)
FromMonth = input(defval = 1, title = "Str. Başlama Tarihi Ay", minval = 1, maxval = 12)
FromYear = input(defval = 2015, title = "Str. Başlama Tarihi Yıl", minval = 2005)
ToDay = input(defval = 1, title = "Str. Bitiş Tarihi Gün", minval = 1, maxval = 31)
ToMonth = input(defval = 1, title = "Str. Bitiş Tarihi Ay", minval = 1, maxval = 12)
ToYear = input(defval = 9999, title = "Str. Bitiş Tarihi Yıl", minval = 2006)
Start = timestamp(FromYear, FromMonth, FromDay, 00, 00)
Finish = timestamp(ToYear, ToMonth, ToDay, 23, 59)
Timerange() =>
time >= Start and time <= Finish ? true : false
if al
strategy.entry("Al", strategy.long, when=Timerange())
if sat
strategy.entry("Sat", strategy.short, when=Timerange())
Published by ChaoZhang on the FMZ strategy square · last modified 2023-10-07. 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-Bull-Bear-Crossover-Trading-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
- EMA SMA Trend Following with Swing Trading Strategy Combined Volume Filter and Percentage Take Profit Stop Loss SystemPine Script · Trend following · 1d
- Fixed Range Volume Profile And Anchored VWAP Trend Identification Strategy With Dynamic Stop LossPine Script · Trend following · 1h
- Multi Factor Trend Price Action Strategy with Dynamic Risk Management SystemPine Script · Trend following · 2h
- Multi Period Moving Average Ribbon and MACD Crossover Strategy SystemPine Script · Trend following · 1h
- Multi Period Phase Crossover with EMA Trend Following StrategyPine Script · Trend following · 1d
- Trend Following Strategy Based on Moving Average 439858Pine Script · Trend following · 1d