이중 지수 이동 평균 바운스 모멘텀 트레이딩 전략

EMA SL TP R:R 趋势一致性 反弹交易 动量交易 风险管理 蜡烛图形态
생성 날짜: 2025-06-03 10:59:06 마지막으로 수정됨: 2025-06-03 10:59:06
복사: 0 클릭수: 281
avatar of ianzeng123 ianzeng123
2
집중하다
319
수행원

이중 지수 이동 평균 바운스 모멘텀 트레이딩 전략 이중 지수 이동 평균 바운스 모멘텀 트레이딩 전략

개요

이 전략은 쌍 지수 이동 평균선 (EMA) 을 형성한 가격을 활용하여 높은 확률의 역전 기회를 식별한다. 단순한 평균선 통과 전략이 아니라, 가격의 EMA에서 반발하고 강력한 동력을 형성하는 시간을 찾는다. 이 전략은 12주기 및 21주기 EMA를 사용하여 거래 구역을 구성하고, 그래프 형태, 트렌드 일관성 및 정확한 위험 관리 시스템을 결합하여 시장 동력을 포착한다.

전략 원칙

이 전략의 핵심 원칙은 가격이 EMA에서 반발하는 경우를 식별하여 진입 신호를 찾는 것입니다. 12주기 및 21주기 EMA를 사용하여 상하 거래 구역을 만들고 EMA의 상대적 위치에 따라 시장의 경향 방향을 결정합니다.

