Strategy vault / Mean reversion
Oscillation Trading Strategy Between Moving Averages
This strategy combines the moving average indicator and Bollinger Bands to implement a strategy that oscillates between moving averages for two-way trading. Go long when the price breaks above the lower rail, go…

Overview
This strategy combines the moving average indicator and Bollinger Bands to implement a strategy that oscillates between moving averages for two-way trading. Go long when the price breaks above the lower rail, go short when the price breaks below the upper rail, and profit from the oscillation between the moving averages.
Strategy Principle
- Calculate the fast moving average ma_short and slow moving average ma_long
- When ma_short crosses above ma_long, go long; when ma_short crosses below ma_long, go short
- Calculate the upper rail, lower rail and middle rail of Bollinger Bands
- When price breaks above lower rail, confirm long signal; when price breaks below upper rail, confirm short signal
- Open positions when the moving average indicator and Bollinger Bands give signals in the same direction, close positions when they give signals in opposite directions
Advantage Analysis
- The combination of dual indicators makes it relatively stable and can filter out some false signals
- Oscillating between moving averages and Bollinger Bands avoids chasing highs and selling lows
- Allowing two-way trading can take full advantage of price fluctuations for profit
Risk Analysis
- The parameter settings of Bollinger Bands will affect the trading frequency and profitability
- It is easy to generate large losses in strong trending markets
- The moving average system itself tends to generate more losing trades on exits
Risk Management:
- Optimize Bollinger Bands parameters to adjust to suitable trading frequency
- Set stop loss strategy to control single trade loss
- Use this strategy when the trend is not obvious
Optimization Directions
- Test different parameter combinations of moving average systems
- Evaluate whether to add volume indicators to filter signals
- Test whether to combine RSI and other indicators to determine overbought and oversold zones
The above optimizations can further improve profitability, reduce unnecessary trades, lower trading frequency and loss risks.
Summary
This strategy combines moving average systems and Bollinger Bands to implement oscillation trading between price moving averages. The combination of dual indicators can improve signal quality, and allowing two-way trading provides more opportunities. Further optimizing parameters and adding other auxiliary indicators can reduce unnecessary trades and improve profitability, which is worth live testing and optimization. ]
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 24 | Bollinger Period Length |
Source Pine Script
/*backtest
start: 2023-12-09 00:00:00
end: 2023-12-10 00:00:00
period: 2m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
strategy("MA-Zorrillo",overlay=true)
ma_short= sma(close,8)
ma_long= sma(close,89)
entry_ma = crossover (ma_short,ma_long)
exit_ma = crossunder (ma_short,ma_long)
BBlength = input(24, minval=1,title="Bollinger Period Length")
BBmult = 2 // input(2.0, minval=0.001, maxval=50,title="Bollinger Bands Standard Deviation")
BBbasis = sma(close, BBlength)
BBdev = BBmult * stdev(close, BBlength)
BBupper = BBbasis + BBdev
BBlower = BBbasis - BBdev
source = close
entry_bb = crossover(source, BBlower)
exit_bb = crossunder(source, BBupper)
vs_entry = false
vs_exit = false
for i = 0 to 63
if (entry_bb[i])
vs_entry := true
if (exit_bb[i])
vs_exit := true
entry = entry_ma and vs_entry
exit = exit_ma and vs_exit
strategy.entry(id="long_ma",long=true,when=entry)
strategy.close(id="long_ma", when=exit)
strategy.entry(id="short_ma",long=false,when=exit)
strategy.close(id="short_ma",when=entry)
Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-11. 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/Oscillation-Trading-Strategy-Between-Moving-Averages.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 15 Minute Chart Trading Signal StrategyPine Script · Mean reversion · 3h
- Advanced Quantitative Trading Strategy Combining RSI Divergence and Moving AveragesPine Script · Mean reversion · 1h
- Bollinger Bands Stochastic RSI Extreme Strategy BBSR Extreme StrategyPine Script · Mean reversion · 1h
- Dual Moving Average RSI Synergy Options Quantitative Trading StrategyPine Script · Mean reversion · 1h
- Gods Bollinger Bands RSI Trading StrategyPine Script · Mean reversion · 1d
- Multi Indicator Reversal Point Capture Trading StrategyPine Script · Mean reversion · 1d