트리플 이동 평균 크로스오버와 윌리엄스 지표 전략

저자:차오장, 날짜: 2023-09-28 10:58:16
태그:

전반적인 설명

이 전략은 세 개의 부드러운 이동 평균, 상대 강도 지수 (RSI) 및 윌리엄스 지표를 결합하여 가격 트렌드 방향을 식별하고 트렌드가 역전될 때 거래 기회를 찾습니다. 빠른, 중간 및 느린 이동 평균이 상향 (하향) 으로 정렬되면 길게 (단기) 가 RSI가 50 이상 (하하위) 이며 윌리엄스 신호가 나타납니다. 스톱 손실은 엔트리 가격의 특정 비율로 설정되며 엔트리 가격에서 유리한 방향으로 특정 비율로 이동하여 이익을 취합니다.

전략 논리

이 전략은 빠른, 중간 및 느린 MA를 포함한 다른 기간을 가진 세 개의 이동 평균을 사용합니다. 빠른 MA가 중간 MA를 넘을 때 상승 가격 추세를 신호합니다. 빠른 MA가 중간 MA를 넘을 때 하락 가격 추세를 신호합니다. 상승 추세 또는 하락 추세를 확인한 후 전략은 첫 번째 거래 기회를 기다리고 있습니다.

구체적으로, 가격이 상승 추세로 진입 한 후, 전략은 다음 다섯 가지 조건이 충족 될 때까지 기다립니다.

  1. 빠른, 중간, 느린 MAs는 모두 위쪽으로 향하고 있습니다.

  2. RSI는 50 이상입니다.

  3. 아래쪽 Williams 패턴이 나타납니다.

  4. 가격이 느린 MA를 넘습니다.

  5. 현재 위치가 없습니다.

가격이 하락 추세로 진입한 후, 전략은 하락하기 전에 다음 다섯 가지 조건이 충족될 때까지 기다립니다.

  1. 빠른, 중간, 느린 MAs는 모두 아래로 향하고 있습니다.

  2. RSI가 50보다 낮습니다.

  3. 위쪽 윌리엄스 패턴이 나타납니다.

  4. 가격이 느린 MA보다 낮아집니다.

  5. 현재 위치가 없습니다.

장기 또는 단위로 가다보면 전략은 입시 가격의 특정 비율로 스톱 로스를 설정하고, 입시 가격의 특정 비율로 수익을 취하는 목표를 설정합니다.

장점

  1. 여러 지표를 결합하여 엔트리를 확인하면 가짜 브레이크오프를 효과적으로 피할 수 있습니다. 트리플 MA는 트렌드 방향을 식별하고, 윌리엄스는 반전 신호를 감지하고, RSI는 범위 내의 가격 행동을 필터링하여 엔트리의 정확성을 공동으로 향상시킵니다.

  2. 스톱 로스 및 영업 취득을 설정하면 각 거래의 위험/이익을 조절할 수 있으며, 이기는 거래가 손실되는 거래를 초과하는 것을 보장합니다.

  3. 전략 논리는 명확하고 이해하기 쉽다. 매개 변수는 합리적으로 설정되어 있습니다. 그것은 다양한 수준의 거래자에게 적합합니다.

위험성

  1. 지표는 범위 제한 시장에서 잘못된 신호를 생성하여 불필요한 엔트리를 유발할 수 있습니다. RSI 매개 변수를 최적화하면 몇 가지 윙스를 필터링 할 수 있습니다.

  2. 빠른 및 중간 MA 크로스오버에는 잘못된 파열이있을 수 있습니다. 부피와 같은 다른 지표의 조합을 사용하는 것이 좋습니다.

  3. 만약 스톱 로스가 엔트리 가격에 너무 가깝다면, 그것은 조기 중단될 수 있습니다. 스톱 로스는 적절한 위치에 조정되어야 합니다.

  4. 만약 이윤은 입시 가격과 너무 멀어지면 타격을 받지 못할 수도 있습니다. 이윤은 또한 적절한 조정이 필요합니다.

최적화 방향

  1. 세 가지 MA와 RSI에 대한 다른 매개 변수 조합을 테스트합니다.

  2. 부피와 같은 다른 지표를 추가하여 부피가 급격히 증가하는지 확인합니다.

  3. 각기 다른 제품에 기초한 테스트 매개 변수

  4. 백테스트 결과를 기반으로 수익 곡선을 그리면 스톱 로스를 최적화하고 수익을 취합니다.

  5. 매개 변수를 최적화하기 전에 종이 거래를 시도해보세요.

결론

이 전략은 전반적으로 명확한 논리를 가지고 있으며, 지표의 조합으로 입점 및 출구 포지션을 통해 위험을 효과적으로 제어합니다. 매개 변수 최적화에 큰 여지가 있습니다. 다른 매개 변수 설정을 테스트함으로써이 전략은 안정적으로 수익성있는 양적 거래 전략이 될 수 있습니다. 그러나 어떤 전략도 손실을 완전히 피할 수 없습니다. 거래자는 거래 규율을 따라야합니다. 승리할 때 이익을 얻고 손실을 줄입니다.


