Williams %R은 손절매 및 손절매 전략을 동적으로 조정합니다.

EMA TP SL
생성 날짜: 2024-06-07 15:52:55 마지막으로 수정됨: 2024-06-07 15:52:55
복사: 10 클릭수: 783
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

Williams %R은 손절매 및 손절매 전략을 동적으로 조정합니다.

개요

이 전략은 윌리엄스 %R 지표에 기반을 두고 있으며, 동적으로 스톱로스 레벨을 조정하여 거래 성능을 최적화한다. 윌리엄스 %R가 오버셀 영역을 통과할 때 구매 신호를 발생시키고 오버셀 영역을 통과할 때 판매 신호를 발생시킨다. 지수 이동 평균 (EMA) 을 사용하면서 Williams %R의 수치를 평형화하여 잡음을 줄인다. 이 전략은 지표 주기와 스톱로스 레벨 (TP/SL) 을 포함한 유연한 파라미터 설정을 제공하며, 거래 시간 및 거래 방향의 선택은 다른 시장 환경과 거래자의 선호도에 적합하다.

전략 원칙

  1. 주어진 주기에서의 Williams %R 지수값을 계산한다.
  2. Williams %R의 지수 이동 평균을 계산한다.
  3. 윌리엄스 %R이 아래에서 위쪽으로 80 레벨을 통과하면 구매 신호가 발생하고, 위쪽에서 아래로 20 레벨을 통과하면 판매 신호가 발생한다.
  4. 구매 후, 스톱/스트로프 레벨을 설정하여 스톱/스트로프 가격에 도달하거나 Williams %R 역전 신호를 유발할 때까지 포지션을 청산하십시오.
  5. 팔린 후, 스톱과 스톱로스 레벨을 설정하고, 스톱/스톱로스 가격이나 윌리엄스 %R 반향 신호가 발동될 때까지 포지션을 청산한다.
  6. 지정된 시간 범위 (예: 9: 00-11: 00) 에서 거래하고 (예: 전 X 분부터 후 Y 분까지) 전체 지점 근처에서 거래하는지 여부를 선택할 수 있습니다.
  7. 거래방향을 선택할 수 있습니다. 그냥 더하고, 그냥 공백하거나 양방향 거래.

우위 분석

  1. 동적 스톱 로즈: 사용자의 설정에 따라 동적으로 스톱 로즈 수준을 조정하여 수익을 더 잘 보호하고 위험을 제어할 수 있습니다.
  2. 유연한 변수: 사용자는 자신의 선호에 따라 다양한 변수를 설정할 수 있습니다. 예를 들어, 지표 주기, 스톱 스톱 손실 수준, 거래 시간 등.
  3. 평형 지표: EMA 평형 윌리엄스 %R 값을 도입하여 지표 소음을 효과적으로 줄이고 신호 신뢰성을 향상시킬 수 있다.
  4. 거래 시간을 제한: 특정 시간 범위에서 거래할 수 있으며, 시장의 변동성이 큰 시기를 피하고 위험을 줄일 수 있다.
  5. 사용자 정의 거래 방향: 시장의 추세와 개인의 판단에 따라, 그냥 더하고, 그냥 공백 또는 양방향 거래를 선택할 수 있습니다.

위험 분석

  1. 변수 설정이 부적절하다. 만약 스톱스트로드 설정이 너무 느슨하거나 너무 엄격하다면, 이익 손실이나 빈번한 스톱스트로드를 초래할 수 있다.
  2. 트렌드 인식 오류: 윌리엄스 %R 지표는 흔들리는 시장에서 제대로 작동하지 않아 잘못된 신호가 발생할 수 있다.
  3. 시간 제한의 효과는 제한적입니다. 거래 시간을 제한하면 전략이 좋은 거래 기회를 놓칠 수 있습니다.
  4. 과도한 최적화: 과도한 최적화 매개 변수는 전략이 미래의 실제 거래에서 좋지 않은 결과를 초래할 수 있다.

최적화 방향

  1. 트렌드 지표, 변동률 지표 등과 결합하여 신호 확인의 정확도를 높인다.
  2. 동적 파라미터 최적화: 시장 상황에 따라 실시간으로 파라미터를 조정합니다. 예를 들어, 트렌드 시장과 흔들림 시장에서 다른 파라미터 설정을 사용합니다.
  3. 더 나은 상쇄 손실 방법: 추적 상쇄, 부분 상쇄와 같은 방법을 적용하여 수익을 더 잘 보호하고 위험을 제어하십시오.
  4. 자금 관리에 참여: 계좌 잔액과 위험 선호도에 따라 각 거래의 포지션 크기를 동적으로 조정합니다.

