デュアルチャネルアルゴリズム自動取引戦略


作成日: 2023-10-10 15:25:53 最終変更日: 2023-10-10 15:25:53
コピー: 0 クリック数: 639
1
フォロー
1617
フォロワー

概要

この戦略は,スーパートレンドとストックRSIの2つの指標を使用して,潜在的な買入と売却のシグナルを識別するために,異なる時間周期の価格動向とオーバーバイのオーバーセルの分析を行います. この戦略は,主要なトレンドの方向をフォローして取引し,価格の主要な方向を中長線で捉えることを目的としています.

戦略原則

この戦略は,1時間と4時間の2つの時間周期のスーパートレンド指標を使用して価格の傾向の方向を判断します. 2つの時間周期のスーパートレンドが同じ方向に進むと,より強い価格の傾向が起こっていると考えることができます.

さらに,ストックRSI指標を使用して,超買い超売りが発生しているかどうかを判断する.ストックRSI指標は,RSIとストックアスティックオシレータの2つの指標の利点を組み合わせている.ストックRSI指標の線段の上の超買線を突破すると,価格が超売りが発生する可能性を示し,ストックRSI指標の線段の下の超売りが発生した場合,価格が超売りが発生する可能性を示している.

双のスーパートレンドが価格トレンドの方向を確認していると同時に,もしStochRSIも超買超売の現象を示しているならば,それは良い買い買いまたは売り売りの時間である.信号をさらに検証するために,戦略は,また,逆行期を設定し,StochRSIが超買超売の信号を示した後に,一定数のK線を逆行する必要があり,もしこの期間中に価格走行がStochRSIの信号を確認したならば,買い買いまたは売り売りを触発する.

全体として,この戦略は,二重時間枠のSupertrendを活用して大トレンドを判断し,StochRSIの局所的な調整を判断する方法を統合して,中長線でトレンドフォロー型の取引を行う.

戦略的優位性

  • 多周期指数を用いて判断し,誤信号を効果的にフィルターする
  • SupertrendとStochRSIを組み合わせることで,トレンド判断や超買いと超売り判断を行う
  • 信号の検証に後退期を設定し,不必要な取引を回避します.
  • 中長線操作戦略を採用することで,過度に頻繁な取引による滑点損失を減らすことができる
  • 簡単に理解できる2つの指標の組み合わせ,パラメータの調整の柔軟性

戦略リスク

  • 大波の時には,中長線傾向は目立たないので,誤った信号が多く現れる可能性があります.
  • 長期の遡及期間が長くなり,より良い買い/売却の機会を逃してしまう可能性があります.
  • 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)