Strategy vault / Mean reversion
Dual Stochastic Oscillator Strategy
This strategy uses two stochastic oscillators with different parameters to determine bull/bear conditions. It is a typical moving average crossover system. The faster oscillator judges short-term trends and entry…
Overview
This strategy uses two stochastic oscillators with different parameters to determine bull/bear conditions. It is a typical moving average crossover system. The faster oscillator judges short-term trends and entry signals, while the slower one confirms overall trend direction. Signals are generated from the combination.
Strategy Logic
Fast %K shows short-term trend direction. %K crossing over the smoothing line SM1 generates entry signals.
Slow %K reflects overall trend conditions. When fast oscillator gives reversal signal, check slow oscillator for trend validity.
%K fast crossover above SM1 indicates bullish signal. Slow %K above 50 means uptrend, satisfying long condition.
%K fast crossover below SM1 indicates bearish signal. Slow %K below 50 means downtrend, satisfying short condition.
Set take profit and stop loss points at fixed percentages.
Advantage Analysis
Dual stochastic filters noise and improves accuracy. Fast and slow combination reduces being trapped risks.
Smaller SM1 parameter makes %K sensitive for catching short-term opportunities.
Larger cycle judges overall trend, smaller cycle captures reversals. Dual long/short strategies fit most market environments.
Fixed profit taking and stop loss points make risk controllable without huge swings.
Risk Analysis
Divergence between indicators can cause missed trades or wrong signals.
Fixed profit taking and stop loss points lack flexibility in adjusting to markets.
Stochastic parameters need repetitive optimization, improper settings lead to failure.
High trading frequency from short-term trading increases transaction costs.
Optimization Directions
Add other indicators or filters to ensure signal quality.
Test different parameter combinations to find optimal settings.
Incorporate volatility measures to make profit taking and stop loss levels dynamic.
Use time filters to avoid key events and irrational price swings.
Optimize capital management strategies like position sizing to improve capital efficiency.
Summary
This strategy integrates fast and slow stochastic oscillators into a dual directional system. Further parameter optimization and adding filters like trend and volatility indicators can improve it. With proper risk control, this strategy can achieve relatively steady excess returns.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 5 | Leading K |
| v_input_2 | 2 | Leading Smooth |
| v_input_3 | 97 | Lagging K |
| v_input_4 | 3 | Lagging D |
| v_input_5 | true | Lagging Smooth |
| v_input_6 | 1.2 | v_input_6 |
| v_input_7 | 1.2 | v_input_7 |
Source Pine Script
/*backtest
start: 2023-08-17 00:00:00
end: 2023-09-16 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("Double Stochastic", overlay=true)
//-----------------------Stochastics------------------------//
c= security(syminfo.tickerid,timeframe.period , close)
h= security(syminfo.tickerid, timeframe.period, high)
l= security(syminfo.tickerid, timeframe.period, low)
c1= security(syminfo.tickerid, timeframe.period, close)
h2= security(syminfo.tickerid, timeframe.period, high)
l1= security(syminfo.tickerid, timeframe.period, low)
K1 = input(5, title="K", minval=1, title="Leading K")
SM1 = input(2, title="Smooth", minval=1, title="Leading Smooth ")
k = ema(stoch(c, h, l, K1), SM1)
K2 = input(97, title="K", minval=1, title="Lagging K")
D2 = input(3, title="D", minval=1, title="Lagging D")
SM2 = input(1, title="Smooth", minval=1, title="Lagging Smooth")
k1 = ema(stoch(c1, h2, l1, K2), SM2)
// buy ((k[2] < 40 and k > 40) and bars_up > 0 and k1 > 50)
// sell (k[2] > 60 and k < 60) and bars_down > 0 and k1 < 50
//-----------------------Mechanics------------------------//
buy = k1 > 50 and k < 30 and k > k[1] ? 1 : 0
sell = k1 < 50 and k > 70 and k < k[1] ? 1 : 0
buy_val = valuewhen(buy == 1, close, 1)
sell_val = valuewhen(sell == 1, close, 1)
buy_close = buy_val * input(1.20, minval=0.1)
sell_close = sell_val / input(1.20, minval=0.1)
//------------------------Buy/Sell-------------------------//
longCondition = buy == 1
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)
close_long = close >= buy_close
if (close_long)
strategy.close("My Long Entry Id")
sellCondition = sell == 1
if (sellCondition)
strategy.entry("My Short Entry Id", strategy.short)
close_short = close <= sell_close
if (close_short)
strategy.close("My Short Entry Id") Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-17. 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-Stochastic-Oscillator-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