피보나치 패턴 통계 분석 전략

斐波那契 模式识别 统计分析 技术指标 趋势跟踪 ATR 风险管理 IQR
생성 날짜: 2025-03-03 10:24:54 마지막으로 수정됨: 2025-03-03 10:24:54
복사: 3 클릭수: 478
avatar of ianzeng123 ianzeng123
2
집중하다
319
수행원

피보나치 패턴 통계 분석 전략 피보나치 패턴 통계 분석 전략

개요

피보나치 패턴 통계 분석 전략은 피보나치 리커드 레벨, 패턴 인식 알고리즘 및 통계 분석의 세 가지 핵심 기술을 능숙하게 결합한 고급 수치 거래 방법이다. 이 전략은 주로 피보나치 리커드 레벨의 19%와 82.56%를 거래 신호의 기본으로 사용하며, 패턴 매칭 알고리즘을 통해 높은 확률의 거래 설정을 식별하고, 통계 분석을 통해 보조적으로 확인한다. 이러한 다차원 신호 확인 메커니즘은 전략의 신뢰성과 정확성을 크게 향상시킵니다. 이 전략은 명확한 입출장 규칙을 제공합니다.

전략 원칙

피보나치 모델의 통계 분석 전략의 핵심 원칙은 세 가지 주요 구성 요소의 협동 작업에 기반합니다.

  1. 피보나치 회귀 수준이 전략은 93주기의 최고점과 최저점을 사용하여 특수한 19%와 82.56%의 피보나치 회귀 수준을 계산합니다. 이러한 비정상적인 피보나치 수준은 전략의 특이점이며, 시장의 특정 행동에 대한 통계적 분석을 기반으로 할 수 있습니다. 가격이 이러한 수준을 만지거나 돌파하면 초기 거래 신호가 생성됩니다.

  2. 패턴 인식: 전략은 복잡한 패턴 매칭 알고리즘을 구현하여 과거의 가격 패턴을 분석하고 현재 패턴과 유사성을 계산한다. 그것은 지정된 길이의 그래프 패턴을 사용하며, 역사적 데이터 (설정된 5), (설정된 93 주기) 에서 최적의 매칭을 찾는다. 발견된 패턴 유사성이 설정된 임계값 (설정된 0.7) 을 초과하면, 전략은 이 역사적 패턴 이후의 가격 움직임을 바탕으로 현재 패턴 이후의 가능한 움직임을 예측한다.

  3. 통계 분석: 전략은 통계 확정 메커니즘을 도입하여, 중간, 사분, 사분 거리를 계산하여 가격의 통계 분포를 결정한다. 가격이 중간, 상하 사분, 또는 상하 경계 (Q3 + 1.5 * IQR 및 Q1 - 1.5 * IQR로 정의) 를 넘으면 통계 신호가 발생한다. 이러한 신호의 강도는 돌파수 수준과 사용자 설정된 통계 권한에 따라 재 계산된다.

거래 신호는 다음 세 가지 요소의 합성 결과입니다.

  • 다중 조건은 피보나치 터치 또는 돌파 신호를 충족시켜야 하며, 모드 방향은 다방향 또는 중립적이다.
  • 공허화 조건은 피보나치 접촉 또는 돌파 신호를 충족시켜야 하며, 모형 방향은 공허 또는 중성이며, 통계 공허방향 권리는 0 보다 중요하다.

전략은 또한 복잡한 위험 관리 메커니즘을 구현합니다.

  • % 또는 ATR에 따라 선택 가능한 중지 손실
  • 선택적 추적 중지
  • 7단계 분기 수익 메커니즘, 각 레벨 14.28%의 청산 지점

