RSI와 거래량을 기반으로 한 음양 듀얼 트랙 트렌드 거래 전략


생성 날짜: 2023-12-22 14:29:05 마지막으로 수정됨: 2023-12-22 14:29:05
복사: 0 클릭수: 450
1
집중하다
1224
수행원

RSI와 거래량을 기반으로 한 음양 듀얼 트랙 트렌드 거래 전략

개요

이 전략은 상대적 강도 지수 ((RSI) 와 거래량의 조합 지표를 사용하여 트렌드 방향을 식별하고 트렌드 추적하는 전략입니다. 핵심은 다음과 같습니다:

  1. 중도 이동 평균을 사용하여 중도 축을 계산하고, 거래량 정보를 결합하여 트렌드 중도 축을 판단합니다.
  2. 중축을 기반으로 구매 구역, 판매 구역을 설정합니다.
  3. RSI 정보를 사용하여 구매 구역과 판매 구역의 범위를 조정합니다
  4. 구매 구역에 들어간 후 스톱 라인과 스톱 라인을 설정
  5. 재입학 메커니즘

전략 원칙

이 정책은 다음과 같은 지표와 변수를 사용합니다.

  • 중축: 일정 기간 동안의 최고 가격과 최저 가격의 중화 이동 평균을 계산하고 거래량을 무게로 사용하여 트렌드의 중축 방향을 판단합니다.
  • RSI: 일정 주기 동안의 상대 강도 지수를 계산하여 0-1 범위의 값으로 변환합니다.
  • 구매 구역: 중간 축에 RSI 조정 비율을 추가하여 구매 구역에 들어가면 더 많은 것을 할 수 있습니다.
  • 판매 구역: 중축은 RSI 조정량의 일정한 비율을 빼고 판매 구역에 들어가면 공백을 만들 수 있습니다
  • 정지선: 중축
  • 스톱 라인: 구매 구역 아래/판매 구역 위의 일정한 비율 설정

가격이 구매 구역 또는 판매 구역에 들어간 후, 상반된 방향의 포지션 개시 작업을 수행한다. 이후 스톱 및 스톱 손실 위치를 설정하고, 스톱 또는 스톱을 트리플 할 때 포지션을 평정한다. 또한 재입입 메커니즘을 설정하고, 구성이 허용하면, 포지션 개시 신호를 다시 트리플 할 때 다시 입입 할 수 있다.

전략적 이점

이 전략은 다음과 같은 장점을 가지고 있습니다.

  1. RSI와 거래량 이중 지표를 사용하여 추세를 식별하여 판단의 정확성을 향상시킵니다.
  2. RSI 지수는 실제 동향에 더 잘 맞추기 위해 구매 구역과 판매 구역 범위를 조정합니다.
  3. 거래량 정보는 가격 변화에 더 많은 무게를 부여하여 중축을 더 정확하게 만듭니다.
  4. 위험을 통제하기 위한 손해 방지 장치
  5. 다시 입원할 수 있고, 가짜 침입의 위험을 줄일 수 있습니다.

위험 분석

이 전략에는 몇 가지 위험도 있습니다.

  1. RSI 및 거래량 파라미터의 잘못된 설정은 거래 구역 범위를 결정하는 정확성에 영향을 미칠 수 있습니다.
  2. 중축이 트렌드를 완전히 정확하게 판단할 수 없으므로 오류가 발생할 수 있습니다.
  3. 정지점 설정이 너무 넓으면 더 큰 손실이 발생할 수 있습니다.
  4. 재입장 메커니즘은 과도한 거래로 이어질 수 있습니다.

대응 최적화 조치:

  1. RSI 주기, 거래량 주기 파라미터를 조정하여 시장 상황에 더 적합하게 만듭니다.
  2. 다른 지표와 함께 구매/판매 신호를 검증하여 실수로 침입하는 것을 방지합니다.
  3. 단편적 손실을 통제하기 위한 적절한 절감
  4. 매일 거래하는 횟수를 제한하고 과도한 거래를 피하십시오.

전략 최적화 방향

이 정책은 다음과 같은 측면에서 최적화될 수 있습니다.

  1. 다른 지표로 구매 신호를 확인해 보세요. K선 형태, 변동률 지표 등과 같은 것
  2. 이윤 후 부가가치와 같은 포지션 관리 장치를 추가합니다.
  3. 트렌드를 판단하는 기계 학습 알고리즘의 정확도를 높이고, 구매 및 판매 구역 설정을 향상시킵니다.
  4. 스톱 스톱 손실 지점 설정을 평가하는 최적의 매개 변수
  5. 다양한 품종의 파라미터가 다르기 때문에 개별적으로 테스트 및 최적화가 필요합니다.

요약하다

이 전략은 전체적으로 RSI와 거래량 지표를 사용하여 트렌드 추적을위한 정량화 전략입니다. 트렌드 신호를 식별하는 이중 검증 메커니즘이 있으며, 위험을 제어하기 위해 중지 중지 손실을 설정하고, 수익 기회를 높이기 위해 재입장 메커니즘을 설정합니다. 매개 변수 조정 및 알고리즘 최적화를 통해이 전략은 매우 실용적인 트렌드 추적 거래 전략이 될 수 있습니다.

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

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@    ,@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@      @@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@        @@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@         @@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@           @@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@        .@@@@@@@@@@@@@@@            @@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@          *@@@@@@@@@@@@@@             @@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@         @@@@@@@@@@@@@@@               @@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@                 @@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                  @@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.                    @@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                      @@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.                         @
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                             @
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@,                                       @
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                                                @
// @@@@@@@@@@@@@@@@@@@@@@@@@@@                                                    @
// @@@@@@@@@@@@@@@@@@@@@@@@@                                                     @@
// @@@@@@@@@@@@@@@@@@@@@@@                                                       @@
// @@@@@@@@@@@@@@@@@@@@@@                                                       @@@
// @@@@@@@@@@@@@@@@@@@@@*                @@@@@                                 @@@@
// @@@@@@@@@@@@@@@@@@@@@               @@@@@@@@@                              @@@@@
// @@@@@@@@@@@@@@@@@@@@@              @@@@@@@@@@@                           @@@@@@@
// @@@@@@@@@@@@@@@@@@@@@               @@@@@@@@%                           @@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@                                                @@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@                                            @@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@                                        %@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@                                   @@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@                           @@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// © YinYangAlgorithms

//@version=5
strategy("YinYang RSI Volume Trend Strategy", shorttitle="YinYang RSVT Strategy", overlay=true )
// ~~~~~~~~~~~ INPUTS ~~~~~~~~~~~ //
len = input.int(80, "Trend Length:", tooltip="How far back should we span this indicator?\nThis length effects all lengths of the indicator")
purchaseSrc = input.source(close, "Purchase Source (Long and Short):", tooltip="What source needs to exit the purchase zone for a purchase to happen?")
exitSrc = input.source(close, "Exit Source (Long and Short):", tooltip="What source needs to hit a exit condition to stop the trade (Take profit, Stop Loss or hitting the other sides Purchase Zone)?")
useTakeProfit = input.bool(true, "Use Take Profit", tooltip="Should we take profit IF we cross the basis line and then cross it AGAIN?")
useStopLoss = input.bool(true, "Use Stop Loss", tooltip="Stop loss will ensure you don't lose too much if its a bad call")
stopLossMult = input.float(0.1, "Stoploss Multiplier %:", tooltip="How far from the purchase lines should the stop loss be")
resetCondition = input.string("Entry", "Reset Purchase Availability After:", options=["Entry", "Stop Loss", "None"],
 tooltip="If we reset after a condition is hit, this means we can purchase again when the purchase condition is met. \n" +
 "Otherwise, we will only purchase after an opposite signal has appeared.\n" +
 "Entry: means when the close enters the purchase zone (buy or sell).\n" +
 "Stop Loss: means when the close hits the stop loss location (even when were out of a trade)\n" +
 "This allows us to get more trades and also if our stop loss initally was hit but it WAS a good time to purchase, we don't lose that chance.")

// ~~~~~~~~~~~ VARIABLES ~~~~~~~~~~~ //
var bool longStart = na
var bool longAvailable = na
var bool longTakeProfitAvailable = na
var bool longStopLoss = na
var bool shortStart = na
var bool shortAvailable = na
var bool shortTakeProfitAvailable = na
var bool shortStopLoss = na

resetAfterStopLoss = resetCondition == "Stop Loss"
resetAfterEntry = resetCondition == "Entry"

// ~~~~~~~~~~~ CALCULATIONS ~~~~~~~~~~~ //
// Mid Line
midHigh = ta.vwma(ta.highest(high, len), len)
midLow = ta.vwma(ta.lowest(low, len), len)
mid = math.avg(midHigh, midLow)
midSmoothed = ta.ema(mid, len)

//Volume Filtered
avgVol = ta.vwma(volume, len)
volDiff = volume / avgVol
midVolSmoothed = ta.vwma(midSmoothed * volDiff, 3)

//RSI Filtered
midDifference = ta.sma(midHigh - midLow, len)
midRSI = ta.rsi(midVolSmoothed, len) * 0.01
midAdd = midRSI * midDifference

//Calculate Zones
purchaseZoneHigh = midSmoothed + midAdd
purchaseZoneLow = midSmoothed - midAdd
purchaseZoneBasis = math.avg(purchaseZoneHigh, purchaseZoneLow)

//Create Stop Loss Locations
stopLossHigh = purchaseZoneHigh * (1 + (stopLossMult * 0.01))
stopLossLow = purchaseZoneLow * (1 - (stopLossMult * 0.01))

// ~~~~~~~~~~~ PURCHASE CALCULATIONS ~~~~~~~~~~~ //
//Long
longEntry = ta.crossunder(purchaseSrc, purchaseZoneLow)
longStart := ta.crossover(purchaseSrc, purchaseZoneLow) and longAvailable
longAvailable := ta.crossunder(purchaseSrc, purchaseZoneHigh) or (resetAfterStopLoss and longStopLoss) or (resetAfterEntry and longEntry) ? true : longStart ? false : longAvailable[1]
longEnd = ta.crossover(exitSrc, purchaseZoneHigh)
longStopLoss := ta.crossunder(exitSrc, stopLossLow)
longTakeProfitAvailable := ta.crossover(exitSrc, purchaseZoneBasis) ? true : longEnd ? false : longTakeProfitAvailable[1]
longTakeProfit = ta.crossunder(exitSrc, purchaseZoneBasis) and longTakeProfitAvailable

//Short
shortEntry = ta.crossover(purchaseSrc, purchaseZoneHigh)
shortStart := ta.crossunder(purchaseSrc, purchaseZoneHigh) and shortAvailable
shortAvailable := ta.crossover(purchaseSrc, purchaseZoneLow) or (resetAfterStopLoss and shortStopLoss) or (resetAfterEntry and shortEntry)? true : shortStart ? false : shortAvailable[1]
shortEnd = ta.crossunder(exitSrc, purchaseZoneLow)
shortStopLoss := ta.crossover(exitSrc, stopLossHigh)
shortTakeProfitAvailable := ta.crossunder(exitSrc, purchaseZoneBasis) ? true : shortEnd ? false : shortTakeProfitAvailable[1]
shortTakeProfit = ta.crossover(exitSrc, purchaseZoneBasis) and shortTakeProfitAvailable

// ~~~~~~~~~~~ PLOTS ~~~~~~~~~~~ //
shortLine = plot(purchaseZoneHigh, color=color.green)
shortStopLossLine = plot(stopLossHigh, color=color.green) //color=color.rgb(0, 97, 3)
fill(shortLine, shortStopLossLine, color = color.new(color.green, 90))
plot(purchaseZoneBasis, color=color.white)
longLine = plot(purchaseZoneLow, color=color.red)
longStopLossLine = plot(stopLossLow, color=color.red) //color=color.rgb(105, 0, 0)
fill(longLine, longStopLossLine, color=color.new(color.red, 90))

// ~~~~~~~~~~~ STRATEGY ~~~~~~~~~~~ //
if (longStart)
    strategy.entry("buy", strategy.long)
else if (longEnd or (useStopLoss and longStopLoss) or (useTakeProfit and longTakeProfit))
    strategy.close("buy")

if (shortStart)
    strategy.entry("sell", strategy.short)
else if (shortEnd or (useStopLoss and shortStopLoss) or (useTakeProfit and shortTakeProfit))
    strategy.close("sell")

// ~~~~~~~~~~~ ALERTS ~~~~~~~~~~~ //
if longStart or (longEnd or (useStopLoss and longStopLoss) or (useTakeProfit and longTakeProfit)) or shortStart or (shortEnd or (useStopLoss and shortStopLoss) or (useTakeProfit and shortTakeProfit))
    alert("{{strategy.order.action}} | {{ticker}} | {{close}}", alert.freq_once_per_bar)