Strategy vault / Pairs & stat-arb
Multi MA Pair Trading Strategy
This strategy combines dual moving average selection and price pattern recognition to form a more comprehensive entry mechanism for improving signal quality. It also incorporates profit taking control and maximum…
Overview
This strategy combines dual moving average selection and price pattern recognition to form a more comprehensive entry mechanism for improving signal quality. It also incorporates profit taking control and maximum holding period to achieve robust risk management.
Strategy Logic
The strategy includes the following indicators and rules:
3 SMAs judge overall trend.
2 EMAs make detailed directional judgment.
SAR assists with trend and momentum.
Price patterns identify formations as entry signals.
Max profit take limit controls profit booking.
Holding period limit avoids loss expansion.
The combination of multiple indicators forms robust entry signals and exit mechanisms, balancing profitability and risk control for steady trading.
Advantages
Compared to single indicator strategies, the advantages are:
Multiple indicators improve accuracy.
Price pattern recognition improves entry timing.
Profit take control realizes profit.
Holding period avoids loss expansion.
SMAs follow the trend.
EMAs improve sensitivity.
SAR verifies breakout reliability.
Overall good risk-reward balance, robustness.
Tuning parameters can achieve steady alpha.
Risks
Despite the merits, the following risks should be noted:
Multiple indicators increase complexity.
Broad parameter tuning risks over-optimization.
Price pattern recognition effectiveness uncertain.
Profit taking risks missing trend continuation.
Holding period limits profit potential.
Stability and profitability have tradeoff.
Multi-market robustness requires validation.
Ongoing monitoring of model robustness critical.
Enhancement
Based on the analysis, enhancements may include:
Adjust parameters for return stability.
Incorporate machine learning for entry timing.
Optimize dynamic stop loss and take profit.
Assess impact of holding period on equity curve.
Test robustness across different markets.
Add parameter robustness checks to prevent overfitting.
Develop quantitative risk management.
Continually validate strategy efficacy.
Conclusion
In summary, the multi-indicator approach forms a relatively robust trading system. But continual optimization and validation are key for any strategy, with focus on parameter robustness for market adaptability. Quant trading is an iterative process.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | true | Quantity |
| v_input_2 | 3 | SMA Period 01 |
| v_input_3 | 8 | SMA Period 02 |
| v_input_4 | 10 | SMA Period 03 |
| v_input_5 | 5 | EMA Period 01 |
| v_input_6 | 3 | EMA Period 02 |
| v_input_7 | 5 | Max Profit Close |
| v_input_8 | 10 | Max Total Bars |
Source Pine Script
//@version=3
strategy("Free Strategy #08 (Combo of #01 and #02) (ES / SPY)", overlay=true)
// Inputs
Quantity = input(1, minval=1, title="Quantity")
SmaPeriod01 = input(3, minval=1, title="SMA Period 01")
SmaPeriod02 = input(8, minval=1, title="SMA Period 02")
SmaPeriod03 = input(10, minval=1, title="SMA Period 03")
EmaPeriod01 = input(5, minval=1, title="EMA Period 01")
EmaPeriod02 = input(3, minval=1, title="EMA Period 02")
MaxProfitCloses = input(5, minval=1, title="Max Profit Close")
MaxBars = input(10, minval=1, title="Max Total Bars")
// Misc Variables
src = close
BarsSinceEntry = 0
MaxProfitCount = 0
Sma01 = sma(close, SmaPeriod01)
Sma02 = sma(close, SmaPeriod02)
Sma03 = sma(close, SmaPeriod03)
Ema01 = ema(close, EmaPeriod01)
Ema02 = ema(close, EmaPeriod02)
OHLC = (open + high + low + close) / 4.0
// Conditions
Cond00 = strategy.position_size == 0
Cond01 = close < Sma03
Cond02 = close <= Sma01
Cond03 = close[1] > Sma01[1]
Cond04 = open > Ema01
Cond05 = Sma02 < Sma02[1]
Entry01 = Cond00 and Cond01 and Cond02 and Cond03 and Cond04 and Cond05
Cond06 = close < Ema02
Cond07 = open > OHLC
Cond08 = volume <= volume[1]
Cond09 = (close < min(open[1], close[1]) or close > max(open[1], close[1]))
Entry02 = Cond00 and Cond06 and Cond07 and Cond08 and Cond09
// Update Exit Variables
BarsSinceEntry := Cond00 ? 0 : nz(BarsSinceEntry[1]) + 1
MaxProfitCount := Cond00 ? 0 : (close > strategy.position_avg_price and BarsSinceEntry > 1) ? nz(MaxProfitCount[1]) + 1 : nz(MaxProfitCount[1])
// Entries
strategy.entry(id="L1", long=true, qty=Quantity, when=(Entry01 or Entry02))
// Exits
strategy.close("L1", (BarsSinceEntry - 1 >= MaxBars or MaxProfitCount >= MaxProfitCloses))Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-23. 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/Multi-MA-Pair-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
- MCL YG Bollinger Band Breakout Pair Trading StrategyPine Script · Pairs & stat-arb · 1d
- Pair trading strategyPine Script · Pairs & stat-arb · 1d
- Dual ATR Channel Trend Following StrategyPine Script · Trend following · 15m
- Momentum Strategy Based on Double Bottom Breakout ModelPine Script · Breakout · 1m
- Quantitative Strategy PSARZigZagMACDART Based on Multi Indicator CombinationPine Script · Breakout · 1m
- Quantitative Trading Strategy Based on Ichimoku with Multiple SignalsPine Script · Breakout · 1h