Strategy vault / Mean reversion
Dual MA Stoch Indicators Combo Trading Strategy
This strategy combines moving averages and Stoch indicators into a quantitative trading system with both trend-following and overbought/oversold detection capabilities. It integrates the strengths of multiple…
This strategy combines moving averages and Stoch indicators into a quantitative trading system with both trend-following and overbought/oversold detection capabilities. It integrates the strengths of multiple indicators for systematic trend identification and opportunity capture.
Strategy Logic:
Calculate long-term MA and short-term EMA to determine trend direction.
Calculate Stoch K and D values to identify overbought/oversold levels.
When CLOSE breaks above MA, and Stoch K&D are above overbought line, go long.
When CLOSE breaks below EMA, and Stoch K&D are below oversold line, go short.
Use COLOR to mark determined trade direction.
Advantages:
Dual MAs improve trend accuracy and avoid false signals.
Stoch identifies high-probability buy/sell zones.
Combining indicators improves reliability through verification.
Risks:
Poor parameter tuning causes excessive signals or inconsistencies.
Both MAs and Stoch can lag, causing premature or delayed entries.
More indicators mean more complexity despite improved reliability.
In summary, this strategy quantitatively trades using MAs for trend and Stoch for overbought/oversold levels. With robust parameter optimization, it can improve system stability and reliability. But prudent risk management is still required, and investors should apply discretion.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 50 | MA (green) |
| v_input_2 | 25 | EMA (red) |
| v_input_3 | 20 | STOCH - K |
| v_input_4 | 2 | STOCH - D |
| v_input_5 | 2 | STOCH - Smooth |
| v_input_6 | 50 | Long when Close > MA and Stoch > |
| v_input_7 | 80 | Short when Close < EMA and Stoch < |
| v_input_8 | 2019 | Strategy Test Start Year |
| v_input_9 | true | Strategy Test Start Month |
| v_input_10 | true | Strategy Test Start Day |
| v_input_11 | 2019 | Strategy Test Stop Year |
| v_input_12 | 12 | Strategy Test Stop Month |
| v_input_13 | 31 | Strategy Test Stop Day |
Source Pine Script
/*backtest
start: 2023-08-12 00:00:00
end: 2023-09-11 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
// strategy("PMB2", overlay=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 20, initial_capital=1000, currency=currency.USD)
//study(title="PMB2", overlay=true)
l_ma = input(50, title="MA (green)", type=input.integer)
l_ema = input(25, title="EMA (red)", type=input.integer)
MA = sma(close,l_ma)
EMA = ema(close,l_ema)
plot(MA, color=color.green)
plot(EMA, color=color.red)
//STOCH(14,3,3)
length = input(20, minval=1, title="STOCH - K")
smoothK = input(2, minval=1, title="STOCH - D")
smoothD = input(2 , minval=1, title="STOCH - Smooth")
StkLong= input(50 , minval=1, maxval=100, title="Long when Close > MA and Stoch > ")
StkShort= input(80 , minval=1, maxval=100, title="Short when Close < EMA and Stoch < ")
k = sma(stoch(close, high, low, length), smoothK)
d = sma(k, smoothD)
//plot(k, color=color.blue, title="STOCH - K")
//plot(d, color=color.orange, title="STOCH - D")
//band180 = hline(80, title="STOCH - Banda superior")
//band120 = hline(20, title="STOCH - Banda superior")
//band100 = hline(50, color=color.gray, editable=false, linestyle=hline.style_solid)
//fill(band180, band120, color=color.gray, transp=75, title="STOCH - Fundo")
BTStartY = input(title="Strategy Test Start Year", type=input.integer, defval=2019, minval=2010, maxval=2100)
BTStartM = input(title="Strategy Test Start Month", type=input.integer, defval=1, minval=1, maxval=12)
BTStartD = input(title="Strategy Test Start Day", type=input.integer, defval=1, minval=1, maxval=31)
BTStopY = input(title="Strategy Test Stop Year", type=input.integer, defval=2019, minval=2010, maxval=2100)
BTStopM = input(title="Strategy Test Stop Month", type=input.integer, defval=12, minval=1, maxval=12)
BTStopD = input(title="Strategy Test Stop Day", type=input.integer, defval=31, minval=1, maxval=31)
// set up min and max date for strategy test
TMin = timestamp(BTStartY, BTStartM, BTStartD, 00, 00)
TMax = timestamp(BTStopY, BTStopM, BTStopD, 00, 00)
InTime = true
bool long = false, short = false, trade = false
trade := trade[1]
long := long[1]
short := short[1]
if (crossover(close, MA) and k > StkLong and d > StkLong) // "LONG!"
//if (close > MA and k > StkLong and d > StkLong) // "LONG!"
short := false
long := true
trade := true // LONG
if (crossunder(close, EMA) and k < StkShort and d < StkShort) // "SHORT!""
//if (close < EMA and k < StkShort and d < StkShort) // "SHORT!""
long := false
short := true
trade := false // SHORT
//bgcolor(FL > SH ? color.green : FH < SL ? color.red : na, transp=80)
bgcolor(trade ? color.green : color.red, transp=90)
//alertcondition((crossover(close, MA) and k > 50 and d > 50) , title='Buy', message='Buy')
//alertcondition((crossunder(close, EMA) and k > 80 and d > 80) , title='Sell', message='Sell')
if ((crossover(close, MA) and k > StkLong and d > StkLong) and InTime)
//if ((close > MA and k > StkLong and d > StkLong) and InTime)
strategy.entry("Long", strategy.long)
if ((crossunder(close, EMA) and k < StkShort and d < StkShort) and InTime)
//if ((close < EMA and k < StkShort and d < StkShort) and InTime)
strategy.entry("Short", strategy.short)
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/Dual-MA-Stoch-Indicators-Combo-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
- Dynamic Adaptive Multi Timeframe Trend Following and Range Reversal Hybrid StrategyPine Script · Mean reversion · 2d
- Multi Strategy Technical Analysis Trading SystemPine Script · Mean reversion · 1d
- Oma and Apollo Dual Rail Trading StrategyPine Script · Mean reversion · 5m
- Stochastic Moving Average StrategyPine Script · Mean reversion · 1h
- 3EMA with Stochastic RSI StrategyPine Script · Mean reversion · 1h