다중 기간 결합 K-라인 패턴 인식 거래 전략

JSC CP TS
생성 날짜: 2024-12-11 11:04:35 마지막으로 수정됨: 2024-12-11 11:04:35
복사: 0 클릭수: 480
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

다중 기간 결합 K-라인 패턴 인식 거래 전략

개요

이 전략은 K선 형태를 인식하는 기반의 자동화 거래 시스템이다. 이 전략은 10가지의 클래식 K선 형태를 통합하고 있으며, 5가지의 시점 형태 ((子線,多頭吞,刺透線,晨星,三白兵) 와 5가지의 시점 형태 ((上線吊吊,空頭吞,雲蓋頂,暮星,三黑) 를 포함한다. 이 전략은 이러한 형태를 실시간으로 인식하고 분석함으로써 거래자에게 잠재적인 시장 역전 신호와 거래 기회를 제공한다.

전략 원칙

전략의 핵심은 다양한 K선 형태를 프로그래밍하여 정확하게 식별하는 것이다. 각각의 형태는 고유한 수학적 정의와 조건 판단을 가지고 있다:

  1. 단일 K선 형태 (선, 상반선 등) 에 대해서는 주로 실체와 그림자 선의 비례 관계를 기준으로 판단한다.
  2. 두 개의 K선 형태 (예: 침수선, 침투선) 를, 인접한 두 개의 K선의 개시시장 가격 위치 관계를 비교하여 판단한다.
  3. 3개의 K선 형태 (예: 3개의 하얀 군인, 3개의 검은 수) 에 대해, 연속적인 3개의 K선의 이동 방향과 위치 관계를 동시에 만족시켜야 한다. 정책은 사용자가 매개 변수를 통해 특정 형태의 식별을 활성화 또는 비활성화 할 수있는 유연한 선택을 허용합니다.

전략적 이점

  1. 포괄성: 가장 대표적인 10개의 K선 형태를 포괄하여 다양한 유형의 시장 역전 신호를 포착할 수 있습니다.
  2. 유연성: 사용자는 시장 환경과 개인 거래 스타일에 따라 식별해야 할 형태의 조합을 자유롭게 선택할 수 있습니다.
  3. 시각화: 명확한 표기 시스템을 통해 다양한 형태의 발생 위치와 유형을 직관적으로 표시
  4. 자동화: 인간의 주관적이고 감정적인 판단을 피하는 완전히 프로그래밍 된 판단 과정
  5. 실용성: 전략 논리가 명확하여 다른 기술 지표 또는 거래 시스템과 결합하여 사용할 수 있습니다.

전략적 위험

  1. 지연성 위험: K 라인 형태 확인은 K 라인 종결을 기다려야 하며, 입시 시기가 약간 늦어질 수 있다.
  2. 가짜 신호 위험: 흔들리는 시장에서 K선 형태에만 의존하면 더 많은 가짜 신호가 발생할 수 있습니다.
  3. 시장 환경 의존성: 전략이 트렌드가 뚜렷한 시장에서 잘 작동하지만 수평 시장에서는 효과가 떨어질 수 있습니다.
  4. 매개 변수 설정 위험: 너무 많은 형태 인식이 활성화되면 신호가 너무 밀집되어 판단에 영향을 미칠 수 있습니다.
  5. 손해 통제 위험: 전략 자체에는 완벽한 손해 통제 장치가 포함되어 있지 않으며, 추가적인 위험 통제 조치가 필요합니다.

전략 최적화 방향

  1. 트렌드 필터 도입: 이동 평균 또는 트렌드 지표와 결합하여 역동 신호를 필터링
  2. 트랜지먼트 확인이 증가: 트랜지먼트 변화를 통해 형식의 유효성을 검증
  3. 리스크 관리를 개선: 다이내믹 스톱로스 및 수익 목표 설정 기능 추가
  4. 형태 파라미터를 최적화: 다른 시장과 시간대에 따라 형태를 식별하는 파라미터 기준을 조정합니다.
  5. 형태 무게를 추가: 다른 형태의 신뢰성에 따라 다른 신호 무게 시스템을 설정

요약하다

이것은 합리적이고 논리적으로 명확하게 설계된 K선 형태 인식 거래 전략이다. 이것은 전통적인 기술 분석에서 가장 일반적으로 사용되는 K선 형태 판단을 프로그램 방식으로 구현하여 거래자에게 객관적이고 체계화된 거래 도구를 제공합니다. 일부 고유한 한계가 있지만, 적절한 최적화와 다른 기술 도구와 함께 사용하면 거래 의사 결정에 귀중한 참조 신호를 제공할 수 있습니다. 전략의 모듈화 설계는 또한 후속 기능 확장 및 성능 최적화에 좋은 토대를 제공합니다.

전략 소스 코드
/*backtest
start: 2024-11-10 00:00:00
end: 2024-12-09 08:00:00
period: 2h
basePeriod: 2h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
// Author: Raymond Ngobeni
strategy('Candlestick Pattern Strategy [Ubaton]', 'Ubaton - Candlestick Pattern Strategy', overlay = true, max_labels_count = 500, max_lines_count = 500, max_boxes_count = 500)

// User Inputs: Enable/Disable Patterns
// Bullish Patterns
enableHammer = input.bool(true, "Show Hammer")
enableBullEngulfing = input.bool(true, "Show Bullish Engulfing")
enablePiercingLine = input.bool(true, "Show Piercing Line")
enableMorningStar = input.bool(true, "Show Morning Star")
enableThreeWhiteSoldiers = input.bool(true, "Show Three White Soldiers")

// Bearish Patterns
enableHangingMan = input.bool(true, "Show Hanging Man")
enableBearEngulfing = input.bool(true, "Show Bearish Engulfing")
enableDarkCloudCover = input.bool(true, "Show Dark Cloud Cover")
enableEveningStar = input.bool(true, "Show Evening Star")
enableThreeBlackCrows = input.bool(true, "Show Three Black Crows")

// Helper Functions
isHammer() =>
    bodySize = math.abs(open - close)
    shadowSize = low < math.min(open, close) ? math.min(open, close) - low : na
    shadowSize >= 2 * bodySize and high - math.max(open, close) <= bodySize

isBullishEngulfing() =>
    close[1] < open[1] and close > open and open <= close[1] and close >= open[1]

isPiercingLine() =>
    close[1] < open[1] and close > close[1] + (open[1] - close[1]) * 0.5 and close < open[1]

isMorningStar() =>
    close[2] < open[2] and math.abs(close[1] - open[1]) < (high[1] - low[1]) * 0.3 and close > open

isThreeWhiteSoldiers() =>
    close > open and close[1] > open[1] and close[2] > open[2] and open > close[1] and open[1] > close[2]

isHangingMan() =>
    bodySize = math.abs(open - close)
    shadowSize = low < math.min(open, close) ? math.min(open, close) - low : na
    shadowSize >= 2 * bodySize and high - math.max(open, close) <= bodySize and close < open

isBearishEngulfing() =>
    close[1] > open[1] and close < open and open >= close[1] and close <= open[1]

isDarkCloudCover() =>
    close[1] > open[1] and open > close[1] and close < open[1] and close < close[1] + (open[1] - close[1]) * 0.5

isEveningStar() =>
    close[2] > open[2] and math.abs(close[1] - open[1]) < (high[1] - low[1]) * 0.3 and close < open

isThreeBlackCrows() =>
    close < open and close[1] < open[1] and close[2] < open[2] and open < close[1] and open[1] < close[2]

// Detect Patterns
// Bullish
hammerDetected = enableHammer and isHammer()
bullEngulfDetected = enableBullEngulfing and isBullishEngulfing()
piercingDetected = enablePiercingLine and isPiercingLine()
morningStarDetected = enableMorningStar and isMorningStar()
threeWhiteDetected = enableThreeWhiteSoldiers and isThreeWhiteSoldiers()

// Bearish
hangingManDetected = enableHangingMan and isHangingMan()
bearEngulfDetected = enableBearEngulfing and isBearishEngulfing()
darkCloudDetected = enableDarkCloudCover and isDarkCloudCover()
eveningStarDetected = enableEveningStar and isEveningStar()
threeBlackDetected = enableThreeBlackCrows and isThreeBlackCrows()

// Plot Bullish Patterns
plotshape(enableHammer and hammerDetected, title="Hammer", location=location.belowbar, color=color.green, style=shape.labelup, text="Hammer")
plotshape(enableBullEngulfing and bullEngulfDetected, title="Bullish Engulfing", location=location.belowbar, color=color.green, style=shape.labelup, text="Engulf")
plotshape(enablePiercingLine and piercingDetected, title="Piercing Line", location=location.belowbar, color=color.green, style=shape.labelup, text="Piercing")
plotshape(enableMorningStar and morningStarDetected, title="Morning Star", location=location.belowbar, color=color.green, style=shape.labelup, text="Morning")
plotshape(enableThreeWhiteSoldiers and threeWhiteDetected, title="Three White Soldiers", location=location.belowbar, color=color.green, style=shape.labelup, text="3 Soldiers")

// Plot Bearish Patterns
plotshape(enableHangingMan and hangingManDetected, title="Hanging Man", location=location.abovebar, color=color.red, style=shape.labeldown, text="Hanging")
plotshape(enableBearEngulfing and bearEngulfDetected, title="Bearish Engulfing", location=location.abovebar, color=color.red, style=shape.labeldown, text="Engulf")
plotshape(enableDarkCloudCover and darkCloudDetected, title="Dark Cloud Cover", location=location.abovebar, color=color.red, style=shape.labeldown, text="Dark Cloud")
plotshape(enableEveningStar and eveningStarDetected, title="Evening Star", location=location.abovebar, color=color.red, style=shape.labeldown, text="Evening")
plotshape(enableThreeBlackCrows and threeBlackDetected, title="Three Black Crows", location=location.abovebar, color=color.red, style=shape.labeldown, text="3 Crows")

// Strategy Execution
if hammerDetected or bullEngulfDetected or piercingDetected or morningStarDetected or threeWhiteDetected
    strategy.entry("Bullish Entry", strategy.long)

if hangingManDetected or bearEngulfDetected or darkCloudDetected or eveningStarDetected or threeBlackDetected
    strategy.entry("Bearish Entry", strategy.short)