가격 범위와 돌파구에 기반한 효율적인 양적 거래 전략

Pivot CONSOLIDATION ZONE BREAKOUT
생성 날짜: 2025-02-20 11:41:51 마지막으로 수정됨: 2025-02-27 17:46:06
복사: 2 클릭수: 363
avatar of ianzeng123 ianzeng123
2
집중하다
319
수행원

가격 범위와 돌파구에 기반한 효율적인 양적 거래 전략 가격 범위와 돌파구에 기반한 효율적인 양적 거래 전략

개요

이 전략은 주로 시장 내의 조회 영역을 식별하고, 가격이 이러한 영역을 돌파 할 때 거래합니다. 이 전략은 ZigZag 지표를 사용하여 중요한 가격 지점을 식별하고, 높은 낮은 점과 함께 조회 영역을 정의하고, 가격이 이러한 영역을 돌파 할 때 거래 신호를 발송합니다.

전략 원칙

이 전략의 핵심 논리는 다음과 같은 몇 가지 핵심 단계를 포함합니다.

  1. Loopback Period의 최고 가격과 최저 가격으로 중요한 전환점을 식별합니다.
  2. 지그자그 알고리즘을 사용하여 가격 움직임을 추적하여 중요한 지원 및 저항 지점을 결정합니다.
  3. 최소 통합 길이를 설정하여 유효한 통합 간격을 확인합니다.
  4. 동적으로 상하 경계 업데이트, 실시간으로 지역 개조 변경을 추적
  5. 거래 신호를 트리거 할 때 가격이 포괄 범위를 돌파

전략적 이점

  1. 적응성 - 전략은 다양한 시장 환경에 적응하기 위해 회수 범위를 동적으로 식별하고 업데이트 할 수 있습니다.
  2. 위험 제어 - 명확한 회수 영역을 정의하여 거래에 대한 명확한 중지 손실 위치를 제공합니다.
  3. 시각적 지원 - 거래자가 시장 상태를 이해하는 데 도움이되는 회수 영역의 시각적 표시를 제공합니다.
  4. 양방향 거래 - 시장 기회를 극대화하기 위해 상향과 하향의 거래 기회를 지원합니다.
  5. 변수 조정 가능 - 다양한 시장 특성에 따라 최적화 할 수 있도록 여러 가지 조정 가능한 매개 변수를 제공합니다

전략적 위험

  1. 가짜 침입 위험 - 시장에서 가짜 침입이 발생하여 거래 실패로 이어질 수 있습니다.
  2. 미끄러지 위험 - 빠른 시점에 큰 미끄러짐이 발생할 수 있습니다.
  3. 시장 환경 의존성 - 전략은 흔들리는 시장에서 잘 작동하지만 추세 시장에서는 좋지 않을 수 있습니다.
  4. 매개 변수 민감성 - 매개 변수 설정이 잘못되면 정책 성능에 영향을 미칠 수 있습니다.
  5. 자금 관리 위험 - 거래마다 필요한 자금의 규모를 합리적으로 통제하는 것

전략 최적화 방향

  1. 거래량 지표 도입 - 거래량으로 돌파구를 확인하는 효과
  2. 입학 시간을 최적화 - 재청구 확인 메커니즘을 추가하여 입학 품질을 향상시킵니다.
  3. 손해 방지 제도를 개선하고, 더 유연한 손해 방지 전략을 수립합니다.
  4. 시장 환경 필터를 추가합니다. 트렌드 판단을 추가하여 적절한 시장 환경에서 작동합니다.
  5. 최적화 매개 변수 적응 - 시장의 변동성에 따라 매개 변수를 자동으로 조정

요약하다

이것은 합리적이고 논리적으로 명확하게 설계된 양적 거래 전략이다. 평형 영역을 식별하고 돌파 신호를 포착함으로써 거래자에게 신뢰할 수있는 거래 시스템을 제공합니다. 전략의 시각화 효과와 매개 변수 유연성은 실용성을 갖는다. 지속적인 최적화 및 위험 제어로 전략은 실제 거래에서 안정적인 수익을 얻을 수 있습니다.

