RSI価格乖離定量戦略指標動的監視および適応最適化システム

RSI TP SL
作成日: 2025-01-10 16:20:25 最終変更日: 2025-01-10 16:20:25
コピー: 5 クリック数: 421
1
フォロー
1617
フォロワー

RSI価格乖離定量戦略指標動的監視および適応最適化システム

概要

この戦略は、RSI と価格の乖離に基づいたインテリジェントな取引システムです。RSI インジケーターと価格トレンドの乖離関係を動的に監視することで、市場の反転シグナルを捉えます。この戦略は、補助的な確認としてフラクタルを取り入れ、完全に自動化された取引実行を実現するための適応型ストッププロフィットおよびストップロスメカニズムを備えています。このシステムは、多品種、多サイクルのアプリケーションをサポートし、優れた柔軟性と実用性を備えています。

戦略原則

戦略の中核となるロジックは、次の主要な要素に基づいています。

  1. RSI ダイバージェンスの識別: RSI インジケーターの高値と安値、および価格アクションを比較して、潜在的なダイバージェンスを識別します。価格が新しい高値に達したが RSI が新しい高値に達しない場合は、トップダイバージェンス売りシグナルが形成されます。価格が新しい安値に達したが RSI が新しい安値に達しない場合は、ボトムダイバージェンス買いシグナルが形成されます。
  2. フラクタル確認: フラクタルを使用して価格構造を分析し、ローカルの高値と安値を検出してダイバージェンスの妥当性を確認し、信号の信頼性を向上させます。
  3. パラメータ適応: システムは、さまざまな市場環境への適応を実現するために、フラクタル判定間隔を動的に調整する感度パラメータを導入します。
  4. リスク管理: パーセンテージベースのストップロスとテイクプロフィットのメカニズムを統合し、各取引のリスクが制御可能であることを保証します。

戦略的優位性

  1. 高いシグナル信頼性: RSI ダイバージェンスとフラクタル理論の二重確認メカニズムにより、取引シグナルの精度が大幅に向上します。
  2. 強い適応性: この戦略は、さまざまな市場状況に応じてパラメータを柔軟に調整でき、環境適応性に優れています。
  3. 完璧なリスク管理: 動的なストッププロフィットとストップロスのメカニズムを統合し、各取引のリスクエクスポージャーを効果的に制御します。
  4. 高度な自動化: シグナル認識からトランザクション実行までのプロセス全体が自動化されており、人間の介入による感情的な影響が軽減されます。
  5. 優れたスケーラビリティ: 戦略フレームワークは、多品種およびマルチサイクルのアプリケーションをサポートし、ポートフォリオ投資を容易にします。

戦略リスク

  1. 市場環境への依存: 明らかなトレンドがある市場では、ダイバージェンス信号の信頼性が低下する可能性があるため、トレンドフィルタリングメカニズムを追加する必要があります。
  2. パラメータの感度: RSI しきい値やフラクタル判定間隔などの戦略の重要なパラメータは、慎重にデバッグする必要があります。不適切なパラメータ設定は、戦略のパフォーマンスに影響を与える可能性があります。
  3. シグナルラグ: シグナルを確認するにはダイバージェンスパターンが完全に形成されるのを待つ必要があるため、エントリータイミングに一定のラグが生じる可能性があります。
  4. 市場ノイズ干渉: 不安定な市場では、誤ったダイバージェンス信号が生成される可能性があり、追加のフィルタリング条件を追加する必要があります。

戦略最適化の方向性

  1. トレンドフィルタリングの強化: トレンド判断インジケーターを導入して、強いトレンド市場での逆シグナルをフィルタリングし、さまざまな市場環境における戦略の適応性を向上させます。
  2. パラメータ適応の最適化: 市場のボラティリティに基づいて動的なパラメータ調整メカニズムを開発し、市場の変化に対する戦略の応答性を向上させます。
  3. リスク管理の改善: 市場の変動に応じてストップロスポジションを自動的に調整し、資金管理効果を最適化する動的ストップロスメカニズムを導入します。
  4. 強化されたシグナル確認: 取引量やボラティリティなどの市場微細構造指標を組み合わせて、より完全なシグナル確認システムを確立します。

要約する

この戦略は、RSI ダイバージェンスとフラクタル理論の革新的な組み合わせを通じて、堅牢な取引システムを構築します。この戦略の利点は、高いシグナル信頼性、強力な適応性、完全なリスク管理メカニズムにあります。継続的な最適化と改善を通じて、この戦略はさまざまな市場環境において安定したパフォーマンスを維持することが期待されます。リアルタイムで適用する場合は、市場特性を考慮してパラメータを十分にテストして最適化し、リスク管理措置を厳密に実施することをお勧めします。

ストラテジーソースコード
/*backtest
start: 2025-01-02 00:00:00
end: 2025-01-09 00:00:00
period: 5m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":49999}]
*/

//FRACTALS
//@version=5

