Strategy vault / Mean reversion
Price Extreme Reversion Strategy Based on Binomial Distribution
This strategy is named "Price Extreme Reversion Strategy Based on Binomial Distribution". It uses the binomial distribution function to estimate the probability of price reversals and sets a dual-EMA system to…
This strategy is named "Price Extreme Reversion Strategy Based on Binomial Distribution". It uses the binomial distribution function to estimate the probability of price reversals and sets a dual-EMA system to generate trade signals.
The logic is:
Calculate the number of up close bars in the recent 20 bars, and the percentage p of up periods in the past 100 bars.
Plug the up period counts and probability p into the binomial distribution function to compute the cumulative distribution function (CDF).
Apply 10-day and 20-day EMAs to the CDF. When the fast EMA crosses above the slow EMA, it signals a high probability of price extreme reversion, generating buy signals.
When the fast EMA crosses below the slow EMA, prices may be peaking in the short run, producing sell signals here.
The advantage of this strategy is estimating price extreme reversion timing through probability methods. But parameters need market-adjusted optimization to avoid excessive false signals.
In conclusion, statistical techniques help uncover price behavior patterns objectively. But ultimately, traders still need keen market judgment to use technical indicators as supplementary tools.
Source Pine Script
/*backtest
start: 2022-09-06 00:00:00
end: 2023-05-01 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/
// © pieroliviermarquis
//@version=4
strategy("Binomial Strategy", overlay=false, default_qty_type= strategy.percent_of_equity, default_qty_value= 100, slippage=1, initial_capital= 10000, calc_on_every_tick=true)
factorial(length) =>
n = 1
if length != 0
for i = 1 to length
n := n * i
n
binomial_pdf(success, trials, p) =>
q = 1-p
coef = factorial(trials) / (factorial(trials-success) * factorial(success))
pdf = coef * pow(p, success) * pow(q, trials-success)
binomial_cdf(success, trials, p) =>
q = 1-p
cdf = 0.0
for i = 0 to success
cdf := cdf + binomial_pdf(i, trials, p)
up = close[0] > close[1] ? 1 : 0
//long-term probabilities
lt_lookback = 100
lt_up_bars = sum(up, lt_lookback)
prob = lt_up_bars/lt_lookback
//lookback for cdf
lookback = 20
up_bars = sum(up, lookback)
cdf = binomial_cdf(up_bars, lookback, prob)
//ema on cdf
ema1 = ema(cdf, 10)
ema2 = ema(cdf, 20)
plot(cdf*100)
plot(ema1*100, color=color.red)
plot(ema2*100, color=color.orange)
buy = ema1 > ema2
sell = ema1 < ema2
//////////////////////Bar Colors//////////////////
var color buy_or_sell = na
if buy == true
buy_or_sell := #3BB3E4
else if sell == true
buy_or_sell := #FF006E
barcolor(buy_or_sell)
///////////////////////////Orders////////////////
if buy
strategy.entry("Long", strategy.long, comment="")
if sell
strategy.close("Long", comment="Sell")
Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-13. 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/Price-Extreme-Reversion-Strategy-Based-on-Binomial-Distribution.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
- 1 2 3 Pattern Quantitative Trading Strategy with EMAs MACD and 4th Candle ExtensionPine Script · Mean reversion · 1h
- ATR and EMA based Dynamic Take Profit and Stop Loss Adaptive StrategyPine Script · Mean reversion · 1h
- 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