Strategy vault / Mean reversion
Moving Average Percentage Reversal Strategy
The moving average percentage reversal strategy generates trading signals by calculating the percentage differential between price and a moving average. Trades are taken when the percentage gap between price and the…
Strategy Logic
The moving average percentage reversal strategy generates trading signals by calculating the percentage differential between price and a moving average.
Trades are taken when the percentage gap between price and the MA reaches preset levels.
Specifically, the logic is:
- Calculate the absolute difference between price and an N-period MA
- Convert the difference to percentage terms, i.e. divide by price
- Go short when the percentage gap exceeds an upper threshold (e.g. 5%)
- Go long when the percentage gap falls below a lower threshold (e.g. -3%)
- Optionally reverse signals (longs become shorts, shorts become longs)
E.g. with N=14, upper limit=5%, lower limit=-3%:
- Go short when price is >5% above the 14-day MA
- Go long when price is <3% below the 14-day MA
Parameters N, upper/lower limits can adjust sensitivity.
Advantages
- Percentage gaps account for changing price levels
- Adjustable parameters suit different cycles
- BREAK strategy aims to catch trend turning points early
Risks
- Percentage gaps alone cannot confirm trend direction
- Prone to false signals, needs additional filters
- MAs lagging, may not catch reversals promptly
Summary
The MA percentage strategy uses the percentage gap between price and MA to identify potential turning points, with a BREAK approach. Adjustable parameters can adapt to varying market conditions, but lag and whipsaws are risks needing mitigation.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 14 | Length |
| v_input_2 | 0.54 | SellZone |
| v_input_3 | 0.03 | BuyZone |
| v_input_4 | false | Trade reverse |
Source Pine Script
/*backtest
start: 2023-08-14 00:00:00
end: 2023-09-13 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
////////////////////////////////////////////////////////////
// Copyright by HPotter v1.0 30/07/2018
// Percent difference between price and MA
//
// You can change long to short in the Input Settings
// WARNING:
// - For purpose educate only
// - This script to change bars colors.
////////////////////////////////////////////////////////////
strategy(title="Percent difference between price and MA Backtest")
Length = input(14, minval=1)
SellZone = input(0.54, minval=0.01, step = 0.01)
BuyZone = input(0.03, minval=0.01, step = 0.01)
reverse = input(false, title="Trade reverse")
hline(BuyZone, color=green, linestyle=line)
hline(SellZone, color=red, linestyle=line)
xSMA = sma(close, Length)
nRes = abs(close - xSMA) * 100 / close
pos = iff(nRes < BuyZone, 1,
iff(nRes > SellZone, -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(nRes, color=blue, title="PD MA")Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-14. 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-Percentage-Reversal-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
- 3 10 Oscillator Profile Flagging StrategyPine Script · Mean reversion · 1d
- A Trend Reversal Strategy Based on Moving Averages Price Patterns and VolumePine Script · Mean reversion · 1d
- Adaptive Mean Reversion Trading Strategy Based on Chande Momentum OscillatorPine Script · Mean reversion · 1d
- Adaptive Trading Strategy Combining Dynamic Trend Reversal and Stochastic IndicatorPine Script · Mean reversion · 1d
- 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