전략 소스 코드
/*backtest
start: 2024-09-01 00:00:00
end: 2025-02-18 08:00:00
period: 5d
basePeriod: 5d
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/

// This code is released under the Mozilla Public License 2.0
// More details at: https://mozilla.org/MPL/2.0/
// © LonesomeTheBlue

//@version=5
strategy("Consolidation Zones - Live [Strategy]", overlay=true, max_bars_back=1100)

//-----------------------------------------------------------------------//
//                        Input Variables
//-----------------------------------------------------------------------//
prd       = input.int(defval=10, title="Loopback Period", minval=2, maxval=50)
conslen   = input.int(defval=5,  title="Min. Consolidation Length", minval=2, maxval=20)
paintcons = input.bool(defval=true, title="Color Consolidation Zone?")
zonecol   = input.color(defval=color.new(color.blue, 70), title="Zone Color")

//-----------------------------------------------------------------------//
//                  Variables and Calculations for ZZ (ZigZag) Detection
//-----------------------------------------------------------------------//

// Check if the bar has the highest High or lowest Low in the last prd bars
float hb_ = ta.highestbars(prd) == 0 ? high : na
float lb_ = ta.lowestbars(prd)  == 0 ? low  : na

// Convert to bool to check if hb_ and lb_ are valid (not na)
bool hasHb = not na(hb_)
bool hasLb = not na(lb_)

// Direction variable to determine the trend, based on the last high or low pivot
var int dir = 0

// ZigZag value and last pivot
float zz = na
float pp = na

// 1) Determine direction based on whether a high or low pivot occurred
dir := if hasHb and not hasLb
    1
else if hasLb and not hasHb
    -1
else
    dir  // unchanged direction

// 2) If both a high and low pivot occurred in the same bar
bool sameBar = hasHb and hasLb
if sameBar
    if dir == 1
        zz := hb_
    else
        zz := lb_
else
    zz := hasHb ? hb_ : (hasLb ? lb_ : na)

// 3) Storing last pivots (pp) - iterate over older bars
for x = 0 to 1000
    if na(close) or dir != dir[x]
        break
    if not na(zz[x])  // if zz[x] is a valid value
        if na(pp)
            pp := zz[x]
        else
            if dir[x] == 1 and zz[x] > pp
                pp := zz[x]
            if dir[x] == -1 and zz[x] < pp
                pp := zz[x]

//-----------------------------------------------------------------------//
//                Logic for Consolidation Zone Detection
//-----------------------------------------------------------------------//
var int   conscnt    = 0
var float condhigh   = na
var float condlow    = na

float H_ = ta.highest(conslen)
float L_ = ta.lowest(conslen)

var line upline      = na
var line dnline      = na

bool breakoutup    = false
bool breakoutdown  = false

// Check if pp has changed
bool changedPP = ta.change(pp) != 0

if changedPP
    // If enough candles are in consolidation, check for breakout
    if conscnt > conslen and not na(condhigh) and not na(condlow) and not na(pp)
        if pp > condhigh
            breakoutup := true
        if pp < condlow
            breakoutdown := true
    
    // Check if we are still "in the zone"
    bool inZone = conscnt > 0 and not na(pp) and not na(condhigh) and not na(condlow) and (pp <= condhigh) and (pp >= condlow)
    if inZone
        conscnt += 1
    else
        conscnt := 0
else
    // No change in pivot -> continue consolidation
    conscnt += 1

if conscnt >= conslen
    // At the first "touch" of the required number of candles
    if conscnt == conslen
        condhigh := H_
        condlow  := L_
    else
        condhigh := math.max(condhigh, high)
        condlow  := math.min(condlow, low)
    

//-----------------------------------------------------------------------//
//                          Drawing Fill
//-----------------------------------------------------------------------//
// Declare two plot variables (just ordinary assignment)
condHighPlot = plot(condhigh, color=na, style=plot.style_stepline)
condLowPlot  = plot(condlow,  color=na, style=plot.style_stepline)

// bool to check if we want to color the zone
bool doFill = paintcons and (conscnt > conslen)

// Calling fill
fill(condHighPlot, condLowPlot, color= doFill ? zonecol : color.new(color.white, 100))

//-----------------------------------------------------------------------//
//                          Alerts & STRATEGY
//-----------------------------------------------------------------------//
alertcondition(breakoutup,   title="Breakout Up",   message="Breakout Up")
alertcondition(breakoutdown, title="Breakout Down", message="Breakout Down")

if breakoutup
    // Close short first
    if strategy.position_size < 0
        strategy.close("Breakout Short")
    // Open LONG
    strategy.entry("Breakout Long", strategy.long)

if breakoutdown
    // Close long first
    if strategy.position_size > 0
        strategy.close("Breakout Long")
    // Open SHORT
    strategy.entry("Breakout Short", strategy.short)