//last : 30m 70 68 22 25 0 0 4.7 11.5

//init
capital=1000
percent=100
fees=0//in percent for each entry and exit

//Inputs
start = input(timestamp("1 Feb 2002"), "Start Time", group = "Date")
end = input(timestamp("1 Feb 2052"), "End Time", group = "Date")

//Strategy
strategy("Divergence Finder (RSI/Price) Strategy with Options", overlay = true, initial_capital=capital, default_qty_value=percent, default_qty_type=strategy.percent_of_equity, commission_type=strategy.commission.percent, calc_on_order_fills=false,process_orders_on_close=true , commission_value=fees, currency=currency.EUR, calc_on_every_tick=true, use_bar_magnifier=false)
//indicator("Divergence Finder (RSI/Price) with Options", overlay=true, max_boxes_count=200, max_bars_back=500,max_labels_count=500)


srcUp=input.source(close, "Source for Price Buy Div", group="sources")
srcDn=input.source(close, "Source for Price Sell Div", group="sources")
srcRsi=input.source(close, "Source for RSI Div", group="sources")


HighRSILimit=input.int(70, "Min RSI for Sell divergence (p1:pre last)", group="signals", inline="1", step=1)
HighRSILimit2=input.int(68, "Min RSI for Sell divergence (p2):last", group="signals", inline="1", step=1)
LowRSILimit=input.int(22, "Min RSI for Buy divergence (p1:pre last)", group="signals", inline="2", step=1)
LowRSILimit2=input.int(25, "Min RSI for Buy divergence (p2:last)", group="signals", inline="2", step=1)


minMarginP=input.float(0, "Min margin between price for displaying divergence (%)", group="signals", step=0.01)
minMarginR=input.float(0, "Min margin between RSI for displaying divergence (%)", group="signals", step=1)

nb=input.int(2, "Sensivity: Determine how many candle will be used to determine last top or bot (too high cause lag, too low cause repaint)", group="Sensivity", inline="3", step=1)


stopPer= input.float(4.7, title='Stop %', group = "Per", inline="3", step=0.01)
tpPer = input.float(11.5, title='TP %', group = "Per", inline="4", step=0.01)

//nb=2
leftBars = nb
rightBars=nb


labels=input.bool(true, "Display Divergence labels", group="Display")
draw=input.bool(true, "Display tops/bottoms")



dnFractal = (close[nb-2] < close[nb]) and (close[nb-1] < close[nb]) and (close[nb+1] < close[nb]) and (close[nb+2] < close[nb])
upFractal = (close[nb-2] > close[nb]) and (close[nb-1] > close[nb]) and (close[nb+1] > close[nb]) and (close[nb+2] > close[nb])
ph=dnFractal
pl=upFractal

plot(dnFractal and draw ? close[nb] : na, style=plot.style_line,offset=-2, color=color.lime, title="tops")
plot(upFractal and draw ? close[nb] : na,  style=plot.style_line, offset=-2, color=color.red, title="botts")

plotchar(dnFractal ? high[nb] : na, char='⮝',location=location.absolute,offset=-2, color=color.rgb(236, 255, 63), title="Down Fractal")
plotchar(upFractal ? low[nb] : na, char='⮟', location=location.absolute, offset=-2, color=color.rgb(67, 227, 255), title="Up Fractal")


float myRSI=ta.rsi(srcRsi, 14)

bool divUp=false
bool divDn=false

//compare lasts bots
p2=ta.valuewhen( ph,srcDn[nb], 0 ) //last price
p1=ta.valuewhen( ph,srcDn[nb], 1 ) //pre last price

r2=ta.valuewhen( ph,myRSI[nb], 0 )  //last rsi
r1=ta.valuewhen( ph,myRSI[nb], 1 )  //pre last rsi


if ph
    if p1 < p2// - (p2 * minMarginP)/100
        if r1 > HighRSILimit and r2 > HighRSILimit2
            if r1 > r2 + (r2 * minMarginR)/100
                divDn:=true

plot(divDn ? close:na, style=plot.style_cross, linewidth=3, color= color.red, offset=-rightBars, title="Sell Div")
if labels and divDn and strategy.position_size >= 0
    label.new(bar_index-nb,high, "Sell Divergence "+str.tostring(p1)+"   "+str.tostring(math.round(r1, 2))+"  "+str.tostring(p2)+"   "+str.tostring(math.round(r2, 2)),xloc=xloc.bar_index,yloc=yloc.abovebar, color = color.red, style = label.style_label_down)
else if divDn and strategy.position_size >= 0
    label.new(bar_index-nb,high, "Sell Divergence",xloc=xloc.bar_index,yloc=yloc.abovebar, color = color.red, style = label.style_label_down)



p2:=ta.valuewhen( pl,srcUp[nb], 0 )
p1:=ta.valuewhen( pl,srcUp[nb], 1 )

