추세선 돌파 헌터

EMA Pivot BREAKOUT TRENDLINE
생성 날짜: 2025-10-29 15:47:08 마지막으로 수정됨: 2025-10-29 15:47:08
복사: 0 클릭수: 248
avatar of ianzeng123 ianzeng123
2
집중하다
319
수행원

추세선 돌파 헌터 추세선 돌파 헌터

200일 EMA+ 동적 트렌드 라인, 이 조합은 권투 시장의 아픔을 보여줍니다.

이 전략은 200일 EMA를 통해 큰 트렌드 방향을 판단하고, 그 다음에는 중요한 저항/지원 지점에서 돌파 기회를 찾습니다.핵심 논리는 간단하고 거칠습니다. 황소 시장은 하향 트렌드 라인을 뚫기 위해 더 많은 것을 하고, 곰 시장은 상승 트렌드 라인을 뚫기 위해 더 많은 것을 합니다.

데이터 이야기: 전략은 5+5의 축점 검사를 사용하여 신호가 재배치되지 않도록 한다. 20주기 회전 창은 역사 데이터 범위를 제한하고 과도한 일치를 피한다. 이것은 미학이 아니라 순수한 가격 행동 분석이다.

1: 3의 위험과 보상보다 디자인, 수학은 당신의 편에 서 기대

스톱 손실은 앞 K 선의 최고/최저 지점에 설정되어 있으며, 스톱 손실의 목표값은 스톱 손실 거리의 3배이다.이 말은 30%의 승률이 있더라도 장기적으로 수익을 낼 수 있다는 뜻입니다.

