0bps

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…

Author
ChaoZhang
Complexity
Intermediate · 89 lines
Parameters
13
Backtest bar
1h · intraday
Tested on
BTC/USDT · futures

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:

  1. Calculate long-term MA and short-term EMA to determine trend direction.

  2. Calculate Stoch K and D values to identify overbought/oversold levels.

  3. When CLOSE breaks above MA, and Stoch K&D are above overbought line, go long.

  4. When CLOSE breaks below EMA, and Stoch K&D are below oversold line, go short.

  5. Use COLOR to mark determined trade direction.

Advantages:

  1. Dual MAs improve trend accuracy and avoid false signals.

  2. Stoch identifies high-probability buy/sell zones.

  3. Combining indicators improves reliability through verification.

Risks:

  1. Poor parameter tuning causes excessive signals or inconsistencies.

  2. Both MAs and Stoch can lag, causing premature or delayed entries.

  3. 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

NameDefaultWhat it controls
v_input_150MA (green)
v_input_225EMA (red)
v_input_320STOCH - K
v_input_42STOCH - D
v_input_52STOCH - Smooth
v_input_650Long when Close > MA and Stoch >
v_input_780Short when Close < EMA and Stoch <
v_input_82019Strategy Test Start Year
v_input_9trueStrategy Test Start Month
v_input_10trueStrategy Test Start Day
v_input_112019Strategy Test Stop Year
v_input_1212Strategy Test Stop Month
v_input_1331Strategy 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.

in Claude Code, Cursor, Codex & 4 more
/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
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. 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

esc

Try , , or .

↑↓ move↵ open