r2:=ta.valuewhen( pl,myRSI[nb], 0 )
r1:=ta.valuewhen( pl,myRSI[nb], 1 )


if pl
    if p1 > p2 + (p2 * minMarginP)/100
        if r1 < LowRSILimit and r2 < LowRSILimit2
            if r1 < r2 - (r2 * minMarginR)/100
                divUp:=true
               
plot(divUp ? close:na, style=plot.style_cross, linewidth=3, color= color.green, offset=-rightBars, title="Buy Div")
if labels and divUp and strategy.position_size <= 0
    label.new(bar_index-nb,high, "Buy Divergence "+str.tostring(p1)+"   "+str.tostring(math.round(r1, 2))+"  "+str.tostring(p2)+"   "+str.tostring(math.round(r2, 2)),xloc=xloc.bar_index,yloc=yloc.belowbar, color = color.green, style = label.style_label_up)
else if divUp and strategy.position_size <= 0
    label.new(bar_index-nb,high, "Buy Divergence",xloc=xloc.bar_index,yloc=yloc.belowbar, color = color.green, style = label.style_label_up)


//strat LONG
longEntry = divUp//  and strategy.position_size == 0
longExit = divDn//  and strategy.position_size == 0

//strat SHORT
shortEntry = divDn
shortExit = divUp

LongActive=input(true, title='Activate Long', group = "Directions", inline="2")
ShortActive=input(true, title='Activate Short', group = "Directions", inline="2")
//StopActive=input(false, title='Activate Stop', group = "Directions", inline="2")


//tpActive =  input(false, title='Activate Take Profit', group = "TP", inline="4")
//RR=input(0.5, title='Risk Reward Multiplier', group = "TP")
//QuantityTP = input(100.0, title='Trade Ammount %', group = "TP")


//calc stop
//longStop = strategy.position_avg_price * (1 - stopPer)
//shortStop = strategy.position_avg_price * (1 + stopPer)

longStop = strategy.position_avg_price - (strategy.position_avg_price * stopPer/100)
shortStop = strategy.position_avg_price + (strategy.position_avg_price * stopPer/100)

longTP = strategy.position_avg_price + (strategy.position_avg_price * tpPer/100)
shortTP = strategy.position_avg_price - (strategy.position_avg_price * tpPer/100)

//Calc TP
//longTP = ((strategy.position_avg_price-longStop)*RR+strategy.position_avg_price)
//shortTP = (strategy.position_avg_price-((shortStop-strategy.position_avg_price)*RR))


//display stops
plot(strategy.position_size > 0 ? longStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Long Fixed SL")
plot(strategy.position_size < 0 ? shortStop : na, style=plot.style_linebr, color=color.purple, linewidth=1, title="Short Fixed SL")


//display TP
plot(strategy.position_size > 0 ? longTP : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Long Fixed TP")
plot(strategy.position_size < 0 ? shortTP : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Short Fixed TP")

//do
if true
    //check money available
    if strategy.equity > 0
        //if tpActive //Need to put TP before Other exit
        strategy.exit("Close Long", from_entry="Long", limit=longTP,stop=longStop, comment="Close Long with : "+ str.tostring(math.round(strategy.equity)) +" $ ", qty_percent=100)
        strategy.exit("Close Short", from_entry="Short", limit=shortTP,stop=shortStop, comment="Close Short with : "+ str.tostring(math.round(strategy.equity)) +" $ ", qty_percent=100)
        //Set Stops
        //if StopActive
        //    strategy.exit("Stop Long", from_entry="Long", stop=longStop, comment="Stop Long with : "+ str.tostring(math.round(strategy.equity)) +" $ ")
        //    strategy.exit("Stop Short", from_entry="Short", stop=shortStop, comment="Stop Short with : "+ str.tostring(math.round(strategy.equity)) +" $ ")
        if longEntry
            if ShortActive
                strategy.close("Short",comment="Close Short with : "+ str.tostring(math.round(strategy.equity)) +" $ ")
                alert("Close Short")
            if LongActive
                strategy.entry("Long", strategy.long, comment="Open Long with : "+ str.tostring(math.round(strategy.equity)) +" $ ")
                alert("Open Long")
        if longExit
            if LongActive
                strategy.close("Long",comment="Close Long with : "+ str.tostring(math.round(strategy.equity)) +" $ ")
                alert("Close Long")
            if ShortActive
                strategy.entry("Short", strategy.short, comment="Open Short with : "+ str.tostring(math.round(strategy.equity)) +" $ ")
                alert("Open Short")


//alertcondition(longEntry and LongActive, title="Buy Divergence Open", message="Buy Divergence Long Opened!")
//alertcondition(longExit and ShortActive, title="Sell Divergence Open", message="Buy Divergence Short Opened!")

//alertcondition(longExit and LongActive, title="Buy Divergence Closed", message="Buy Divergence Long Closed!")
//alertcondition(longEntry and ShortActive, title="Sell Divergence Closed", message="Buy Divergence Short Closed!")