구체적 실행: 다중 헤드 브레이크 후, 중지 = 이전 낮은, 중지 = 입시 가격 + 3 × ((입시 가격 - 이전 낮은) 텅 비어 . 위험 제어 기본 설정은 계정 자금의 1%로, 조정 가능한 범위는 0.1%-10% . 무심한 포지션 전략보다 100 배 안전하다 .

주관적인 선에 작별인사를 하는 축점 검출기구

전통적인 기술 분석의 가장 큰 문제는 너무 많은 주관성이 있다는 것입니다. 이 전략은 알고리즘이 자동으로 중요한 높고 낮은 점을 식별하는 것입니다.

  • 왼쪽 5 K선 + 오른쪽 5 K선 확인 축점
  • 20주기 안에 가장 가까운 두 개의 유효 축점만 연결합니다.
  • 불시장 편향: 하락한 고점을 연결하여 하락하는 트렌드 라인을 형성
  • 곰 시장 편향: 연결된 낮은 지점들이 상승 동향선을 형성한다

그리고 그 결과, 완전히 객관적이고, 다시 그리지 않고, 재현할 수 있습니다. 여러분의 손으로 그린 그림보다 1,000배 더 정확합니다.

듀얼 필터링 메커니즘, 가짜 침입 확률을 크게 줄입니다.

1층 필터: EMA 추세 편향 판단가격이 200일 EMA 위에만 다중 돌파를 하고, 아래에만 하위 돌파를 한다. 이 트릭은 80%의 역동적인 거래를 직접 필터링한다.

두 번째 필터: 트렌드 라인의 유효성 검증.시스템 요구에 따라 트렌드 라인을 그리기 위해서는 두 개의 합격한 축점을 찾아야 한다. 충분한 데이터가 뒷받침되지 않는 “트렌드 라인”은 직접 무시한다.

실전 효과: 흔들리는 도시에서 무효 신호를 크게 줄이고, 트렌드 도시에서 돌파 기회를 정확하게 잡는다.

역동적인 포지션 관리, 수익보다 위험 통제

두 가지 포지션 모델이 있습니다.

  1. 위험 비율 모드매 거래의 위험을 고정하기 위해 스톱로즈 거리 변화에 따라 포지션을 조정합니다.
  2. 고정 계약 모드경험있는 거래자에게 적합합니다. 포지션은 고정되어 있지만 위험은 상쇄 거리 변화에 따라 변합니다.

수식: 포지션 크기 = (계좌 자금 × 위험 비율) ÷ 스톱 거리

이 포지션 관리는 시장에서 90%의 전략보다 과학적입니다. 연속적인 손실이 있을 때 자동으로 포지션을 줄이고, 수익이 있을 때 점차적으로 포지션을 올립니다.

전략적 한계, 나는 숨기지 않을 것이다.

이 전략은 만능이 아니기 때문에, 다음과 같은 경우에도 효과가 좋지 않습니다:

  • 수평이 흔들리는 시장: 빈번한 가짜 해킹으로 거래 비용이 증가합니다.
  • 극심한 변동성엑소포트 검사는 급격한 변화에 뒤쳐질 수 있습니다.
  • 낮은 유동성 품종가격 상승으로 인해 손해 차단 효과가 떨어질 수 있습니다.

변수 감수성 경고:

  • 축점 민감도가 너무 낮게 설정되면 노이즈 신호가 발생한다.
  • 트렌드 라인을 찾을 수 없는 매우 짧은 회귀 창
  • 2% 이상의 위험은 신중하게 고려해야 합니다.

실전 배치 제안, 이론보다 착륙 가능함

가장 적합한 시나리오:

  • 중·장기 추세에 대한 명확한 주류 품종
  • 일선 또는 4시간 차트
  • 시장 환경은 다소 변동적이지만 너무 미친 것은 아닙니다.

다음 항목을 참고하십시오:

  • 신입생들은 0.5%-1%의 위험을 통제할 것을 제안합니다.
  • 축점 민감도는 품종 특성에 따라 조정
  • 회귀 창은 시장 주기에 따라 적절히 연장될 수 있습니다.

위험 팁: 역사적인 회전은 미래의 수익을 의미하지 않으며, 모든 전략에는 연속적인 손실이 존재할 수 있다. 먼저 시뮬레이션 환경 테스트를 통해 전략 논리를 이해한 후 실장에 투입하는 것이 좋습니다. 시장에는 위험성이 있으며 거래는 신중해야합니다.

전략 소스 코드
/*backtest
start: 2024-10-29 00:00:00
end: 2025-10-27 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"SOL_USDT"}]
*/

//@version=5
strategy("Trendline Breakout Strategy", overlay=true, max_lines_count=500, max_labels_count=500, max_boxes_count=500)

// === INPUTS ===
ema_len = input.int(200, "EMA Length", minval=1, group="Trend Detection")
src = input.source(close, "EMA Source", group="Trend Detection")
lookback = input.int(20, "Lookback Window for Pivots (bars)", minval=5, group="Trend Detection")
left_bars = input.int(5, "Pivot Left Sensitivity (bars)", minval=1, group="Trend Detection")
right_bars = input.int(5, "Pivot Right Sensitivity (bars)", minval=1, group="Trend Detection")

qty_mode = input.string("Risk Percent", "Position Sizing Mode", options=["Risk Percent", "Fixed Contracts"], group="Position Sizing")
risk_pct = input.float(1.0, "Risk % of Equity", minval=0.1, maxval=10.0, step=0.1, group="Position Sizing")
fixed_size = input.int(1, "Fixed Contract Size", minval=1, group="Position Sizing")

show_trendline = input.bool(true, "Show Trendline", group="Visuals")
enable_prints = input.bool(true, "Enable Info Table", group="Visuals")

// === CORE LOGIC ===
// EMA Calculation
ema = ta.ema(src, ema_len)
bias_bull = close > ema
bias_bear = close < ema

// Pivot Detection (confirmed, no repainting)
ph = ta.pivothigh(high, left_bars, right_bars)
pl = ta.pivotlow(low, left_bars, right_bars)

// Arrays to store historical pivots (limited to prevent memory issues)
var array<float> ph_values = array.new<float>()
var array<int> ph_bars = array.new<int>()
var array<float> pl_values = array.new<float>()
var array<int> pl_bars = array.new<int>()

// Update pivot highs array
if not na(ph)
    array.push(ph_values, ph)
    array.push(ph_bars, bar_index - right_bars)
    if array.size(ph_values) > 100
        array.shift(ph_values)
        array.shift(ph_bars)

// Update pivot lows array
if not na(pl)
    array.push(pl_values, pl)
    array.push(pl_bars, bar_index - right_bars)
    if array.size(pl_values) > 100
        array.shift(pl_values)
        array.shift(pl_bars)

// Function to find two most recent pivots within lookback
get_two_pivots(arr_vals, arr_bars) =>
    int p1_bar = na
    float p1_val = na
    int p2_bar = na
    float p2_val = na
    for j = array.size(arr_bars) - 1 to 0
        int pb = array.get(arr_bars, j)
        if pb < bar_index - lookback
            break
        if na(p1_bar)
            p1_bar := pb
            p1_val := array.get(arr_vals, j)
        else if na(p2_bar)
            p2_bar := pb
            p2_val := array.get(arr_vals, j)
            break  // Only need the two most recent
    [p1_bar, p1_val, p2_bar, p2_val]

// Get pivots for bullish bias
int p1h_bar = na
float p1h_val = na
int p2h_bar = na
float p2h_val = na
if bias_bull
    [tmp1, tmp2, tmp3, tmp4] = get_two_pivots(ph_values, ph_bars)
    p1h_bar := tmp1
    p1h_val := tmp2
    p2h_bar := tmp3
    p2h_val := tmp4

// Get pivots for bearish bias
int p1l_bar = na
float p1l_val = na
int p2l_bar = na
float p2l_val = na
if bias_bear
    [tmp5, tmp6, tmp7, tmp8] = get_two_pivots(pl_values, pl_bars)
    p1l_bar := tmp5
    p1l_val := tmp6
    p2l_bar := tmp7
    p2l_val := tmp8

// Validate trendlines
bull_valid = bias_bull and not na(p1h_bar) and not na(p2h_bar) and p2h_bar < p1h_bar and p2h_val > p1h_val  // Descending: older high > newer high
bear_valid = bias_bear and not na(p1l_bar) and not na(p2l_bar) and p2l_bar < p1l_bar and p2l_val < p1l_val  // Ascending: older low < newer low

// Calculate trendline Y at current bar
float bull_y = na
if bull_valid and p1h_bar != p2h_bar
    float slope = (p1h_val - p2h_val) / (p1h_bar - p2h_bar)
    bull_y := p1h_val + slope * (bar_index - p1h_bar)

float bear_y = na
if bear_valid and p1l_bar != p2l_bar
    float slope = (p1l_val - p2l_val) / (p1l_bar - p2l_bar)
    bear_y := p1l_val + slope * (bar_index - p1l_bar)

// Breakout conditions (confirmed on close, no repainting)
long_breakout = bull_valid and ta.crossover(close, bull_y)
short_breakout = bear_valid and ta.crossunder(close, bear_y)

// === POSITION SIZING AND ENTRIES ===
var float entry_price = na
var float sl_price = na
var float tp_price = na

if long_breakout and strategy.position_size == 0
    entry_price := close
    sl_price := low[1]
    float risk = entry_price - sl_price
    if risk > 0
        strategy.entry("Long", strategy.long, qty = qty_mode == "Fixed Contracts" ? float(fixed_size) : (strategy.equity * risk_pct / 100) / risk)
        tp_price := sl_price + 3 * risk
        strategy.exit("Long Exit", "Long", stop=sl_price, limit=tp_price)

if short_breakout and strategy.position_size == 0
    entry_price := close
    sl_price := high[1]
    float risk = sl_price - entry_price
    if risk > 0
        strategy.entry("Short", strategy.short, qty = qty_mode == "Fixed Contracts" ? float(fixed_size) : (strategy.equity * risk_pct / 100) / risk)
        tp_price := sl_price - 3 * risk
        strategy.exit("Short Exit", "Short", stop=sl_price, limit=tp_price)

// === VISUAL LABELS ===
if long_breakout
    label.new(bar_index, low, text="Long\nEntry: " + str.tostring(entry_price, "#.##") + "\nSL: " + str.tostring(sl_price, "#.##") + "\nTP: " + str.tostring(tp_price, "#.##") + "\nReason: Trendline Breakout", 
              style=label.style_label_up, color=color.green, textcolor=color.white, size=size.small)

if short_breakout
    label.new(bar_index, high, text="Short\nEntry: " + str.tostring(entry_price, "#.##") + "\nSL: " + str.tostring(sl_price, "#.##") + "\nTP: " + str.tostring(tp_price, "#.##") + "\nReason: Trendline Breakout", 
              style=label.style_label_down, color=color.red, textcolor=color.white, size=size.small)

// === INFO TABLE ===
if enable_prints and barstate.islast
    var table info_table = table.new(position.top_right, 2, 4, bgcolor=color.white, border_width=1)
    table.cell(info_table, 0, 0, "Bias", text_color=color.black, bgcolor=color.gray)
    table.cell(info_table, 1, 0, bias_bull ? "Bull" : "Bear", text_color=bias_bull ? color.green : color.red)
    table.cell(info_table, 0, 1, "Trendline", text_color=color.black, bgcolor=color.gray)
    table.cell(info_table, 1, 1, bull_valid or bear_valid ? (bull_valid ? "Descending" : "Ascending") : "None", text_color=color.black)
    table.cell(info_table, 0, 2, "Position", text_color=color.black, bgcolor=color.gray)
    table.cell(info_table, 1, 2, strategy.position_size > 0 ? "Long" : strategy.position_size < 0 ? "Short" : "Flat", text_color=color.black)
    table.cell(info_table, 0, 3, "P&L", text_color=color.black, bgcolor=color.gray)
    table.cell(info_table, 1, 3, str.tostring(strategy.netprofit, "#.##"), text_color=strategy.netprofit >= 0 ? color.green : color.red)

// === EMA PLOT ===
plot(ema, "EMA", color=color.blue, linewidth=2)

// === ALERTS ===
alertcondition(long_breakout, title="Long Entry Alert", message="Bullish bias: Price broke above descending trendline. Enter Long.")
alertcondition(short_breakout, title="Short Entry Alert", message="Bearish bias: Price broke below ascending trendline. Enter Short.")
alertcondition(strategy.position_size[1] != 0 and strategy.position_size == 0, title="Exit Alert", message="Position closed at SL or TP.")

// === COMMENTS AND LIMITATIONS ===
// Comments:
// - Pivots are detected using ta.pivothigh/low with user-defined sensitivity to identify "significant" swings.
// - Trendlines are redrawn only when bias is active and valid (two qualifying pivots found).
// - Entries/exits use strategy.entry/exit for backtesting; position size closes opposite trades automatically.
// - No repainting: All pivots require 'right_bars' confirmation; breakouts checked on bar close.
// - Variable names: Descriptive (e.g., p1h_bar for most recent pivot high bar).
//
// Limitations:
// - Trendline uses the two *most recent* pivot highs/lows within lookback; may not always connect the absolute highest/lowest if more pivots exist.
// - Pivot sensitivity (left/right bars) approximates "significant" swings—too low may include noise, too high may miss turns.
// - Only one trendline per bias; does not handle multiple parallel lines or complex channels.
// - Position sizing assumes equity-based risk; in "Fixed Contracts" mode, risk % varies with SL distance.
// - Lookback window limits historical context—short windows may yield few/no valid trendlines on low-volatility periods.
// - Strategy does not filter for overall trend strength beyond EMA bias; add filters (e.g., volume) for production use.