EMA12 > EMA21시장이 부진한 환경 ((녹색 영역) 에 있을 때, 우리는 여러 가지 기회를 찾습니다. 여러 가지 조건은 다음과 같습니다: 가격 하위 그림자가 EMA 영역에 닿고, 강력한 부진이 형성됩니다 ((하위 그림자보다 큰 개체), 상위 그림자가 최소화됩니다 (( 범위의 2% 미만), 두 개의 EMA보다 높은 종결 가격, 이전 그림자가 하위 영역 아래에 들어가지 않고, 그리고 몇 개의 연쇄 뿌리가 부진 추세 일관성을 유지합니다.

EMA12 < EMA21, 시장이 하향 환경 (붉은 영역) 에있을 때, 우리는 하향 기회를 찾습니다. 하향 조건은 다음과 같습니다: 가격 상조선은 EMA 영역을 만지고, 강력한 하향 경로를 형성합니다. 상조선보다 큰 실물 (주체), 하향 경계가 최소화됩니다. ( 범위의 2% 미만).

전략은 내장된 고정 리스크 수익률의 리스크 관리 시스템으로, 기본적으로 3:1, 스톱로스는 이전 의 최고/최저에 설정되며, 스톱은 리스크 수익률에 따라 자동으로 계산된다.

전략적 이점

이 전략에는 몇 가지 중요한 장점이 있습니다.

  1. 높은 승률 잠재력: 이 전략은 EMA의 반발 이후의 강력한 동력 상황을 포착함으로써 성공 가능성이 높은 거래 기회를 식별할 수 있다.

  2. 명확한 입출장 규칙: 전략은 명확한 거래 조건을 제공하며 주관적 판단과 감정적 의사 결정의 영향을 줄입니다.

  3. 우수한 위험 관리: 고정된 리스크 수익률과 자동 중지 손실 차단 설정을 사용하여 각 거래의 위험이 통제되도록합니다.

  4. 트렌드는 우위를 따른다: 전략은 트렌드를 지배하는 방향으로만 거래하며, 역행동의 높은 위험을 피한다.

  5. 다중 시간 주기에 적용: 이 전략은 다양한 시간 주기에 효과적으로 작동하여 유연한 거래 옵션을 제공합니다.

  6. 포괄적 인 경고 시스템: 거래 기회를 놓치지 않도록 세부적인 거래 신호 상기 기능이 내장되어 있습니다.

  7. 시각적 도움말: 배경 색상 변화와 태그提示을 통해 거래 신호와 조건 상태를 직관적으로 표시한다.

전략적 위험

이 전략은 훌륭하게 설계되었지만, 다음과 같은 잠재적인 위험들이 있습니다.

  1. 흔들리는 시장 위험: 가로판 또는 흔들리는 시장에서 EMA 대역이 밀집되어 빈번하지만 낮은 품질의 신호를 생성하여 연속적인 손실을 초래할 수 있습니다.

  2. 급격한 가격 폭락 위험: 중요한 뉴스 또는 사건 이후에 시장이 폭락하여 스톱포트가 무효화되어 예상보다 더 큰 손실이 발생할 수 있습니다.

  3. 변수 최적화 과잉: 과도하게 최적화된 전략 변수들은 곡선 적합성을 초래하여 전략이 실판 거래에서 좋지 않은 성능을 발휘하게 할 수 있다.

  4. 트렌드 인식 지연: EMA는 지연 지표로서, 트렌드 전환점에서 느리게 반응할 수 있으며, 이로 인해 최적의 진입 지점을 놓치거나 퇴출을 지연시킬 수 있다.

  5. 정지 손실 트리거 위험: 시장의 소음은 정지 손실이 유발되면 가격이 예상 방향으로 돌아가서 불필요한 손실을 초래할 수 있습니다.

해결 방법은 다음과 같습니다: 흔들리는 시장에서 거래를 중지; 변동율 필터를 사용하여 낮은 품질의 신호를 피하십시오. 다른 지표와 결합하여 트렌드를 확인하십시오. 주기적으로 재검토하고 최적화 매개 변수; 추적 스톱을 사용하는 것을 고려하십시오.

전략 최적화 방향

이 전략은 다음과 같은 방향으로 최적화될 수 있습니다.

  1. 동적 위험 관리: 시장의 변동에 따라 자동으로 리스크 수익률과 포지션 크기를 조정하여 높은 변동성 환경에서 리스크 을 줄인다.

  2. 고급 필터 도입: ATR ((평균 실제 파장) 지표와 결합하여 낮은 변동 기간의 신호를 필터링합니다. 거래량 확인을 추가하여 가격 반전의 유효성을 검증합니다.

  3. 다중 시간 주기의 분석: 더 높은 시간 주기의 트렌드 방향을 통합하는 추가 필터링 조건으로, 여러 시간 주기의 트렌드가 일치할 때만 들어간다.

  4. 머신러닝 최적화: 머신러닝 알고리즘을 사용하여 매개 변수를 동적으로 조정하여 다른 시장 환경에 따라 최적의 매개 변수 조합에 적응합니다.

  5. 추적 중지 실현: 수익이 일정 수준에 도달 한 후, 추적 중지 메커니즘을 적용하여 수익의 일부를 잠금하는 동시에 추세가 계속 발전하도록 허용하십시오.

  6. 부분 수익 전략: 분기 수익 전략을 시행하고, 다양한 목표 가격에서 점진적으로 지분을 줄이고, 전반적인 리스크 수익 성과를 최적화한다.

이러한 최적화 방향은 전략의 안정성, 적응성, 그리고 장기적인 수익성을 향상시킬 수 있습니다.

요약하다

이진 지수 이동평균带反弹动量 거래 전략은 기술 분석, 도표형태 식별 및 엄격한 위험 관리를 결합한 종합 거래 시스템이다. 그것은 가격의 EMA带反弹의 높은 확률의 반전점을 식별하여 폭발적인 동력을 가진 시장 기회를 포착한다. 이 전략의 핵심 장점은 명확한 거래 규칙, 고정된 위험 수익 프레임워크 및 트렌드 일관성 요구 사항에 있으며, 다양한 시장 환경과 주기적 시간에 적합하다.

몇 가지 잠재적인 위험에도 불구하고, 제안된 최적화 조치를 시행함으로써, 거래자는 전략의 안정성과 수익성을 더욱 향상시킬 수 있습니다. 이 전략은 체계화되고, 규율되고, 위험을 통제할 수 있는 거래 방법을 찾는 거래자에게 특히 적합하며, 단기 또는 중장기 투자자 모두 혜택을 누릴 수 있습니다.

전략 소스 코드
/*backtest
start: 2025-05-26 00:00:00
end: 2025-06-02 00:00:00
period: 5m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/

//@version=5
strategy("Enhanced EMA Band Rejection Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10)

// Input parameters
ema12_length = input.int(12, title="EMA 12 Length")
ema21_length = input.int(21, title="EMA 21 Length")
max_wick_percent = input.float(2.0, title="Max Wick % at High/Low", minval=0.0, maxval=10.0)
risk_reward_ratio = input.float(3.0, title="Risk/Reward Ratio (R)", minval=1.0, maxval=10.0)
trend_consistency_bars = input.int(5, title="Trend Consistency Required (Bars)", minval=1, maxval=20)

// Notification Settings
enable_notifications = input.bool(true, title="Enable Notifications", group="Notifications")
notify_on_entry = input.bool(true, title="Notify on Trade Entry", group="Notifications")
notify_on_exit = input.bool(true, title="Notify on Trade Exit", group="Notifications")
notify_on_setup = input.bool(false, title="Notify on Potential Setup (Pre-Entry)", group="Notifications")
notify_on_failed_conditions = input.bool(false, title="Notify on Failed Conditions", group="Notifications")

// Calculate EMAs
ema12 = ta.ema(close, ema12_length)
ema21 = ta.ema(close, ema21_length)

// Determine upper and lower EMA bands
ema_upper = math.max(ema12, ema21)
ema_lower = math.min(ema12, ema21)

// Plot EMAs
plot(ema12, color=color.blue, linewidth=2, title="EMA 12")
plot(ema21, color=color.red, linewidth=2, title="EMA 21")

// Calculate candle components
body_size = math.abs(close - open)
upper_wick = high - math.max(open, close)
lower_wick = math.min(open, close) - low
candle_range = high - low

// Calculate wick percentages
upper_wick_percent = candle_range > 0 ? (upper_wick / candle_range) * 100 : 0
lower_wick_percent = candle_range > 0 ? (lower_wick / candle_range) * 100 : 0

// Determine EMA trend direction
ema_bullish = ema12 > ema21  // Green bands - bullish trend
ema_bearish = ema12 < ema21  // Red bands - bearish trend

// Check trend consistency for required number of bars
bullish_consistency_check = true
bearish_consistency_check = true

for i = 0 to trend_consistency_bars - 1
    ema12_past = ta.ema(close[i], ema12_length)
    ema21_past = ta.ema(close[i], ema21_length)
    if ema12_past <= ema21_past
        bullish_consistency_check := false
    if ema12_past >= ema21_past
        bearish_consistency_check := false

// Final trend conditions with consistency requirement
ema_bullish_consistent = ema_bullish and bullish_consistency_check
ema_bearish_consistent = ema_bearish and bearish_consistency_check

// NEW RULE: Previous candle close position relative to bands
prev_close_above_upper_band = close[1] > ema_upper[1]
prev_close_below_lower_band = close[1] < ema_lower[1]
prev_close_within_bands = close[1] >= ema_lower[1] and close[1] <= ema_upper[1]

// Long setup conditions (only when EMAs are bullish/green consistently)
long_wick_condition = low <= ema_lower or (low <= ema_upper and low >= ema_lower)
long_body_condition = body_size >= lower_wick
long_wick_percent_condition = upper_wick_percent <= max_wick_percent
long_bullish_candle = close > open
long_trend_condition = ema_bullish_consistent  // Only long when bands are consistently green
long_close_above_bands = close > ema_upper  // NEW: Close must be above both EMAs
// Previous candle must not have closed below the lower band
long_prev_close_condition = not prev_close_below_lower_band
long_setup = long_wick_condition and long_body_condition and long_wick_percent_condition and long_bullish_candle and long_trend_condition and long_close_above_bands and long_prev_close_condition

// Short setup conditions (only when EMAs are bearish/red consistently)
short_wick_condition = high >= ema_upper or (high >= ema_lower and high <= ema_upper)
short_body_condition = body_size >= upper_wick
short_wick_percent_condition = lower_wick_percent <= max_wick_percent
short_bearish_candle = close < open
short_trend_condition = ema_bearish_consistent  // Only short when bands are consistently red
short_close_below_bands = close < ema_lower  // NEW: Close must be below both EMAs
// Previous candle must not have closed above the upper band
short_prev_close_condition = not prev_close_above_upper_band
short_setup = short_wick_condition and short_body_condition and short_wick_percent_condition and short_bearish_candle and short_trend_condition and short_close_below_bands and short_prev_close_condition

// Entry conditions
var float long_sl = na
var float short_sl = na
var float long_tp = na
var float short_tp = na

if long_setup and strategy.position_size == 0
    strategy.entry("Long", strategy.long)
    long_sl := low
    risk_amount = close - long_sl
    long_tp := close + (risk_amount * risk_reward_ratio)
    label.new(bar_index, low, "LONG", style=label.style_label_up, color=color.green, size=size.small)
    
    // Entry Notification
    if enable_notifications and notify_on_entry
        alert("🟢 LONG ENTRY SIGNAL\n" + 
              "Symbol: " + syminfo.ticker + "\n" + 
              "Price: " + str.tostring(close, "#.####") + "\n" + 
              "Stop Loss: " + str.tostring(long_sl, "#.####") + "\n" + 
              "Take Profit: " + str.tostring(long_tp, "#.####") + "\n" + 
              "Risk/Reward: " + str.tostring(risk_reward_ratio, "#.##") + "R\n" + 
              "Time: " + str.tostring(time), alert.freq_once_per_bar)

if short_setup and strategy.position_size == 0
    strategy.entry("Short", strategy.short)
    short_sl := high
    risk_amount = short_sl - close
    short_tp := close - (risk_amount * risk_reward_ratio)
    label.new(bar_index, high, "SHORT", style=label.style_label_down, color=color.red, size=size.small)
    
    // Entry Notification
    if enable_notifications and notify_on_entry
        alert("🔴 SHORT ENTRY SIGNAL\n" + 
              "Symbol: " + syminfo.ticker + "\n" + 
              "Price: " + str.tostring(close, "#.####") + "\n" + 
              "Stop Loss: " + str.tostring(short_sl, "#.####") + "\n" + 
              "Take Profit: " + str.tostring(short_tp, "#.####") + "\n" + 
              "Risk/Reward: " + str.tostring(risk_reward_ratio, "#.##") + "R\n" + 
              "Time: " + str.tostring(time), alert.freq_once_per_bar)

// Exit conditions with fixed R:R
if strategy.position_size > 0
    // Long position - fixed stop loss and take profit
    strategy.exit("Long Exit", "Long", stop=long_sl, limit=long_tp)
    
    // Exit Notifications
    if enable_notifications and notify_on_exit
        if close <= long_sl
            alert("🛑 LONG STOP LOSS HIT\n" + 
                  "Symbol: " + syminfo.ticker + "\n" + 
                  "Exit Price: " + str.tostring(close, "#.####") + "\n" + 
                  "Loss: " + str.tostring(close - strategy.position_avg_price, "#.####") + "\n" + 
                  "Time: " + str.tostring(time), alert.freq_once_per_bar)
        if close >= long_tp
            alert("🎯 LONG TAKE PROFIT HIT\n" + 
                  "Symbol: " + syminfo.ticker + "\n" + 
                  "Exit Price: " + str.tostring(close, "#.####") + "\n" + 
                  "Profit: " + str.tostring(close - strategy.position_avg_price, "#.####") + "\n" + 
                  "Time: " + str.tostring(time), alert.freq_once_per_bar)

if strategy.position_size < 0
    // Short position - fixed stop loss and take profit
    strategy.exit("Short Exit", "Short", stop=short_sl, limit=short_tp)
    
    // Exit Notifications
    if enable_notifications and notify_on_exit
        if close >= short_sl
            alert("🛑 SHORT STOP LOSS HIT\n" + 
                  "Symbol: " + syminfo.ticker + "\n" + 
                  "Exit Price: " + str.tostring(close, "#.####") + "\n" + 
                  "Loss: " + str.tostring(strategy.position_avg_price - close, "#.####") + "\n" + 
                  "Time: " + str.tostring(time), alert.freq_once_per_bar)
        if close <= short_tp
            alert("🎯 SHORT TAKE PROFIT HIT\n" + 
                  "Symbol: " + syminfo.ticker + "\n" + 
                  "Exit Price: " + str.tostring(close, "#.####") + "\n" + 
                  "Profit: " + str.tostring(strategy.position_avg_price - close, "#.####") + "\n" + 
                  "Time: " + str.tostring(time), alert.freq_once_per_bar)

// Plot stop levels and take profit levels
plot(strategy.position_size > 0 ? long_sl : na, color=color.red, linewidth=2, style=plot.style_line, title="Long SL")
plot(strategy.position_size < 0 ? short_sl : na, color=color.red, linewidth=2, style=plot.style_line, title="Short SL")
plot(strategy.position_size > 0 ? long_tp : na, color=color.green, linewidth=2, style=plot.style_line, title="Long TP")
plot(strategy.position_size < 0 ? short_tp : na, color=color.green, linewidth=2, style=plot.style_line, title="Short TP")

// Additional Notification Logic
// Potential Setup Notifications (when most conditions are met but not all)
long_potential_setup = long_wick_condition and long_body_condition and long_wick_percent_condition and long_bullish_candle and long_trend_condition and long_prev_close_condition and not long_close_above_bands
short_potential_setup = short_wick_condition and short_body_condition and short_wick_percent_condition and short_bearish_candle and short_trend_condition and short_prev_close_condition and not short_close_below_bands

if enable_notifications and notify_on_setup and strategy.position_size == 0
    if long_potential_setup
        alert("⚠️ POTENTIAL LONG SETUP\n" + 
              "Symbol: " + syminfo.ticker + "\n" + 
              "Price: " + str.tostring(close, "#.####") + "\n" + 
              "Status: Close needs to be above " + str.tostring(ema_upper, "#.####") + "\n" + 
              "Current Close: " + str.tostring(close, "#.####") + "\n" + 
              "Time: " + str.tostring(time), alert.freq_once_per_bar)
    
    if short_potential_setup
        alert("⚠️ POTENTIAL SHORT SETUP\n" + 
              "Symbol: " + syminfo.ticker + "\n" + 
              "Price: " + str.tostring(close, "#.####") + "\n" + 
              "Status: Close needs to be below " + str.tostring(ema_lower, "#.####") + "\n" + 
              "Current Close: " + str.tostring(close, "#.####") + "\n" + 
              "Time: " + str.tostring(time), alert.freq_once_per_bar)

// Failed Conditions Notifications (for debugging)
if enable_notifications and notify_on_failed_conditions and strategy.position_size == 0
    if long_wick_condition and long_body_condition and long_wick_percent_condition and long_bullish_candle and not long_trend_condition
        alert("❌ LONG SETUP FAILED\n" + 
              "Symbol: " + syminfo.ticker + "\n" + 
              "Reason: " + (not ema_bullish ? "EMA trend bearish" : "EMA trend not consistent") + "\n" + 
              "EMA12: " + str.tostring(ema12, "#.####") + "\n" + 
              "EMA21: " + str.tostring(ema21, "#.####") + "\n" + 
              "Time: " + str.tostring(time), alert.freq_once_per_bar)
    
    if short_wick_condition and short_body_condition and short_wick_percent_condition and short_bearish_candle and not short_trend_condition
        alert("❌ SHORT SETUP FAILED\n" + 
              "Symbol: " + syminfo.ticker + "\n" + 
              "Reason: " + (not ema_bearish ? "EMA trend bullish" : "EMA trend not consistent") + "\n" + 
              "EMA12: " + str.tostring(ema12, "#.####") + "\n" + 
              "EMA21: " + str.tostring(ema21, "#.####") + "\n" + 
              "Time: " + str.tostring(time), alert.freq_once_per_bar)
bgcolor(long_setup ? color.new(color.green, 90) : na, title="Long Setup")
bgcolor(short_setup ? color.new(color.red, 90) : na, title="Short Setup")
// Show when previous close condition fails
bgcolor(long_wick_condition and long_body_condition and long_wick_percent_condition and long_bullish_candle and long_trend_condition and prev_close_below_lower_band ? color.new(color.orange, 95) : na, title="Long Rejected by Prev Close")
bgcolor(short_wick_condition and short_body_condition and short_wick_percent_condition and short_bearish_candle and short_trend_condition and prev_close_above_upper_band ? color.new(color.orange, 95) : na, title="Short Rejected by Prev Close")

// Detailed debugging for failed conditions
long_all_conditions_except_prev = long_wick_condition and long_body_condition and long_wick_percent_condition and long_bullish_candle and long_trend_condition and long_close_above_bands
bgcolor(long_all_conditions_except_prev and prev_close_below_lower_band ? color.new(color.purple, 90) : na, title="Long Failed: Prev Close Below Band")
bgcolor(long_wick_condition and not long_body_condition ? color.new(color.yellow, 90) : na, title="Long Failed: Body Too Small")
bgcolor(long_wick_condition and long_body_condition and not long_wick_percent_condition ? color.new(color.blue, 90) : na, title="Long Failed: Upper Wick Too Big")
bgcolor(long_wick_condition and long_body_condition and long_wick_percent_condition and not long_bullish_candle ? color.new(color.gray, 90) : na, title="Long Failed: Not Bullish Candle")
bgcolor(long_wick_condition and long_body_condition and long_wick_percent_condition and long_bullish_candle and ema_bullish and not ema_bullish_consistent ? color.new(color.fuchsia, 90) : na, title="Long Failed: Trend Not Consistent")
bgcolor(long_wick_condition and long_body_condition and long_wick_percent_condition and long_bullish_candle and not ema_bullish ? color.new(color.maroon, 90) : na, title="Long Failed: EMA Trend Bearish")
bgcolor(long_wick_condition and long_body_condition and long_wick_percent_condition and long_bullish_candle and long_trend_condition and not long_close_above_bands ? color.new(color.lime, 90) : na, title="Long Failed: Close Not Above Bands")

// Similar debugging for shorts
short_all_conditions_except_prev = short_wick_condition and short_body_condition and short_wick_percent_condition and short_bearish_candle and short_trend_condition and short_close_below_bands
bgcolor(short_all_conditions_except_prev and prev_close_above_upper_band ? color.new(color.purple, 90) : na, title="Short Failed: Prev Close Above Band")
bgcolor(short_wick_condition and short_body_condition and short_wick_percent_condition and short_bearish_candle and short_trend_condition and not short_close_below_bands ? color.new(color.aqua, 90) : na, title="Short Failed: Close Not Below Bands")

// Enhanced table for debugging
if barstate.islast
    var table debug_table = table.new(position.top_right, 2, 19, bgcolor=color.white, border_width=1)
    table.cell(debug_table, 0, 0, "Condition", text_color=color.black, bgcolor=color.gray)
    table.cell(debug_table, 1, 0, "Value", text_color=color.black, bgcolor=color.gray)
    table.cell(debug_table, 0, 1, "Body Size", text_color=color.black)
    table.cell(debug_table, 1, 1, str.tostring(body_size, "#.##"), text_color=color.black)
    table.cell(debug_table, 0, 2, "Upper Wick", text_color=color.black)
    table.cell(debug_table, 1, 2, str.tostring(upper_wick, "#.##"), text_color=color.black)
    table.cell(debug_table, 0, 3, "Lower Wick", text_color=color.black)
    table.cell(debug_table, 1, 3, str.tostring(lower_wick, "#.##"), text_color=color.black)
    table.cell(debug_table, 0, 4, "Upper Wick %", text_color=color.black)
    table.cell(debug_table, 1, 4, str.tostring(upper_wick_percent, "#.##") + "%", text_color=color.black)
    table.cell(debug_table, 0, 5, "Lower Wick %", text_color=color.black)
    table.cell(debug_table, 1, 5, str.tostring(lower_wick_percent, "#.##") + "%", text_color=color.black)
    table.cell(debug_table, 0, 6, "EMA Upper", text_color=color.black)
    table.cell(debug_table, 1, 6, str.tostring(ema_upper, "#.##"), text_color=color.black)
    table.cell(debug_table, 0, 7, "EMA Lower", text_color=color.black)
    table.cell(debug_table, 1, 7, str.tostring(ema_lower, "#.##"), text_color=color.black)
    table.cell(debug_table, 0, 8, "R:R Ratio", text_color=color.black)
    table.cell(debug_table, 1, 8, str.tostring(risk_reward_ratio, "#.##") + "R", text_color=color.black)
    table.cell(debug_table, 0, 9, "Position", text_color=color.black)
    table.cell(debug_table, 1, 9, strategy.position_size > 0 ? "LONG" : strategy.position_size < 0 ? "SHORT" : "NONE", text_color=color.black)
    // NEW DEBUG INFO
    table.cell(debug_table, 0, 10, "Prev Close", text_color=color.black)
    table.cell(debug_table, 1, 10, str.tostring(close[1], "#.##"), text_color=color.black)
    table.cell(debug_table, 0, 11, "Prev Above Upper", text_color=color.black)
    table.cell(debug_table, 1, 11, prev_close_above_upper_band ? "YES" : "NO", text_color=color.black)
    table.cell(debug_table, 0, 12, "Prev Below Lower", text_color=color.black)
    table.cell(debug_table, 1, 12, prev_close_below_lower_band ? "YES" : "NO", text_color=color.black)
    table.cell(debug_table, 0, 13, "Prev Within Bands", text_color=color.black)
    table.cell(debug_table, 1, 13, prev_close_within_bands ? "YES" : "NO", text_color=color.black)
    // NEW: Trend consistency info
    table.cell(debug_table, 0, 14, "Bullish Consistent", text_color=color.black)
    table.cell(debug_table, 1, 14, ema_bullish_consistent ? "YES" : "NO", text_color=color.black)
    table.cell(debug_table, 0, 15, "Bearish Consistent", text_color=color.black)
    table.cell(debug_table, 1, 15, ema_bearish_consistent ? "YES" : "NO", text_color=color.black)
    table.cell(debug_table, 0, 16, "Consistency Bars", text_color=color.black)
    table.cell(debug_table, 1, 16, str.tostring(trend_consistency_bars), text_color=color.black)
    // NEW: Close position relative to bands
    table.cell(debug_table, 0, 17, "Close Above Upper", text_color=color.black)
    table.cell(debug_table, 1, 17, close > ema_upper ? "YES" : "NO", text_color=color.black)
    table.cell(debug_table, 0, 18, "Close Below Lower", text_color=color.black)
    table.cell(debug_table, 1, 18, close < ema_lower ? "YES" : "NO", text_color=color.black)