/*backtest
start: 2023-08-28 00:00:00
end: 2023-09-27 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//This script is a combination of 3 smoothed moving averages, and RSI. When moving averages are aligned upward (downward) and RSI is above (below) 50 and a down (up) William fractal appears, it enters long (short) position. Exiting from long and short entries are defined by StopLoss and TargetProfit.

//@version=5

strategy(title="3SmmaCrossUp + Fractal + RSI", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, currency=currency.USD, commission_type=strategy.commission.percent, commission_value=0.03)

///////////////////////////////////////////////////////////////////////////////////////////////////////////////// inputs

// Global
src = input(close, title="Source")
stopLoss = input.float(defval = 0.1, title = "Stop Loss %", minval = 0, maxval=100, step = 0.1)
targetProfit = input.float(defval = 0.4, title = "Target Profit %", minval = 0, maxval=100, step = 0.1)

// Smooth Moving Average
fastSmmaLen = input.int(21, minval=1, title="Fast Length", group = "Smooth Moving Average")
midSmmaLen = input.int(50, minval=1, title="Mid Length",group = "Smooth Moving Average")
slowSmmaLen = input.int(200, minval=1, title="Slow Length",group = "Smooth Moving Average")

// RSI
rsiLen = input.int(defval=14, title="length", minval=1, maxval=1000, step=1, group="RSI")

// Fractals
n = input.int(title="Periods", defval=2, minval=2, group = "Fractals")

///////////////////////////////////////////////////////////////////////////////////////////////////////////////// initialization

var waitingFirstTradeInUpwardTrend = false
var waitingFirstTradeInDownwardTrend = false

///////////////////////////////////////////////////////////////////////////////////////////////////////////////// functions

smma(ma, src, len) => 
    smma = 0.0
    smma := na(smma[1]) ? ma : (smma[1] * (len - 1) + src) / len
    smma
    
fractals(n, highs, lows) =>
    // UpFractal
    bool upflagDownFrontier = true
    bool upflagUpFrontier0 = true
    bool upflagUpFrontier1 = true
    bool upflagUpFrontier2 = true
    bool upflagUpFrontier3 = true
    bool upflagUpFrontier4 = true
    for i = 1 to n
        upflagDownFrontier := upflagDownFrontier and (highs[n-i] < highs[n])
        upflagUpFrontier0 := upflagUpFrontier0 and (highs[n+i] < highs[n])
        upflagUpFrontier1 := upflagUpFrontier1 and (highs[n+1] <= highs[n] and highs[n+i + 1] < highs[n])
        upflagUpFrontier2 := upflagUpFrontier2 and (highs[n+1] <= highs[n] and highs[n+2] <= highs[n] and highs[n+i + 2] < highs[n])
        upflagUpFrontier3 := upflagUpFrontier3 and (highs[n+1] <= highs[n] and highs[n+2] <= highs[n] and highs[n+3] <= highs[n] and highs[n+i + 3] < highs[n])
        upflagUpFrontier4 := upflagUpFrontier4 and (highs[n+1] <= highs[n] and highs[n+2] <= highs[n] and highs[n+3] <= highs[n] and highs[n+4] <= highs[n] and highs[n+i + 4] < highs[n])
    flagUpFrontier = upflagUpFrontier0 or upflagUpFrontier1 or upflagUpFrontier2 or upflagUpFrontier3 or upflagUpFrontier4
    
    upFractal = (upflagDownFrontier and flagUpFrontier)
    
    // downFractal
    bool downflagDownFrontier = true
    bool downflagUpFrontier0 = true
    bool downflagUpFrontier1 = true
    bool downflagUpFrontier2 = true
    bool downflagUpFrontier3 = true
    bool downflagUpFrontier4 = true
    
    for i = 1 to n
        downflagDownFrontier := downflagDownFrontier and (lows[n-i] > lows[n])
        downflagUpFrontier0 := downflagUpFrontier0 and (lows[n+i] > lows[n])
        downflagUpFrontier1 := downflagUpFrontier1 and (lows[n+1] >= lows[n] and lows[n+i + 1] > lows[n])
        downflagUpFrontier2 := downflagUpFrontier2 and (lows[n+1] >= lows[n] and lows[n+2] >= lows[n] and lows[n+i + 2] > lows[n])
        downflagUpFrontier3 := downflagUpFrontier3 and (lows[n+1] >= lows[n] and lows[n+2] >= lows[n] and lows[n+3] >= lows[n] and lows[n+i + 3] > lows[n])
        downflagUpFrontier4 := downflagUpFrontier4 and (lows[n+1] >= lows[n] and lows[n+2] >= lows[n] and lows[n+3] >= lows[n] and lows[n+4] >= lows[n] and lows[n+i + 4] > lows[n])
    flagDownFrontier = downflagUpFrontier0 or downflagUpFrontier1 or downflagUpFrontier2 or downflagUpFrontier3 or downflagUpFrontier4
    
    downFractal = (downflagDownFrontier and flagDownFrontier)
    [upFractal, downFractal]

///////////////////////////////////////////////////////////////////////////////////////////////////////////////// calcs

[upFractal, downFractal] = fractals(n, high, low)


rsiIsHigh = ta.rsi(src, rsiLen) >= 50 


slowMa = ta.sma(src, slowSmmaLen)
midMa = ta.sma(src, midSmmaLen)
fastMa = ta.sma(src, fastSmmaLen)

slowSmma = smma(slowMa ,src, slowSmmaLen)
midSmma = smma(midMa, src, midSmmaLen)
fastSmma = smma(fastMa, src, fastSmmaLen)

isFastSmmaUpward = ta.rising(fastSmma, 1)
isMidSmmaUpward = ta.rising(midSmma, 1)
isSlowSmmaUpward = ta.rising(slowSmma, 1)

isFastSmmaDownward = ta.falling(fastSmma, 1)
isMidSmmaDownward = ta.falling(midSmma, 1)
isSlowSmmaDownward = ta.falling(slowSmma, 1)

slowMovingAveragesAreUpward = isMidSmmaUpward and isSlowSmmaUpward
slowMovingAveragesAreDownward = isMidSmmaDownward and isSlowSmmaDownward

justEnteredUpwardTrend = ta.crossover(fastSmma, midSmma) ? true : false
justEnteredDownwardTrend = ta.crossunder(fastSmma, midSmma) ? true : false

waitingFirstTradeInUpwardTrend := justEnteredUpwardTrend == true ? true : (isFastSmmaDownward or isMidSmmaDownward or isSlowSmmaDownward ? false : waitingFirstTradeInUpwardTrend)
waitingFirstTradeInDownwardTrend := justEnteredDownwardTrend == true ? true : (isFastSmmaUpward or isMidSmmaUpward or isSlowSmmaUpward ? false : waitingFirstTradeInDownwardTrend)

priceCrossedOverSlowMa = ta.crossover(close, slowSmma)
priceCrossedUnderSlowMa = ta.crossunder(close, slowSmma)

enterLongCondition = barstate.isconfirmed and low > fastSmma and rsiIsHigh and (downFractal or priceCrossedOverSlowMa) and waitingFirstTradeInUpwardTrend and strategy.position_size == 0

enterShortCondition = barstate.isconfirmed and high < fastSmma and (not rsiIsHigh) and (upFractal or priceCrossedUnderSlowMa) and waitingFirstTradeInDownwardTrend and strategy.position_size == 0

///////////////////////////////////////////////////////////////////////////////////////////////////////////////// strategy

if(enterLongCondition)
    strategy.entry(id="L", direction=strategy.long)
    waitingFirstTradeInUpwardTrend := false

if(enterShortCondition)
    strategy.entry(id="S", direction=strategy.short)
    waitingFirstTradeInDownwardTrend := false
    
if(strategy.position_size > 0)
    strategy.exit(id="EL", stop=strategy.position_avg_price * (1 - stopLoss/100), limit=strategy.position_avg_price * (1+targetProfit/100)) 
if(strategy.position_size < 0)
    strategy.exit(id="ES", stop=strategy.position_avg_price * (1 + stopLoss/100), limit=strategy.position_avg_price * (1-targetProfit/100)) 

///////////////////////////////////////////////////////////////////////////////////////////////////////////////// plots

plot(series = slowSmma, title="Slow SMMA", linewidth=3)
plot(series = midSmma, title="Mid SMMA", linewidth=2)
plot(series = fastSmma, title="Fast SMMA", linewidth=1)
plotchar(series=rsiIsHigh, title='rsiIsHigh', char='')
plotchar(series=justEnteredUpwardTrend, title='justEnteredUpwardTrend', char='')
plotchar(series=justEnteredDownwardTrend, title='justEnteredDownwardTrend', char='')
plotchar(series=waitingFirstTradeInUpwardTrend, title='waitingFirstTradeInUpwardTrend', char='')
plotchar(series=waitingFirstTradeInDownwardTrend, title='waitingFirstTradeInDownwardTrend', char='')
plotchar(series=enterLongCondition, title='enterLongCondition' , char='')
plotchar(series=enterShortCondition, title='enterShortCondition' , char='')
plotshape(series=upFractal, title='upFractal', style=shape.triangleup, location=location.abovebar, color=#009688, size = size.tiny)
plotshape(series=downFractal, title='downFractal', style=shape.triangledown, location=location.belowbar, color=color.red, size = size.tiny)













더 많은