
이 전략은 망치선과 매달린 남자라는 두 가지 고전적 촛대 패턴을 기반으로 한 양적 거래 시스템입니다. 이 전략은 시장에서 이러한 반전 패턴을 식별하여 가격 움직임의 잠재적인 전환점을 예측하는 방식으로 작동합니다. 이 시스템은 K-라인 본체와 그림자 사이의 비례 관계, 추세 방향 및 기타 요소를 포함한 여러 기술 지표를 결합하여 신호의 유효성을 확인하고 시장 반전 지점을 정확하게 포착합니다.
이 전략의 핵심 논리는 프로그래밍 방식으로 두 가지 주요 캔들스틱 패턴을 식별하는 것입니다.
이 전략은 다음을 포함한 엄격한 매개변수를 설정하여 이러한 패턴을 정량화합니다.
이 전략은 고전적인 기술 분석 이론을 정량적인 방법을 통해 체계적으로 응용하는 것을 실현하며, 강력한 실용적 가치를 가지고 있습니다. 매개변수를 최적화하고 위험 관리 메커니즘을 개선함으로써 이 전략은 다양한 시장 환경에서 안정적인 성과를 유지할 수 있습니다. 전략의 모듈형 설계는 이후의 최적화를 위한 좋은 기반을 제공합니다.
/*backtest
start: 2024-12-10 00:00:00
end: 2025-01-08 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":49999}]
*/
//@version=6
strategy("Hammer and Hanging Man Strategy", overlay=true)
// Input parameters
length = input.int(5, title="Minimum Candle Body Length (Multiplier)", minval=1)
shadowRatio = input.float(1, title="Lower Shadow to Candle Height Ratio", minval=1.0)
holdPeriods = input.int(26, title="Hold Periods (Bars)", minval=1) // Holding period in bars
// Function to calculate the absolute value
absValue(x) =>
x >= 0 ? x : -x
// Function to check if it is a Hammer
isHammer() =>
bodyLength = absValue(close - open)
candleHeight = high - low
lowerShadow = math.min(open, close) - low
upperShadow = high - math.max(open, close)
smallBody = bodyLength <= candleHeight / length
longLowerShadow = lowerShadow >= bodyLength * shadowRatio
shortUpperShadow = upperShadow <= bodyLength
smallBody and longLowerShadow and shortUpperShadow and close > open
// Function to check if it is a Hanging Man
isHangingMan() =>
bodyLength = absValue(close - open)
candleHeight = high - low
lowerShadow = math.min(open, close) - low
upperShadow = high - math.max(open, close)
smallBody = bodyLength <= candleHeight / length
longLowerShadow = lowerShadow >= bodyLength * shadowRatio
shortUpperShadow = upperShadow <= bodyLength
smallBody and longLowerShadow and shortUpperShadow and close < open
// Detect the candles
hammer = isHammer()
hangingMan = isHangingMan()
// Trading logic: Long on Hammer, Short on Hanging Man
if hammer
strategy.entry("Long", strategy.long) // Long entry on Hammer
if hangingMan
strategy.entry("Short", strategy.short) // Short entry on Hanging Man
// Exit after X bars
if strategy.position_size > 0 and bar_index - strategy.opentrades.entry_bar_index(0) >= holdPeriods
strategy.close("Long")
if strategy.position_size < 0 and bar_index - strategy.opentrades.entry_bar_index(0) >= holdPeriods
strategy.close("Short")
// Visualization of signals
plotshape(hammer, title="Hammer", location=location.belowbar, color=color.green, style=shape.labelup, text="Hammer")
plotshape(hangingMan, title="Hanging Man", location=location.abovebar, color=color.red, style=shape.labeldown, text="Hanging Man")