전략적 이점

  1. 다차원 신호 확인이 전략은 기술 분석 (피포나치), 패턴 인식, 통계 분석의 3차원을 결합하여 강력한 복수 확인 메커니즘을 형성하여 가짜 신호의 가능성을 크게 감소시킵니다.

  2. 매우 적응력이 좋다: 전략은 시간 주기의 선택, 모드 길이, 유사성 마이너스, 역사 회귀 창, 통계 주기 등과 같은 풍부한 파라미터 설정을 제공하여 다른 시장 환경과 거래 품종에 적응할 수 있습니다.

  3. 지능형 패턴 인식: 전략의 패턴 매칭 알고리즘은 패턴의 모양뿐만 아니라 유사성 스레드값을 고려하여 매우 유사한 패턴만이 예측에 사용될 수 있도록 보장하여 예측의 정확성을 향상시킵니다.

  4. 통계적 검증4분의 1과 IQR의 통계적 방법을 도입함으로써, 전략은 가격의 통계적 분포의 위치를 식별할 수 있으며, 거래 결정에 대한 추가적인 객관적 근거를 제공합니다.

  5. 좋은 위험 관리: 전략은 여러 종류의 손해 중지 옵션을 제공 합니다 ( 고정 비율, ATR 배수, 추적 중지) 및 7 단계의 분기 수익 메커니즘을 제공하여 유연하고 체계적인 위험 관리를 구현합니다.

  6. 직관적인 시각화: 전략은 배경 색상, 화살표, 표지판 및 태그를 포함한 풍부한 시각적 요소를 제공하여 거래자가 현재의 시장 상태와 신호 강도를 직관적으로 이해할 수 있도록 도와줍니다.

  7. 실시간 상태 패널: 전략은 Fibonacci, 모형 및 세 가지 통계 구성 요소의 현재 상태와 그들의 통합된 결과를 명확하게 보여주는 실시간 업데이트 된 상태 패널을 도표에 표시합니다.

전략적 위험

  1. 매개변수 민감도: 전략은 모드 길이, 유사도 미지수, 통계주기 등과 같은 여러 파라미터를 사용하며, 이러한 파라미터의 설정은 전략 성능에 중대한 영향을 미칩니다. 부적절한 파라미터 설정은 과도한 적합성이나 신호 손실을 초래할 수 있습니다. 피드백 최적화를 통해 특정 시장에 적합한 파라미터 조합을 찾는 것이 좋습니다.

  2. 시장환경의존성: 특정 시장 환경에서 피보나치 레벨이 작동하지 않을 수 있습니다. 특히 강한 추세 또는 극도로 변동하는 시장에서. 전략의 효과는 시장 조건에 따라 달라질 수 있습니다.

  3. 계산의 복잡성: 전략의 패턴 매칭 알고리즘은 각 주기 내의 역사적 데이터를 거쳐서 유사성을 계산해야 하는데, 이는 더 짧은 시간 프레임에 컴퓨팅 부담을 초래할 수 있다. 이 문제를 완화하기 위해, 알고리즘을 최적화하거나 컴퓨팅 주파수를 줄이는 것을 고려할 수 있다.

  4. 과도한 거래의 위험다중 신호 메커니즘은 특히 짧은 시간 프레임에 거래 신호의 빈도를 초래할 수 있습니다. 거래 주파수 제한을 추가하거나 신호 강도 필터를 추가하여 최고 품질의 신호만 실행하는 것이 좋습니다.

  5. 손해 방지 설정 과제: 전략이 여러 가지 중단 옵션을 제공하지만, 최적의 중단 수준을 결정하는 것은 여전히 도전입니다. 너무 긴 중단은 빈번한 중단으로 이어질 수 있고 너무 넓은 것은 과도한 손실로 이어질 수 있습니다. 시장의 변동적 동력에 따라 중단 수준을 조정하는 것이 좋습니다.

  6. 기본적 고려의 부족: 전략은 전적으로 기술 및 통계 분석에 기반하고 기본 요소를 고려하지 않습니다. 중요한 뉴스 또는 사건이 발생했을 때, 순전히 기술적 전략은 도전을받을 수 있습니다. 해결책은 뉴스 필터를 추가하거나 중요한 사건 전후 거래를 중지하는 것입니다.

