Strategy vault / Mean reversion
Demark Reversal Points
Pine Script strategy by ChaoZhang.
Pine ScriptMean reversion
The original spec has no written description. Read the source below.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1_close | 0 | Source: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4 |
| v_input_int_1 | 18000 | Resolution |
| v_input_2 | false | Allow Repainting? |
| v_input_3 | true | Allow Bar Color Change? |
| v_input_int_2 | 9 | Length |
| v_input_int_3 | 4 | LbLength |
Source Pine Script
/*backtest
start: 2022-02-06 00:00:00
end: 2022-05-06 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Bitfinex","currency":"BTC_USD"}]
*/
//@version=5
// Copyright (c) 2019-present, Franklin Moormann (cheatcountry)
// Demark Reversal Points [CC] script may be freely distributed under the MIT license.
//indicator('Demark Reversal Points [CC]', max_bars_back=3000, overlay=true)
inp = input(title='Source', defval=close)
res = input.int(title='Resolution', defval='18000')
rep = input(title='Allow Repainting?', defval=false)
bar = input(title='Allow Bar Color Change?', defval=true)
src = request.security(syminfo.tickerid, res, inp[0])[1]
length = input.int(title='Length', defval=9, minval=1)
lbLength = input.int(title='LbLength', defval=4, minval=1)
uCount = 0
dCount = 0
for i = 0 to length - 1 by 1
uCount += (nz(src[i]) > nz(src[i + lbLength]) ? 1 : 0)
dCount += (nz(src[i]) < nz(src[i + lbLength]) ? 1 : 0)
dCount
drp = dCount == length ? 1 : uCount == length ? -1 : 0
sig = drp > 0 or uCount > dCount ? 1 : drp < 0 or dCount > uCount ? -1 : 0
drpColor = sig > 0 ? color.green : sig < 0 ? color.red : color.black
alertcondition(ta.crossover(drp, 0), 'Buy Signal', 'Bullish Change Detected')
alertcondition(ta.crossunder(drp, 0), 'Sell Signal', 'Bearish Change Detected')
//barcolor(bar ? drpColor : na)
//plotshape(ta.crossover(drp, 0), 'Buy', shape.labelup, location.belowbar, color.new(color.green, 0), text='Buy', textcolor=color.new(color.white, 0))
//plotshape(ta.crossunder(drp, 0), 'Sell', shape.labeldown, location.abovebar, color=color.new(color.red, 0), text='Sell', textcolor=color.new(color.white, 0))
if ta.crossover(drp, 0)
strategy.entry("Enter Long", strategy.long)
else if ta.crossunder(drp, 0)
strategy.entry("Enter Short", strategy.short)Published by ChaoZhang on the FMZ strategy square · last modified 2022-05-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/Demark-Reversal-Points.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
- 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
- ATR and EMA based Dynamic Take Profit and Stop Loss Adaptive StrategyPine Script · Mean reversion · 1h
- Adaptive Mean Reversion Trading Strategy Based on Chande Momentum OscillatorPine Script · Mean reversion · 1d
- Adaptive Moving Average Tracking StrategyPine Script · Mean reversion · 1d