该策略结合了MACD指标和有限的马丁格尔资金管理方法,旨在捕捉市场趋势变化时的交易机会。当MACD快线与慢线发生金叉时产生买入信号,死叉时产生卖出信号。同时,策略采用了有限的马丁格尔方法来控制回撤,最多加仓3次。策略对单笔交易设置了1%的固定止盈止损。
该策略通过MACD指标捕捉趋势,同时采用有限马丁格尔控制回撤,能在趋势行情中取得不错的效果。但策略也存在一定的风险,如信号失效、固定止损等。通过引入其他指标、优化参数设置、仓位管理等方法,可以进一步提升该策略的稳健性和收益性。
/*backtest start: 2024-04-01 00:00:00 end: 2024-04-30 23:59:59 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("Advanced MACD Strategy with Limited Martingale", overlay=true, initial_capital=100) // MACD 설정 fastLength = 15 slowLength = 30 signalSmoothing = 9 [macdLine, signalLine, _] = ta.macd(close, fastLength, slowLength, signalSmoothing) // 계약수 및 이전 거래 결과 기록 var float contractSize = 0.01 var int martingaleCount = 0 // 마틴게일 카운트 var float lastTradeResult = 0 // 매수 및 매도 조건 longCondition = ta.crossover(macdLine, signalLine) shortCondition = ta.crossunder(macdLine, signalLine) // 매수 신호 if (longCondition) strategy.entry("Long", strategy.long, qty=contractSize) lastTradeResult := strategy.netprofit // 매도 신호 if (shortCondition) strategy.entry("Short", strategy.short, qty=contractSize) lastTradeResult := strategy.netprofit // 익절 및 손절 조건 strategy.close("Long", when=(close / strategy.position_avg_price >= 1.01)) strategy.close("Short", when=(strategy.position_avg_price / close >= 1.01)) strategy.close("Long", when=(close / strategy.position_avg_price <= 0.99)) strategy.close("Short", when=(strategy.position_avg_price / close <= 0.99)) // 마틴게일 전략 적용 if (strategy.netprofit < lastTradeResult) if (martingaleCount < 3) contractSize := contractSize * 2 martingaleCount := martingaleCount + 1 else contractSize := 0.01 martingaleCount := 0 else contractSize := 0.01 martingaleCount := 0 // 매수, 매도 포인트 화살표로 표시 plotshape(series=longCondition, location=location.belowbar, color=color.green, style=shape.labelup, text="Buy") plotshape(series=shortCondition, location=location.abovebar, color=color.red, style=shape.labeldown, text="Sell")