듀얼채널 알고리즘 자동거래 전략


생성 날짜: 2023-10-10 15:25:53 마지막으로 수정됨: 2023-10-10 15:25:53
복사: 0 클릭수: 639
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

개요

이 전략은 수퍼트렌드와 스토치RSI를 사용하여 다양한 시기의 가격 동향과 초과 판매 상황을 분석하여 잠재적인 구매 및 판매 신호를 식별합니다. 이 전략은 주요 트렌드 방향에 따라 거래하여 중·장선에서 가격의 주요 방향을 잡습니다.

전략 원칙

이 전략은 1시간과 4시간의 두 시간 주기 수퍼트렌드 지표를 사용하여 가격 트렌드 방향을 판단한다. 두 시간 주기 수퍼트렌드가 같은 방향으로 나타나면 우리는 더 강한 가격 트렌드가 나타났다고 생각할 수 있다.

또한, 전략은 StochRSI 지표를 사용하여 과매매가 존재하는지 판단합니다. StochRSI 지표는 RSI와 Stochastic Oscillator 두 지표의 장점을 결합합니다.

이중 슈퍼트렌드가 가격 트렌드 방향을 확인하는 동시에, 만약 StochRSI도 오버 바이오 오버 세이 현상을 보여준다면, 그때는 좋은 구매 또는 판매 시점이다. 신호를 추가로 검증하기 위해, 전략은 또한 회귀 기간을 설정하고, StochRSI가 오버 바이오 오버 세이 신호를 보여준 후, 특정 K선 수를 회귀해야 하며, 이 기간 동안 가격 움직임이 StochRSI의 신호를 확인하면, 그때는 구매 또는 판매를 촉발한다.

전체적으로, 이 전략은 두 개의 시간 프레임의 Supertrend를 사용하여 큰 트렌드를 판단하고, StochRSI를 사용하여 지역 조정을 판단하여, 중장기선에서 트렌드 추적 트레이드를 수행합니다.

전략적 이점

  • 다중 시간 주기의 지표를 사용하여 판단하여 잘못된 신호를 효과적으로 필터링 할 수 있습니다.
  • Supertrend과 StochRSI를 통합하여 트렌드를 판단하고 과매매를 판단하는 장점
  • 신호 검증을 위한 회귀 기간을 설정하여 불필요한 거래를 방지할 수 있습니다.
  • 중·장기선 운영 전략을 적용하여 너무 자주 거래되는 지점 손실을 줄일 수 있습니다.
  • 쉽게 이해할 수 있는 쌍 지표 조합, 변수 조정 유연성

전략적 위험

  • 대가격동기 때, 중장선 트렌드는 명확하지 않으며, 잘못된 신호가 더 많이 나타날 수 있다.
  • 너무 긴 회귀기 때문에 더 좋은 구매/판매 기회를 놓칠 수 있습니다.
  • StochRSI 파라미터가 잘못 설정되어 오버 바이 오버 셀 신호가 오류가 발생할 수 있습니다.
  • Supertrend 변수가 잘못 설정되어 잘못된 트렌드 방향을 판단할 수 있습니다.
  • 기계적으로 지표 신호를 따라가면서 중요한 기본적 변화를 무시하는 것

최적화 방법:

  • StochRSI와 Supertrend의 변수 조합을 최적화합니다.
  • 다양한 대장 환경에서 회귀 주기의 길이를 조정합니다.
  • 거래량과 같은 지표와 함께 검증합니다.
  • 중요한 기본 소식에 주의를 기울이고 필요한 경우 적극적으로 개입하십시오.

전략 최적화 방향

  • 더 많은 다양한 시간 주기 수퍼트렌드 지표를 추가하여 다단계 필터를 생성합니다.
  • 스토치RSI를 KD, RSI 등과 같은 다른 과매매형 지표로 대체합니다.
  • 트렌드에 따라 더 많은 수익을 얻기 위해 이동적 손실 전략을 늘립니다.
  • 30주기 평균과 같은 중요한 평균 지표와 결합하여 큰 추세를 판단합니다.
  • 자동 변수 최적화 프로그램을 개발하여 전략을 더 거칠게 만듭니다.

요약하다