전략 최적화 방향

  1. 동적 변수 조정: 적응 메커니즘을 도입할 수 있으며, 시장의 변동성이나 트렌드 강도에 따라 패턴 길이, 유사성 마이너스 및 통계 주기와 같은 파라미터를 동적으로 조정할 수 있습니다. 이것은 다양한 시장 환경에서 전략의 적응성을 향상시킬 것입니다.

  2. 강화 모드 매칭 알고리즘: 현재 패턴 매칭은 주로 종전 가격과 개시 가격의 관계에 기초하고 있다. (상승, 하락, 또는 평평함) 패턴 식별의 정확성을 높이기 위해 더 복잡한 패턴 특성을 도입하는 것을 고려할 수 있다.

  3. 시장 환경 분류: 트렌드/레인지/카오시스 분류와 같은 시장 환경 분류 메커니즘을 도입하고, 다른 시장 환경에서 다른 거래 규칙이나 파라미터 설정을 사용하십시오. 이것은 전략이 다른 시장 조건에 더 잘 적응하도록 도와줍니다.

  4. 통계 분석 부분을 최적화: 더 복잡한 통계적 방법을 사용하는 것을 고려할 수 있습니다. 예를 들어, Z-점수 또는 백분율 순위, 또는 통계 신호의 질을 높이기 위해 동적 통계주기를 도입합니다.

  5. 기계학습을 통합하는 것: 패턴 인식 및 통계적 무게 분배를 최적화하거나 특정 패턴을 따르는 가격 이동 확률 분포를 예측하기 위해 기계 학습 알고리즘을 사용하는 것이 고려될 수 있습니다.

  6. 더 나은 위험 관리: 동적인 포지션 관리 전략을 구현할 수 있으며, 신호 강도, 시장 변동성 및 계정 리스크에 따라 포지션 크기를 조정할 수 있습니다. 또한, 분량 수익 메커니즘을 최적화하여 시장 조건에 따라 수익 목표를 동적으로 조정할 수 있습니다.

  7. 필터를 추가합니다.: 트렌드 필터, 파동율 필터 또는 거래량 필터와 같은 다양한 필터를 도입하여 신호 품질을 더욱 향상시키고 가짜 신호를 줄일 수 있습니다.

요약하다

피보나치 패턴 통계 분석 전략은 구조적으로 완벽하게 기능이 풍부한 양적 거래 전략으로, 피보나치 회귀 레벨, 패턴 인식 및 통계 분석을 혁신적으로 결합하여 강력한 다차원 신호 시스템을 구축합니다. 전략의 핵심 장점은 다층 확인 메커니즘, 적응 설계 및 완벽한 위험 관리 기능으로, 다양한 시장 환경에서 높은 확률의 거래 기회를 찾을 수 있습니다.

그러나, 전략은 또한 변수 민감성, 시장 환경 의존성 및 계산 복잡성 등의 도전에 직면한다. 동적 변수 조정, 강화된 모드 매칭 알고리즘, 시장 환경 분류 및 기계 학습과 같은 최적화 방향을 도입함으로써 전략에는 많은 개선의 여지가 있다.

이 전략을 사용하고자 하는 거래자에게는, 먼저 다양한 시장과 변수 설정에서 전략이 어떻게 수행되었는지 재검토하는 것을 권장합니다. 그리고는 실제 거래에서 작은 포지션에서 시작하여 특정 거래 스타일과 시장 환경에 맞게 점진적으로 변수를 조정하고 최적화하십시오.

