Strategy vault / Mean reversion
Moving Average AO Indicator Trading Strategy
This strategy combines moving averages and the AO oscillator to identify trends and trade pullbacks. It aims to capture short-term reversals in price oscillation. Strategy Logic: 1. Calculate fast EMA and slow SMA to…
This strategy combines moving averages and the AO oscillator to identify trends and trade pullbacks. It aims to capture short-term reversals in price oscillation.
Strategy Logic:
Calculate fast EMA and slow SMA to construct a moving average system.
Calculate fast and slow AO lines and the difference between them.
Go long when fast MA crosses above slow MA, close is above slow MA, and AO rises.
Go short when fast MA crosses below slow MA, close is below slow MA, and AO falls.
AO compares differences to avoid false signals.
Advantages:
MAs determine main trend, AO times reversals.
AO difference filters false signals.
Combining indicators improves accuracy.
Risks:
Tuning required to match MA and AO with market conditions.
Both MAs and AO lag, potentially missing best entries.
Hard to set stops in ranging markets, increasing loss risks.
In summary, this strategy combines the strengths of MAs and AO for trading. This can improve signal quality to some extent but proper stops are still required to manage risks for steady returns.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 2017 | Start Year |
| v_input_2 | 12 | Month |
| v_input_3 | 17 | Day |
| v_input_4 | 9999 | End Year |
| v_input_5 | true | Month |
| v_input_6 | true | Day |
| v_input_7 | 8 | Fast EMA |
| v_input_8 | 20 | Slow SMA |
| v_input_9 | 5 | Awesome Length Fast |
| v_input_10 | 8 | Awesome Length Slow |
Source Pine Script
/*backtest
start: 2023-09-04 00:00:00
end: 2023-09-11 00:00:00
period: 30m
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("MA&AO", overlay = true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.075, currency='USD')
startP = timestamp(input(2017, "Start Year"), input(12, "Month"), input(17, "Day"), 0, 0)
end = timestamp(input(9999, "End Year"), input(1, "Month"), input(1, "Day"), 0, 0)
_testPeriod() =>
true
//Inputs
fast_ma = input(8, title="Fast EMA", minval=2)
slow_ma = input(20, minval=1, title="Slow SMA")
AO_fast = input(5, minval=1, title="Awesome Length Fast")
AO_slow = input(8, minval=1, title="Awesome Length Slow")
//MA
fast = ema(close, fast_ma)
slow = sma(close, slow_ma)
//AO
AO_1 = sma(hl2, AO_fast)
AO_2 = sma(hl2, AO_slow)
dif = AO_1 - AO_2
AO = dif>=0? dif > dif[1] ? 1 : 2 : dif > dif[1] ? -1 : -2
long = crossover(fast, slow) and close > slow and abs(AO)==1
short = fast < slow and close < slow and abs(AO)==2
long_condition = long and _testPeriod()
strategy.entry('BUY', strategy.long, when=long_condition)
short_condition = short
strategy.close('BUY', when=short_condition)
plot(fast, color=color.green)
plot(slow, color=color.red)Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-12. 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/Moving-Average-AO-Indicator-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
- Advanced 15 Minute Chart Trading Signal StrategyPine Script · Mean reversion · 3h
- Advanced Momentum EMA Trend Following with RSI Overbought Oversold Trading StrategyPine Script · Mean reversion · 1d
- Advanced Quantitative Trading Strategy Combining RSI Divergence and Moving AveragesPine Script · Mean reversion · 1h
- Advanced Quantitative Trend Following and Cloud Reversal Composite Trading StrategyPine Script · Mean reversion · 1d
- BONK Multi Factor Trading StrategyPine Script · Mean reversion · 1d
- Bidirectional Moving Average Reversion Trading StrategyPine Script · Mean reversion · 1h