遅延RSI取引戦略は,通常のRSI指標を使用して,超買超売り状況を識別し,入場シグナルが現れた後に,偽の突破によって不必要な損失を避けるために,一定の周期後に再入場を遅らせます.この戦略の主な考えは,RSI指標を使用して,市場の超買超売り現象を判断し,この判断に基づいて,遅延入場により,より正確な入場タイミングを把握することです.
この戦略は,21周期の長さのRSI指標を用いて,超買い超売り状況を判断する.RSI指標の上でユーザが設定した超買線 ((デフォルト60)) を越えたとき,超買いと判断する.RSI指標の下にユーザが設定した超売り線 ((デフォルト40) を越えたとき,超売りと判断する.
超買超売シグナルが現れたと判断すると,戦略はすぐに入場せず,遅延周期を計算し始める.遅延周期数 (デフォルト15サイクル) が満たされた後,超買シグナルに従って空きして,超売シグナルを多めにする.
この戦略は,ユーザが異なる入場タイミングを実現するために遅延周期数を調整することを許します.遅延周期が長くなるほど,より多くの偽突破を回避できますが,より良い入場ポイントを逃すこともできます.ユーザは,特定の品種に応じて遅延周期パラメータを調整する必要があります.
さらに,この戦略は,停止,停止,反転取引などのオプションを実現している. ユーザーは,固定ストップ,追跡ストップ,固定ストップなどの方法でポジションを管理することを選択することができます. また,反転取引ロジックを選択することもできます.
RSIは,より成熟した超買い超売り指標であり,反転の機会を効果的に識別することができます.
遅延入場メカニズムは,偽の突破が損失を招くのを防ぐ.多くの突破は,実質的な逆転を必ずしも意味するものではなく,遅延入場は,突破の有効性を検証することができます.
遅延周期数調整可能,入場時刻を正確に把握する. ユーザーは,異なる品種の特性に応じて遅延周期を調整して,最適な入場点を達成することができる.
ストップ・ストップ・マネジメントを実現し,リスクを制御できる. 戦略は,遅延入場と連携してリスクを制御できる複数のストップ・ストップ方法を提供します.
異なる品種特性に適応した逆取引オプションを提供.ユーザーは,不確実性をカバーするために正向または逆取引ロジックを選択することができます.
RSIが誤った信号を発するリスク. RSIの信号は必ずしも有効ではなく,市場状況によっては誤った信号が出ることもあります.
遅延周期が長すぎると,良い入場点を逃す危険がある.
逆転取引は損失のリスクを高めます.逆転取引は不確実性をカバーしますが,全体的な損失を拡大する可能性もあります.
トラッキングストップは,価格が急激に変化したときに,現在の価格に近すぎ,価格がストップを突破するリスクがある.
ストップ・ストップの予測は,利益不足を引き起こすことができない. 固定ストップは,利益の最大化ができないので,合理的な予測が必要となる.
上記のリスクに対して,最適化方法は以下の通りです.
他の指標と組み合わせてRSI信号をフィルタリングし,信頼性を高めます.例えば,KDJ,MACDなどの指標です.
異なる品種の歴史データテストに基づいて最適の遅延周期パラメータを採取する.概説は不適切である.
逆転トレード機能は慎重に使用し,トレンドトレードなどと組み合わせるのが良い.
ストップ・ロスを追跡する際には,現在の価格に近すぎないように,より広い間隔を設定します.
異なる止止倍数をテストして,最適なパラメータを見つけます. 動的止止を考慮することもできます.
この戦略は,以下の点でさらに最適化できます.
KDJ,MACDなどの指標とRSIを組み合わせて,より信頼性の高い取引信号を形成することができます.
遅延周期数を動的に調整する.市場の変動程度に応じて遅延周期数を動的に変更することができ,偽突破を回避することを保証しながら,入場精度も向上させることができる.
ストップ・ストップ戦略の最適化 ダイナミック・ストップ,利回り比率・ストップ,タイム・ストップなどの研究が可能で,ストップ・ストップを市場の波動特性に適したものにすることができる.
トレンド要因を組み合わせて。突破方向と大トレンド方向の合致性を判断し,逆転取引を避ける。また,突破の強さに応じて遅延周期数を調整することができる。
機械学習を使って最適なパラメータの組み合わせを探します.大量のトレーニングと反復データを介して,機械学習はパラメータを自動的に調整して最適なパラメータの組み合わせを得ることができます.
全体として,この戦略にはまだ多くの最適化余地があり,指標の組み合わせ,動的調節,トレンド判断などの方法で戦略をより安定して信頼できるようにすることができます.機械学習の応用も将来の最適化方向です.
遅延RSI策略 overall RSI指標を利用して超買超売状況を判断し,信号が出た後に一定の周期で再入場を遅延することで,偽突破が不必要な損失を引き起こすのを効果的に防ぐことができます. この戦略は,指標判定精度,偽突破を避けるための遅延入場,遅延周期を調整し,ストップ・ストップ・損失管理を実現するなどの利点があります. しかし,RSI信号が信頼できないこと,遅延しすぎる機会を逃すなどのリスクもあります. 信号の精度を最適化するために,指標の組み合わせ,遅延周期を動的に調整し,機会を把握し,ストップ・ストップ・損失戦略を最適化する方法などによってさらに改善することができます. この戦略には,広範囲の最適化スペースがあり,探索に値します.
/*backtest
start: 2023-01-01 00:00:00
end: 2023-10-06 00:00:00
period: 1d
basePeriod: 1h
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/
// © tweakerID and © BacktestRookies
// This strategy uses a 21 period RSI with an overbought (RSI indicator
// is greater than) level of 60 (user defined) to determines long entries and an oversold
// (RSI indicator is less than) level of 40 (user defined) for shorts. It introduces a bar delay that starts
// counting when the RSI < Oversold or RSI > Overbought conditions are true, delaying the entry with
// the amount of bars determined by the user. The trading logic can be reversed, which seems to work better.
//@version=4
strategy("Delayed RSI Strategy",
overlay=false,
default_qty_type=strategy.percent_of_equity,
default_qty_value=100,
initial_capital=10000,
commission_value=0.04,
calc_on_every_tick=false,
slippage=0)
direction = input(0, title = "Strategy Direction", type=input.integer, minval=-1, maxval=1)
strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all :
(direction < 0 ? strategy.direction.short : strategy.direction.long))
// Bought and Sold Boolean Signal
bought = strategy.position_size > strategy.position_size[1]
or strategy.position_size < strategy.position_size[1]
/////////////////////// STRATEGY INPUTS ////////////////////////////////////////
title1=input(true, "-----------------Strategy Inputs-------------------")
rsiLen=input(21, title="RSI Length")
i_OB = input(60, title="Overbought")
i_OS = input(40, title="Oversold")
i_delay = input(15, title="Entry Delay (# of Bars)")
i_Close= input(false, title="Use Strategy Close")
/////////////////////// BACKTESTER /////////////////////////////////////////////
title2=input(true, "-----------------General Inputs-------------------")
// Backtester General Inputs
i_SL=input(true, title="Use Stop Loss and Take Profit")
TS=input(false, title="Use Trailing Stop")
i_SLType=input(defval="ATR Stop", title="Type Of Stop", options=["Strategy Stop", "Swing Lo/Hi", "ATR Stop"])
i_SPL=input(defval=10, title="Swing Point Lookback")
i_PercIncrement=input(defval=3, step=.1, title="Swing Point SL Perc Increment")*0.01
i_ATR = input(14, title="ATR Length")
i_ATRMult = input(3, step=.1, title="ATR Multiple")
i_TPRRR = input(2, step=.1, title="Take Profit Risk Reward Ratio")
DPR=input(false, "Allow Direct Position Reverse")
reverse=input(true, "Reverse Trades")
// Swing Points Stop and Take Profit
SwingStopProfit() =>
LL=(lowest(i_SPL))*(1-i_PercIncrement)
HH=(highest(i_SPL))*(1+i_PercIncrement)
LL_price = valuewhen(bought, LL, 0)
HH_price = valuewhen(bought, HH, 0)
entry_LL_price = strategy.position_size > 0 ? LL_price : na
entry_HH_price = strategy.position_size < 0 ? HH_price : na
tp=strategy.position_avg_price + (strategy.position_avg_price - entry_LL_price)*i_TPRRR
stp=strategy.position_avg_price - (entry_HH_price - strategy.position_avg_price)*i_TPRRR
[entry_LL_price, entry_HH_price, tp, stp]
// ATR Stop
ATRStop() =>
ATR=atr(i_ATR)*i_ATRMult
ATRLong = ohlc4 - ATR
ATRShort = ohlc4 + ATR
ATRLongStop = valuewhen(bought, ATRLong, 0)
ATRShortStop = valuewhen(bought, ATRShort, 0)
LongSL_ATR_price = strategy.position_size > 0 ? ATRLongStop : na
ShortSL_ATR_price = strategy.position_size < 0 ? ATRShortStop : na
ATRtp=strategy.position_avg_price + (strategy.position_avg_price - LongSL_ATR_price)*i_TPRRR
ATRstp=strategy.position_avg_price - (ShortSL_ATR_price - strategy.position_avg_price)*i_TPRRR
[LongSL_ATR_price, ShortSL_ATR_price, ATRtp, ATRstp]
// Strategy Stop
StrategyStop(bought) =>
float LongStop = na
float ShortStop = na
float StratTP = na
float StratSTP = na
[LongStop, ShortStop, StratTP, StratSTP]
//TrailingStop
TrailingStop(SL,SSL) =>
dif=(valuewhen(strategy.position_size>0 and strategy.position_size[1]<=0, high,0))
-strategy.position_avg_price
trailOffset = strategy.position_avg_price - SL
var tstop = float(na)
if strategy.position_size > 0
tstop := high- trailOffset - dif
if tstop<tstop[1]
tstop:=tstop[1]
else
tstop := na
StrailOffset = SSL - strategy.position_avg_price
var Ststop = float(na)
Sdif=strategy.position_avg_price-(valuewhen(strategy.position_size<0
and strategy.position_size[1]>=0, low,0))
if strategy.position_size < 0
Ststop := low+ StrailOffset + Sdif
if Ststop>Ststop[1]
Ststop:=Ststop[1]
else
Ststop := na
[tstop, Ststop]
//Stop Loss & Take Profit Switches
SLTPLogic(LongStop, ShortStop, StratTP, StratSTP, LongSL_ATR_price, ShortSL_ATR_price, ATRtp, ATRstp,
entry_LL_price, entry_HH_price, tp, stp) =>
SL= i_SLType == "Swing Lo/Hi" ? entry_LL_price : i_SLType == "ATR Stop" ? LongSL_ATR_price : LongStop
SSL= i_SLType == "Swing Lo/Hi" ? entry_HH_price : i_SLType == "ATR Stop" ? ShortSL_ATR_price : ShortStop
TP= i_SLType == "Swing Lo/Hi" ? tp : i_SLType == "ATR Stop" ? ATRtp : StratTP
STP= i_SLType == "Swing Lo/Hi" ? stp : i_SLType == "ATR Stop" ? ATRstp : StratSTP
[SL, SSL, TP, STP]
/////////////////////// STRATEGY LOGIC /////////////////////////////////////////
rsi = rsi(close, rsiLen)
isOB= rsi > i_OB
isOS= rsi < i_OS
BarsSinceOB = barssince(not isOB)
BarsSinceOS = barssince(not isOS)
BUY = BarsSinceOS == i_delay
SELL = BarsSinceOB == i_delay
/////////////////////// FUNCTION CALLS /////////////////////////////////////////
// Stops and Profits
[entry_LL_price, entry_HH_price, tp, stp] = SwingStopProfit()
[LongSL_ATR_price, ShortSL_ATR_price, ATRtp, ATRstp] = ATRStop()
[LongStop, ShortStop, StratTP, StratSTP] = StrategyStop(bought)
[SL, SSL, TP, STP] = SLTPLogic(LongStop, ShortStop, StratTP, StratSTP,
LongSL_ATR_price, ShortSL_ATR_price, ATRtp, ATRstp, entry_LL_price, entry_HH_price, tp, stp)
[tstop, Ststop] = TrailingStop(SL,SSL)
// Entries
if reverse
if not DPR
strategy.entry("long", strategy.long, when=SELL and strategy.position_size == 0)
strategy.entry("short", strategy.short, when=BUY and strategy.position_size == 0)
else
strategy.entry("long", strategy.long, when=SELL)
strategy.entry("short", strategy.short, when=BUY)
else
if not DPR
strategy.entry("long", strategy.long, when=BUY and strategy.position_size == 0)
strategy.entry("short", strategy.short, when=SELL and strategy.position_size == 0)
else
strategy.entry("long", strategy.long, when=BUY)
strategy.entry("short", strategy.short, when=SELL)
// Exits
if i_SL
strategy.exit("TP & SL", "long", limit=TP, stop=TS? tstop : SL)
strategy.exit("TP & SL", "short", limit=STP, stop=TS? Ststop : SSL)
if i_Close
strategy.close_all(when=cross(rsi, 50))
/////////////////////// PLOTS //////////////////////////////////////////////////
//Plots
rsiplot = plot(rsi, "RSI", color=#7E57C2)
band1 = hline(i_OB, "Upper Band", color=#787B86)
bandm = hline(50, "Middle Band", color=color.new(#787B86, 50))
band0 = hline(i_OS, "Lower Band", color=#787B86)
fill(band1, band0, color=color.rgb(126, 87, 194, 90), title="Background")
plot(rsi, "RSI", color=#7E57C2)
// OSOBCount = plot(isOB ? BarsSinceOB : isOS ? BarsSinceOS : na, transp=100)
// OSOBColor = color.from_gradient(isOB ? BarsSinceOB : BarsSinceOS, 0, 20, color.black, isOB ? color.red : isOS ? color.green : na)
// OBP = plot(rsi > i_OB ? rsi : na, color=color.white, display=display.none)
// fill(plot(i_OB, display=display.none), OBP, color=OSOBColor, transp=0, fillgaps=false)
// OSP = plot(rsi < i_OS ? rsi : na, color=color.white, display=display.none)
// fill(plot(i_OS, display=display.none), OSP, color=OSOBColor, transp=0, fillgaps=false)
// plotshape(BUY ? 1 : na, style=shape.arrowdown, location=location.bottom,
// color=color.green, title="Bullish Setup", size=size.normal)
// plotshape(SELL ? 1 : na, style=shape.arrowup, location=location.top,
// color=color.red, title="Bearish Setup", size=size.normal)