요약하다

Williams %R 동적으로 조정하는 스톱스트로프 전략은 가격의 초과과 초과 상태를 간단하고 효과적으로 캡처하며, 다양한 시장 환경과 거래 스타일에 맞게 유연한 파라미터 설정을 제공합니다. 이 전략은 동적으로 조정하는 스톱스트로프 수준을 통해 위험을 더 잘 제어하고 이익을 보호 할 수 있습니다. 그러나 실제 응용에서는 파라미터 설정, 신호 확인, 거래 시간 선택과 같은 요소에 주의를 기울여야합니다. 전략의 안정성과 수익성을 더욱 향상시키기 위해.

전략 소스 코드
/*backtest
start: 2024-05-01 00:00:00
end: 2024-05-31 23:59:59
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Williams %R Strategy defined buy/sell criteria with TP / SL", overlay=true)

// User inputs for TP and SL levels
tp_level = input.int(defval=60, title="Take Profit (ticks)", minval=10, maxval=500, step=10)
sl_level = input.int(defval=60, title="Stop Loss (ticks)", minval=10, maxval=200, step=10)

// Williams %R calculation
length = input.int(defval=21, title="Length", minval=5, maxval=50, step=1)
willy = 100 * (close - ta.highest(length)) / (ta.highest(length) - ta.lowest(length))

// Exponential Moving Average (EMA) of Williams %R
ema_length = input.int(defval=13, title="EMA Length", minval=5, maxval=50, step=1)
ema_willy = ta.ema(willy, ema_length)

// User inputs for Williams %R thresholds
buy_threshold = -80
sell_threshold = -20

// User input to enable/disable specific trading hours
use_specific_hours = input.bool(defval=false, title="Use Specific Trading Hours")
start_hour = input(defval=timestamp("0000-01-01 09:00:00"), title="Start Hour")
end_hour = input(defval=timestamp("0000-01-01 11:00:00"), title="End Hour")

// User input to choose trade direction
trade_direction = input.string(defval="Both", title="Trade Direction", options=["Buy Only", "Sell Only", "Both"])

// User input to enable/disable "Minutes Before" and "Minutes After" options
enable_minutes_before_after = input.bool(defval=true, title="Enable Minutes Before/After Options")
minutes_before = enable_minutes_before_after ? input.int(defval=10, title="Minutes Before the Top of the Hour", minval=0, maxval=59, step=1) : 0
minutes_after = enable_minutes_before_after ? input.int(defval=10, title="Minutes After the Top of the Hour", minval=0, maxval=59, step=1) : 0

// Condition to check if the current minute is within the user-defined time window around the top of the hour
is_top_of_hour_range = (minute(time) >= (60 - minutes_before) and minute(time) <= 59) or (minute(time) >= 0 and minute(time) <= minutes_after)

// Condition to check if the current time is within the user-defined specific trading hours
in_specific_hours = true
if use_specific_hours
    in_specific_hours := (hour(time) * 60 + minute(time)) >= (hour(start_hour) * 60 + minute(start_hour)) and (hour(time) * 60 + minute(time)) <= (hour(end_hour) * 60 + minute(end_hour))

// Buy and Sell conditions with time-based restriction
buy_condition = ta.crossover(willy, buy_threshold) and is_top_of_hour_range and in_specific_hours
sell_condition = ta.crossunder(willy, sell_threshold) and is_top_of_hour_range and in_specific_hours

// Strategy entry and exit with TP and SL
if (trade_direction == "Buy Only" or trade_direction == "Both") and buy_condition
    strategy.entry("Buy", strategy.long)

if (trade_direction == "Sell Only" or trade_direction == "Both") and sell_condition
    strategy.entry("Sell", strategy.short)

// If a buy entry was taken, allow the trade to be closed after reaching TP and SL or if conditions for a sell entry are true
if (strategy.opentrades > 0)
    strategy.exit("TP/SL", profit=tp_level, loss=sl_level)

// Plot Williams %R and thresholds for visualization
hline(-20, "Upper Band", color=color.red)
hline(-80, "Lower Band", color=color.green)
plot(willy, title="%R", color=color.yellow, linewidth=2)
plot(ema_willy, title="EMA", color=color.aqua, linewidth=2)