전략 소스 코드
/*backtest
start: 2024-03-03 00:00:00
end: 2024-05-01 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=6
strategy("Fibonacci-Only Strategi V2", overlay=true)

timeframe = input.timeframe("15", "Select Timeframe", options=["1", "5", "15", "30", "60", "240", "D"])
use_break_strategy = input(true, "Use Break Strategy")
stop_loss_percent = input.float(1.0, "Stop Loss %", minval=0.1, maxval=2.0, step=0.1)
use_atr_for_sl = input(true, "Use ATR for Stop Loss")
atr_multiplier = input.float(2.0, "ATR Multiplier for SL", minval=0.5, maxval=5.0, step=0.1)
use_trailing_stop = input(true, "Use Trailing Stop")
trailing_stop_percent = input.float(1.5, "Trailing Stop %", minval=0.1, maxval=5.0, step=0.1)

pattern_length = input.int(5, "Candle Pattern Length", minval=3, maxval=10)
similarity_threshold = input.float(0.7, "Pattern Similarity Threshold", minval=0.6, maxval=0.95)
lookback_window = input.int(93, "Historical Lookback Window", minval=10, maxval=93)

stat_period = input.int(50, "Statistical Period", minval=20, maxval=200)
stat_weight = input.float(0.5, "Statistical Confirmation Weight", minval=0.1, maxval=1.0, step=0.1)

fib_high = ta.highest(high, 93)
fib_low = ta.lowest(low, 93)
fib_diff = fib_high - fib_low
fib_19 = fib_high - fib_diff * 0.19
fib_8256 = fib_high - fib_diff * 0.8256
fib_19_reverse = fib_low + fib_diff * 0.19

plot(fib_8256, color=color.purple, style=plot.style_line, title="82.56% Fib")
plot(fib_19_reverse, color=color.orange, style=plot.style_line, title="19% Fib (Low to High)")

fib_19_touch = low[1] > fib_19 and low <= fib_19
fib_8256_touch = high[1] < fib_8256 and high >= fib_8256
fib_19_break = close < fib_19 and open > fib_19
fib_8256_break = close > fib_8256 and open < fib_8256
fib_19_reverse_touch = high[1] < fib_19_reverse and high >= fib_19_reverse
fib_19_reverse_break = close > fib_19_reverse and open < fib_19_reverse

bull_confirmation = close > open
bear_confirmation = close < open

getMedianAndQuartiles(src, len) =>
    values = array.new_float(0)
    for i = 0 to len - 1
        array.push(values, src[i])
    array.sort(values)
    size = array.size(values)
    median = size % 2 == 1 ? array.get(values, math.floor(size / 2)) : (array.get(values, size / 2 - 1) + array.get(values, size / 2)) / 2
    q1_idx = math.floor(size / 4)
    q3_idx = math.floor(3 * size / 4)
    q1 = array.get(values, q1_idx)
    q3 = array.get(values, q3_idx)
    [median, q1, q3]

[price_median, price_q1, price_q3] = getMedianAndQuartiles(close, stat_period)
iqr = price_q3 - price_q1
upper_bound = price_q3 + 1.5 * iqr
lower_bound = price_q1 - 1.5 * iqr

stat_bull_signal = close > price_median and close[1] <= price_median
stat_bear_signal = close < price_median and close[1] >= price_median
stat_strong_bull = close > price_q3 and close[1] <= price_q3
stat_strong_bear = close < price_q1 and close[1] >= price_q1
stat_extreme_bull = close > upper_bound
stat_extreme_bear = close < lower_bound

long_condition_fib_touch = (fib_19_touch or fib_19_reverse_touch) and bull_confirmation
long_condition_fib_break = use_break_strategy and (fib_19_break or fib_19_reverse_break) and bull_confirmation

short_condition_fib_touch = fib_19_touch and bear_confirmation
short_condition_fib_break = use_break_strategy and fib_19_break and bear_confirmation

getPatternSignature(start_idx, len) =>
    pattern = array.new_float(len)
    
    for i = 0 to len - 1
        if close[start_idx + i] > open[start_idx + i]
            array.set(pattern, i, 1.0)
        else if close[start_idx + i] < open[start_idx + i]
            array.set(pattern, i, -1.0)
        else
            array.set(pattern, i, 0.0)
    
    pattern

calcSimilarity(current_pattern, hist_pattern) =>
    matches = 0.0
    
    for i = 0 to array.size(current_pattern) - 1
        if array.get(current_pattern, i) == array.get(hist_pattern, i)
            matches := matches + 1.0
    
    matches / array.size(current_pattern)

findBestMatch() =>
    curr_pattern = getPatternSignature(1, pattern_length)
    
    best_idx = -1
    best_sim = 0.0
    direction = 0
    
    for i = pattern_length + 2 to lookback_window + 1
        if i < pattern_length * 2
            continue
            
        hist_pattern = getPatternSignature(i, pattern_length)
        sim = calcSimilarity(curr_pattern, hist_pattern)
        
        if sim > best_sim and sim >= similarity_threshold
            best_sim := sim
            best_idx := i
            
            next_close = close[i - pattern_length - 1]
            curr_close = close[i - pattern_length]
            
            if next_close > curr_close
                direction := 1
            else if next_close < curr_close
                direction := -1
    
    [best_idx, best_sim, direction]

var latest_pattern_sim = 0.0
var pattern_direction = 0

if barstate.isconfirmed
    [idx, sim, dir] = findBestMatch()
    
    if sim >= similarity_threshold
        latest_pattern_sim := sim
        pattern_direction := dir

calculateStatWeight(stat_signal, stat_strong, stat_extreme) =>
    weight = 0.0
    if stat_signal
        weight := stat_weight * 0.5
    if stat_strong
        weight := weight + stat_weight * 0.3
    if stat_extreme
        weight := weight + stat_weight * 0.2
    weight

stat_bull_weight = calculateStatWeight(stat_bull_signal, stat_strong_bull, stat_extreme_bull)
stat_bear_weight = calculateStatWeight(stat_bear_signal, stat_strong_bear, stat_extreme_bear)

long_condition = (long_condition_fib_touch or long_condition_fib_break) and 
                 (pattern_direction == 1 or pattern_direction == 0)

short_condition = (short_condition_fib_touch or short_condition_fib_break) and 
                  (pattern_direction == -1 or pattern_direction == 0) and
                  stat_bear_weight > 0

atr = ta.atr(14)

if long_condition
    strategy.entry("Long", strategy.long)

if short_condition
    strategy.entry("Short", strategy.short)

var float long_stop_loss = na
var float short_stop_loss = na

if strategy.position_size > 0
    long_stop_loss := use_atr_for_sl ? strategy.position_avg_price - atr * atr_multiplier : strategy.position_avg_price * (1 - stop_loss_percent / 100)

if strategy.position_size < 0
    short_stop_loss := use_atr_for_sl ? strategy.position_avg_price + atr * atr_multiplier : strategy.position_avg_price * (1 + stop_loss_percent / 100)

take_profit_levels = array.new_float(7)
for i = 0 to 6
    tp_percent = 1 + (i + 1) * 0.5 / 100
    array.set(take_profit_levels, i, tp_percent * strategy.position_avg_price)

if strategy.position_size > 0
    if use_trailing_stop
        trail_price = high - (high - strategy.position_avg_price) * trailing_stop_percent / 100
        strategy.exit("Long TS", "Long", stop=math.max(trail_price, long_stop_loss))
    else
        strategy.exit("Long SL", "Long", stop=long_stop_loss)
    
    for i = 0 to 6
        long_tp_price = array.get(take_profit_levels, i)
        strategy.exit("Long TP" + str.tostring(i+1), "Long", limit=long_tp_price, qty_percent=14.28)

if strategy.position_size < 0
    if use_trailing_stop
        trail_price = low + (strategy.position_avg_price - low) * trailing_stop_percent / 100
        strategy.exit("Short TS", "Short", stop=math.min(trail_price, short_stop_loss))
    else
        strategy.exit("Short SL", "Short", stop=short_stop_loss)
    
    for i = 0 to 6
        short_tp_price = array.get(take_profit_levels, i)
        strategy.exit("Short TP" + str.tostring(i+1), "Short", limit=short_tp_price, qty_percent=14.28)

bgcolor(long_condition ? color.new(color.green, 80) : short_condition ? color.new(color.red, 80) : na)

plotarrow(long_condition ? 1 : short_condition ? -1 : 0, title="Signal Direction", colorup=color.green, colordown=color.red, minheight=10, maxheight=20)

long_touch_marker = long_condition and long_condition_fib_touch ? low - atr : na
long_break_marker = long_condition and long_condition_fib_break ? low - atr * 1.5 : na
short_touch_marker = short_condition and short_condition_fib_touch ? high + atr : na
short_break_marker = short_condition and short_condition_fib_break ? high + atr * 1.5 : na

plotshape(long_touch_marker, style=shape.circle, color=color.green, size=size.normal, title="Long Touch Marker", location=location.absolute)
plotshape(long_break_marker, style=shape.xcross, color=color.green, size=size.normal, title="Long Break Marker", location=location.absolute)
plotshape(short_touch_marker, style=shape.circle, color=color.red, size=size.normal, title="Short Touch Marker", location=location.absolute)
plotshape(short_break_marker, style=shape.xcross, color=color.red, size=size.normal, title="Short Break Marker", location=location.absolute)

plotshape(stat_bear_signal, style=shape.triangledown, color=color.red, size=size.tiny, title="Statistical Bear Signal", location=location.abovebar)

if barstate.islast
    var table info = table.new(position.top_right, 4, 5, color.black, color.white, 2, color.gray, 2)
    
    table.clear(info, 0, 0, 3, 4)
    
    table.cell(info, 0, 0, "Fibonacci-Pattern with Stats", bgcolor=color.blue, text_color=color.white)
    table.cell(info, 0, 1, "Fib Status", bgcolor=color.blue, text_color=color.white)
    
    fib_status = "NEUTRAL"
    fib_color = color.gray
    
    if long_condition_fib_touch or long_condition_fib_break
        fib_status := "LONG"
        fib_color := color.green
    else if short_condition_fib_touch or short_condition_fib_break
        fib_status := "SHORT"
        fib_color := color.red
        
    table.cell(info, 1, 1, fib_status, bgcolor=fib_color, text_color=color.white)
    
    table.cell(info, 0, 2, "Pattern", bgcolor=color.blue, text_color=color.white)
    
    pattern_status = "NEUTRAL"
    pattern_color = color.gray
    
    if pattern_direction == 1
        pattern_status := "LONG"
        pattern_color := color.green
    else if pattern_direction == -1
        pattern_status := "SHORT"
        pattern_color := color.red
        
    table.cell(info, 1, 2, pattern_status, bgcolor=pattern_color, text_color=color.white)
    table.cell(info, 2, 2, pattern_direction != 0 ? str.tostring(math.round(latest_pattern_sim * 100)) + "%" : "N/A", bgcolor=color.gray, text_color=color.white)
    
    table.cell(info, 0, 3, "Statistics", bgcolor=color.blue, text_color=color.white)
    
    stat_status = "NEUTRAL"
    stat_color = color.gray
    
    if stat_bull_weight > 0
        stat_status := "BULL"
        stat_color := color.green
    else if stat_bear_weight > 0
        stat_status := "BEAR"
        stat_color := color.red
        
    table.cell(info, 1, 3, stat_status, bgcolor=stat_color, text_color=color.white)
    table.cell(info, 2, 3, stat_bull_weight > 0 ? str.tostring(math.round(stat_bull_weight * 100)) + "%" : 
                          stat_bear_weight > 0 ? str.tostring(math.round(stat_bear_weight * 100)) + "%" : "0%", 
                          bgcolor=color.gray, text_color=color.white)
    
    table.cell(info, 0, 4, "Combined", bgcolor=color.blue, text_color=color.white)
    
    combined_status = "NEUTRAL"
    combined_color = color.gray
    
    if long_condition
        combined_status := "LONG"
        combined_color := color.green
    else if short_condition
        combined_status := "SHORT"
        combined_color := color.red
        
    table.cell(info, 1, 4, combined_status, bgcolor=combined_color, text_color=color.white)

var label_id = label.new(na, na, "", color=color.gray, style=label.style_label_down, textcolor=color.white)

if long_condition and barstate.isconfirmed
    label.set_xy(label_id, bar_index, high)
    label.set_text(label_id, "LONG\n" + 
                           (long_condition_fib_touch ? "Touch" : "Break") + 
                           (pattern_direction == 1 ? " + Pattern " + str.tostring(math.round(latest_pattern_sim * 100)) + "%" : "") +
                           "\nStat: " + str.tostring(math.round(stat_bull_weight * 100)) + "%")
    label.set_color(label_id, color.green)
    label.set_style(label_id, label.style_label_down)

if short_condition and barstate.isconfirmed
    label.set_xy(label_id, bar_index, low)
    label.set_text(label_id, "SHORT\n" + 
                           (short_condition_fib_touch ? "Touch" : "Break") + 
                           (pattern_direction == -1 ? " + Pattern " + str.tostring(math.round(latest_pattern_sim * 100)) + "%" : "") +
                           "\nStat: " + str.tostring(math.round(stat_bear_weight * 100)) + "%")
    label.set_color(label_id, color.red)
    label.set_style(label_id, label.style_label_up)

alertcondition(long_condition, title="Long Entry", message="Long entry signal detected")
alertcondition(short_condition, title="Short Entry", message="Short entry signal detected")