이동 평균선과 윌리엄스 지표를 기반으로 한 일일 전략


생성 날짜: 2024-01-29 14:35:48 마지막으로 수정됨: 2024-01-29 14:35:48
복사: 1 클릭수: 639
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

이동 평균선과 윌리엄스 지표를 기반으로 한 일일 전략

개요

이 전략은 평균선, ATR 지표와 윌리엄 지표를 사용하여 GBP/JPY의 외환 품종을 대상으로 일선 수준의 거래를합니다. 전략은 우선 평균선을 통해 가격 추세와 가능한 반전점을 판단하고, 윌리엄 지표를 사용하여 거래 신호를 추가로 확인하고, ATR 지표를 사용하여 중지 손실과 거래량을 계산합니다.

전략 원칙

  1. 20일선의 평균선 ((기초선) 을 사용하여 가격의 전반적인 경향을 판단합니다. 가격은 평균선 아래에서 구매 신호로 니다. 평균선 위쪽에서 판매 신호로 니다.
  2. 윌리엄 지표는 가격 반전을 확인하기 위해 사용된다. 지표 상위 -35이 구매를 확인하고, 하위 -70이 판매를 확인한다.
  3. ATR 지표는 지난 2 일 동안의 평균 변동 범위를 계산한다. 이 수치는 스톱로스 거리로 설정된 계수를 곱한다.
  4. 계정 이득의 50%에 따라 위험 통제. 거래량은 중지 거리 및 위험 비율에 따라 계산
  5. 긴 포지션에 진입한 후, 정지점은 가격 낮은 점으로 정지 거리를 니다. 정지점은 진입점으로 100점을 더한다. 출구 신호를 추가로 확인하기 위해 출구 논리를 사용합니다.
  6. 짧은 위치로 들어간 후, 중지 및 정지 동시. 출구 논리는 출구 신호를 추가로 확인하는 데 사용됩니다.

우위 분석

  1. 종합적으로 평균선 판단 트렌드와 지표 확인을 사용하여 가짜 돌파구로 인한 손실을 효과적으로 필터링 할 수 있습니다.
  2. ATR 다이내믹 스톱로스는 시장의 변동에 따라 합리적인 스톱로스 거리를 설정할 수 있다.
  3. 리스크 제어 및 동적 거래량 계산은 단편 손실을 최소화합니다.
  4. 출구 논리 (Exiting logic) 는 평형 판단과 결합하여 출구 시기를 추가로 확인하고 조기 정전을 방지합니다.

위험 분석

  1. 평균선 판단이 잘못된 신호를 생성할 확률이 높기 때문에 지표의 추가 확인이 필요합니다.
  2. 지표 자체는 잘못된 신호를 내보이며 손실을 완전히 피할 수 없습니다.
  3. 이 전략은 트렌드 품종에 더 적합하며, 범위 변동 품종에는 덜 효과적일 수 있습니다.
  4. 리스크 컨트롤의 비율이 잘못 설정되면 전략적 수익에도 영향을 미칠 수 있습니다.

평행 주기 조정, 더 많은 지표의 조합, 또는 인공 개입 거래와 같은 방법을 통해 더 많은 최적화와 개선이 가능합니다.

요약하다

이 전략은 트렌드 판단과 지표 필터링을 결합하여 GBP/JPY 일계 레벨 거래에 대한 방법을 설계한다. 동적 스톱, 위험 제어와 같은 수단을 사용하여 거래 위험을 제어한다. 최적화 공간은 넓고, 매개 변수 조정과 방법 조합을 통해 전략 효과를 더 향상시킬 수 있다.

전략 소스 코드
/*backtest
start: 2023-12-29 00:00:00
end: 2024-01-28 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy("GBPJPY DAILY FX",initial_capital = 1000,currency="USD", overlay=true)

UseHAcandles    = input(false, title="Use Heikin Ashi Candles in Algo Calculations")
//
// === /INPUTS ===

// === BASE FUNCTIONS ===

haClose = UseHAcandles ? security(heikinashi(syminfo.tickerid), timeframe.period, close) : close
haOpen  = UseHAcandles ? security(heikinashi(syminfo.tickerid), timeframe.period, open) : open
haHigh  = UseHAcandles ? security(heikinashi(syminfo.tickerid), timeframe.period, high) : high
haLow   = UseHAcandles ? security(heikinashi(syminfo.tickerid), timeframe.period, low) : low

//INDICATOR---------------------------------------------------------------------    
    //Average True Range (1. RISK)
atr_period = 2
atr = atr(atr_period)



    //Ichimoku Cloud - Kijun Sen (2. BASELINE)
ks_period = 20
kijun_sen = (highest(haHigh,ks_period) + lowest(haLow,ks_period))/2
base_long = haOpen < kijun_sen and haClose > kijun_sen
base_short = haOpen > kijun_sen and haClose < kijun_sen

    //Williams Percent Range (3. Confirmation#1)
use_wpr = true
wpr_len = 4
wpr = -100*(highest(haHigh,wpr_len) - haClose)/(highest(haHigh,wpr_len) - lowest(haLow,wpr_len))
wpr_up = -35
wpr_low = -70
conf1_long = wpr >= wpr_up
conf1_short = wpr <= wpr_low
if(use_wpr == false)
    conf1_long := true
    conf1_short := true
//TRADE LOGIC-------------------------------------------------------------------
    //Long Entry
    //if -> WPR crosses below -39 AND MACD line is less than signal line
l_en = base_long and conf1_long
    //Long Exit
    //if -> WPR crosses above -14
l_ex = haClose < kijun_sen
    //Short Entry
    //if -> WPR crosses above -39 AND MACD line is greater than signal line
s_en = base_short and conf1_short
    //Short Exit
    //if -> WPR crosses under -14
s_ex = haClose > kijun_sen
    
strategy.initial_capital = 50000
//MONEY MANAGEMENT--------------------------------------------------------------
balance = strategy.netprofit + strategy.initial_capital //current balance
floating = strategy.openprofit          //floating profit/loss
isTwoDigit = input(true,"Is this a 2 digit pair? (JPY, XAU, XPD...")
risk = input(50,"Risk %")/100           //risk % per trade
equity_protector = input(30,"Equity Protection %")/100  //equity protection %
stop = atr*100000*input(1,"Average True Range multiplier")    //Stop level
if(isTwoDigit)
    stop := stop/100
target = input(100, "Target TP in Points")  //TP level
    //Calculate current DD and determine if stopout is necessary
equity_stopout = false
if(floating<0 and abs(floating/balance)>equity_protector)
    equity_stopout := true
    
    //Calculate the size of the next trade
temp01 = balance * risk     //Risk in USD
temp02 = temp01/stop        //Risk in lots
temp03 = temp02*100000      //Convert to contracts
size = temp03 - temp03%1000 //Normalize to 1000s (Trade size)
if(size < 1)
    size := 1            //Set min. lot size

//TRADE EXECUTION---------------------------------------------------------------
strategy.close_all(equity_stopout)      //Close all trades w/equity protector
is_open = strategy.opentrades > 0

fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
fromYear = input(defval = 2000, title = "From Year", minval = 1970)
 //monday and session 
// To Date Inputs
toDay = input(defval = 31, title = "To Day", minval = 1, maxval = 31)
toMonth = input(defval = 12, title = "To Month", minval = 1, maxval = 12)
toYear = input(defval = 2021, title = "To Year", minval = 1970)

startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)
finishDate = timestamp(toYear, toMonth, toDay, 00, 00)
time_cond = true

if(time_cond)
    strategy.entry("l_en",true,1,oca_name="a",when=l_en and not is_open)  //Long entry
    strategy.entry("s_en",false,1,oca_name="a",when=s_en and not is_open) //Short entry
    
    strategy.exit("S/L","l_en",loss=stop, profit=target)      //Long exit (stop loss)
    strategy.close("l_en",when=l_ex)            //Long exit (exit condition)
    strategy.exit("S/L","s_en",loss=stop, profit=target)      //Short exit (stop loss)
    strategy.close("s_en",when=s_ex)            //Short exit (exit condition)