양채널 주방방 전략은 Supertrend의 대 추세 판단 방법과 StochRSI의 지역 조정 판단 방법을 최대한 활용하여 신뢰할 수 있는 추세 추적 전략을 구현합니다. 이 전략은 중장선 조작을 주력으로 하며, 너무 자주 거래로 인한 수익 손실을 효과적으로 피할 수 있습니다. 매개 변수 최적화 및 조합 지표 검증과 같은 수단을 통해 이 전략은 안정적인 긍정적 수익을 얻을 수 있습니다. 그러나 투자자는 여전히 중요한 기본 변동에 주의를 기울이고 지표 신호를 기계적으로 따르지 않도록해야합니다.

전략 소스 코드
/*backtest
start: 2023-09-09 00:00:00
end: 2023-10-09 00:00:00
period: 4h
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/
// © Baby_whale_to_moon

//@version=5
strategy('Kitchen [ilovealgotrading]', overlay=true, format=format.price, initial_capital = 1000)

// BACKTEST DATE
Start_Time = input(defval=timestamp('01 January 2017 13:30 +0000'), title='Start_Time', group = " ################# BACKTEST DATE ################ " )
End_Time = input(defval=timestamp('30 April 2024 19:30 +0000'), title='End_Time', group = " ################# BACKTEST DATE ################ " )

// supertrend 
atrPeriod = input(10, 'ATR Length', group = " #################  Supertrend  ################ ")
factor = input(3, 'Factor', group = " #################  Supertrend  ################ ")

time1 = input.string(title='Short Time Period', defval='07 1h', options=['01 1m','02 3m','03 5m',  '04 15m', '05 30m', '06 45m', '07 1h', '08 2h', '09 3h', '10 4h', '11 1D', '12 1W' ], group = " #################  Supertrend  ################ ",tooltip = "this timeframe is the value of our short-time supertrend indicator")
time2 = input.string(title='Long Time Period', defval='10 4h', options=[ '01 1m','02 3m','03 5m', '04 15m', '05 30m', '06 45m', '07 1h', '08 2h', '09 3h', '10 4h', '11 1D', '12 1W' ], group = " #################  Supertrend  ################ ",tooltip = "this timeframe is the value of our long-time supertrend indicator")


res(Resolution) =>
    if Resolution == '00 Current'
        timeframe.period
    else
        if Resolution == '01 1m'
            '1'
        else
            if Resolution == '02 3m'
                '3'
            else
                if Resolution == '03 5m'
                    '5'
                else
                    if Resolution == '04 15m'
                        '15'
                    else
                        if Resolution == '05 30m'
                            '30'
                        else
                            if Resolution == '06 45m'
                                '45'
                            else
                                if Resolution == '07 1h'
                                    '60'
                                else
                                    if Resolution == '08 2h'
                                        '120'
                                    else
                                        if Resolution == '09 3h'
                                            '180'
                                        else
                                            if Resolution == '10 4h'
                                                '240'
                                            else
                                                if Resolution == '11 1D'
                                                    '1D'
                                                else
                                                    if Resolution == '12 1W'
                                                        '1W'
                                                    else
                                                        if Resolution == '13 1M'
                                                            '1M'


// supertrend Long time period 
[supertrend2, direction2] = request.security(syminfo.tickerid, res(time2), ta.supertrend(factor, atrPeriod))
bodyMiddle4 = plot((open + close) / 2, display=display.none)
upTrend2 = plot(direction2 < 0 ? supertrend2 : na, 'Up Trend', color=color.new(color.green, 0), style=plot.style_linebr, linewidth=2)
downTrend2 = plot(direction2 < 0 ? na : supertrend2, 'Down Trend', color=color.new(color.red, 0), style=plot.style_linebr, linewidth=2)

// supertrend short time period 
[supertrend1, direction1] = request.security(syminfo.tickerid, res(time1), ta.supertrend(factor, atrPeriod))
bodyMiddle = plot((open + close) / 2, display=display.none)
upTrend = plot(direction1 < 0 ? supertrend1 : na, 'Up Trend', color=color.new(color.yellow, 0), style=plot.style_linebr)
downTrend = plot(direction1 < 0 ? na : supertrend1, 'Down Trend', color=color.new(color.orange, 0), style=plot.style_linebr)


// Stochastic RSI
low_limit_stoch_rsi = input.float(title = 'Stoch Rsi Low Limit', step=0.5, defval=15, group = " #################  Stoch RSI   ################ ", tooltip = "when Stock rsi value crossover Low Limit value we get Long")
up_limit_stoch_rsi = input.float(title = 'Stoch Rsi Up Limit', step=0.5, defval=85, group = " #################  Stoch RSI   ################ ", tooltip = "when Stock rsi value crossunder Up Limit value we get Short")
stocrsi_back_length = input.int(20, 'Stoch Rsi retroactive length', minval=1, group = " #################  Stoch RSI   ################ ", tooltip = "How many candles are left behind, even if there is a buy or sell signal, it will be valid now")
smoothK = input.int(3, 'Stochastic RSI K', minval=1, group = " #################  Stoch RSI   ################ ")
lengthRSI = input.int(14, 'RSI Length', minval=1, group = " #################  Stoch RSI   ################ ")
lengthStoch = input.int(14, 'Stochastic Length', minval=1, group = " #################  Stoch RSI   ################ ")
src_rsi = input(close, title='RSI Source', group = " #################  Stoch RSI   ################ ")
rsi1 = request.security(syminfo.tickerid, '240', ta.rsi(src_rsi, lengthRSI))
k = request.security(syminfo.tickerid, '240', ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK))

// Strategy settings 
dollar = input.float(title='Dollar Cost Per Position ', defval=20000, group = " #################  Strategy Settings  ################ ")
trade_direction = input.string(title='Trade_direction', group = " #################  Strategy Settings  ################ ", options=['LONG', 'SHORT', 'BOTH'], defval='BOTH')
Long_message_open = input('Long Open', title = "Long Open Message", group = " #################  Strategy Settings  ################ ", tooltip = "if you write your alert window this code {{strategy.order.alert_message}} .When trigger Long signal you will get dynamically what you pasted here for Long Open Message ")
Short_message_open = input('Short Open', title = "Short Open Message", group = " #################  Strategy Settings  ################ ", tooltip = "if you write your alert window this code {{strategy.order.alert_message}} .When trigger Long signal you will get dynamically what you pasted here for Short Open Message ")
Long_message_close = input('Long Close', title = "Long Close Message", group = " #################  Strategy Settings  ################ ", tooltip = "if you write your alert window this code {{strategy.order.alert_message}} .When trigger Long signal you will get dynamically what you pasted here for Long Close Message ")
Short_message_close = input('Short Close', title = "Short Close Message", group = " #################  Strategy Settings  ################ ", tooltip = "if you write your alert window this code {{strategy.order.alert_message}} .When trigger Long signal you will get dynamically what you pasted here for Short Close Message ")

Time_interval = true
bgcolor(Time_interval ? color.rgb(255, 235, 59, 95) : na)

back_long = 0
back_short = 0

for i = 1 to stocrsi_back_length by 1
    if ta.crossover(k, low_limit_stoch_rsi)[i] == true 
        back_long += i
        back_long
    if ta.crossunder(k, up_limit_stoch_rsi)[i] == true 
        back_short += i
        back_short

// bgcolor(back_long>0?color.rgb(153, 246, 164, 54):na)
// bgcolor(back_short>0?color.rgb(246, 153, 153, 54):na)

buy_signal = false
sell_signal = false

if direction2 < 0 and direction1 < 0 and back_long > 0
    buy_signal := true
    buy_signal

if direction2 > 0 and direction1 > 0 and back_short > 0
    sell_signal := true
    sell_signal


//bgcolor(buy_signal  ? color.new(color.lime,90) : na ,title="BUY bgcolor")
plotshape( buy_signal[1] == false and  strategy.opentrades == 0 and Time_interval and buy_signal  ? supertrend2 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white)

//bgcolor(sell_signal  ? color.new(color.red,90) : na ,title="SELL bgcolor")
plotshape(sell_signal[1] == false and strategy.opentrades == 0 and Time_interval and sell_signal  ? supertrend2 : na , title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white)


// Strategy entries 
if strategy.opentrades == 0 and Time_interval and buy_signal and ( trade_direction == 'LONG' or trade_direction == 'BOTH')
    strategy.entry('Long_Open', strategy.long, qty=dollar / close, alert_message=Long_message_open)

if strategy.opentrades == 0 and Time_interval and sell_signal and ( trade_direction == 'SHORT' or trade_direction == 'BOTH')
    strategy.entry('Short_Open', strategy.short, qty=dollar / close, alert_message=Short_message_open)


// Strategy Close
if close < supertrend1 and strategy.position_size > 0 
    strategy.exit('Long_Close',from_entry = "Long_Open", stop=close, qty_percent=100, alert_message=Long_message_close)

if close > supertrend1 and strategy.position_size < 0 
    strategy.exit('Short_Close',from_entry = "Short_Open", stop=close, qty_percent=100, alert_message=Short_message_close)