
이 전략은 여러 기술 지표와 시장 정서를 결합한 통합 거래 시스템입니다. 전략의 핵심은 단기 및 장기 이동 평균 (SMA) 의 교차 신호를 채택하고 MACD 지표와 결합하여 트렌드 방향을 확인합니다. 또한 전략은 시장 정서 지표 RSI를 통합하고, 이중 상위 / 이중 하위 및 상위 어깨 형태를 포함한 차트 형태 인식 시스템을 포함합니다. 전략은 특정 거래 시점에 실행되도록 특별히 설계되었습니다. 거래 효율성과 성공을 높이기 위해.
이 전략은 다음과 같은 핵심 구성 요소에 기반합니다.
구매 조건이 충족되어야 합니다: 목표 거래 시간에, 단기 SMA에 장기 SMA를 착용하고, MACD 지표가 다중 헤드 신호를 보여줍니다. 판매 조건이 충족되어야 합니다: 가격이 주요 저항 지점에 도달하고 MACD 지표가 공백 신호를 표시합니다.
이것은 여러 가지 기술 지표와 시장 정서를 결합하여 비교적 완전한 거래 시스템을 구축하는 포괄적 인 거래 전략입니다. 전략의 장점은 다차원 신호 확인과 정교한 위험 관리 장치에 있습니다. 그러나 파라미터 민감성 및 형태 인식 정확성 등의 문제도 있습니다. 지속적인 최적화 및 개선, 특히 파라미터 자조 및 기계 학습 응용 분야에서 전략은 더 나은 성능을 얻을 수 있습니다.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-11 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("XAUUSD SMA with MACD & Market Sentiment + Chart Patterns", overlay=true)
// Input parameters for moving averages
shortSMA_length = input.int(10, title="Short SMA Length", minval=1)
longSMA_length = input.int(30, title="Long SMA Length", minval=1)
// MACD settings
[macdLine, signalLine, _] = ta.macd(close, 12, 26, 9)
// Lookback period for identifying major resistance (swing highs)
resistance_lookback = input.int(20, title="Resistance Lookback Period", tooltip="Lookback period for identifying major resistance")
// Calculate significant resistance (local swing highs over the lookback period)
major_resistance = ta.highest(close, resistance_lookback)
// Calculate SMAs
shortSMA = ta.sma(close, shortSMA_length)
longSMA = ta.sma(close, longSMA_length)
// RSI for market sentiment
rsiLength = input.int(14, title="RSI Length", minval=1)
rsiOverbought = input.int(70, title="RSI Overbought Level", minval=50, maxval=100)
rsiOversold = input.int(30, title="RSI Oversold Level", minval=0, maxval=50)
rsi = ta.rsi(close, rsiLength)
// Time filtering: only trade during New York session (12:00 PM - 9:00 PM UTC)
isNewYorkSession = true
// Define buy condition based on SMA, MACD, and New York session
buyCondition = isNewYorkSession and ta.crossover(shortSMA, longSMA) and macdLine > signalLine
// Define sell condition: only sell if price is at or above the identified major resistance during New York session
sellCondition = isNewYorkSession and close >= major_resistance and macdLine < signalLine
// Define sentiment-based exit conditions
closeEarlyCondition = strategy.position_size < 0 and rsi > rsiOverbought // Close losing trade early if RSI is overbought
holdWinningCondition = strategy.position_size > 0 and rsi < rsiOversold // Hold winning trade if RSI is oversold
// ------ Chart Patterns ------ //
// Double Top/Bottom Pattern Detection
doubleTop = ta.highest(close, 50) == close[25] and ta.highest(close, 50) == close[0] // Approximate double top: two peaks
doubleBottom = ta.lowest(close, 50) == close[25] and ta.lowest(close, 50) == close[0] // Approximate double bottom: two troughs
// Head and Shoulders Pattern Detection
shoulder1 = ta.highest(close, 20)[40]
head = ta.highest(close, 20)[20]
shoulder2 = ta.highest(close, 20)[0]
isHeadAndShoulders = shoulder1 < head and shoulder2 < head and shoulder1 == shoulder2
// Pattern-based signals
patternBuyCondition = isNewYorkSession and doubleBottom and rsi < rsiOversold // Buy at double bottom in oversold conditions
patternSellCondition = isNewYorkSession and (doubleTop or isHeadAndShoulders) and rsi > rsiOverbought // Sell at double top or head & shoulders in overbought conditions
// Execute strategy: Enter long position when buy conditions are met
if (buyCondition or patternBuyCondition)
strategy.entry("Buy", strategy.long)
// Close the position when the sell condition is met (price at resistance or pattern sell)
if (sellCondition or patternSellCondition and not holdWinningCondition)
strategy.close("Buy")
// Close losing trades early if sentiment is against us
if (closeEarlyCondition)
strategy.close("Buy")
// Visual cues for buy and sell signals
plotshape(series=buyCondition or patternBuyCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=sellCondition or patternSellCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
// ------ Alerts for Patterns ------ //
// Add alert for pattern-based buy condition
alertcondition(patternBuyCondition, title="Pattern Buy Signal Activated", message="Double Bottom or Pattern Buy signal activated: Conditions met.")
// Add alert for pattern-based sell condition
alertcondition(patternSellCondition, title="Pattern Sell Signal Activated", message="Double Top or Head & Shoulders detected. Sell signal triggered.")
// Existing alerts for SMA/MACD-based conditions
alertcondition(buyCondition, title="Buy Signal Activated", message="Buy signal activated: Short SMA has crossed above Long SMA and MACD is bullish.")
alertcondition(sellCondition, title="Sell at Major Resistance", message="Sell triggered at major resistance level.")
alertcondition(closeEarlyCondition, title="Close Losing Trade Early", message="Sentiment is against your position, close trade.")
alertcondition(holdWinningCondition, title="Hold Winning Trade", message="RSI indicates oversold conditions, holding winning trade.")