
トレンド追跡移動平均RSI戦略は,トレンド分析と超買い超売り指標を同時に利用する株式自動取引戦略である.この戦略は,単純な移動平均を使用して市場のトレンド方向を判断し,比較的強い指数 ((RSI) 指数と組み合わせて取引信号を発信し,トレンドの判断と追跡を実現する.
この戦略は主に3つの部分から構成されています.
トレンド判断: 長期トレンドの200日単調移動平均を計算し,短期トレンドの30日および50日単調移動平均を計算する.短期移動平均線上を長期移動平均線を横切るときは看板の信号として,下を横切るときは下落の信号として,市場の長期短期トレンドを判断する.
超買超売判断:14日RSIを計算し,RSI80以上は超買区,20未満は超売区である. RSIが超買区から下落するか,超売区から上昇するときに取引信号を発信する.
入場と出場:超買超売信号を判断する際,トレンド判断の信号方向と一致する場合は,入場は多/空にする.短期と長期の移動平均が金色の交差点が発生する際,判断トレンドが逆転し,平仓出場する.
この戦略により,株価が逆転した時に間に合うように入場し,傾向判断と組み合わせて一部のノイズ取引をフィルターし,逆戻り制御において比較的優れている.
この戦略の利点は以下の通りです.
この戦略にはいくつかのリスクがあります.
この戦略は,以下の点で最適化できます.
トレンドトラッキングの移動平均RSI戦略は,全体的に非常に実用的な戦略的考えであり,傾向分析と超買い超売り指標を組み合わせると,ある程度市場の騒音をフィルターし,取引信号をより正確に有効にします.この戦略は,手段とパラメータを継続的に最適化することで,安定した収益性の高い長期的な取引システムになることができます.
/*backtest
start: 2022-11-16 00:00:00
end: 2023-11-22 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mattehalen
// INPUT per TIMEFRAME
// 5min = Legnth = 9, Source = ohlc4,MaxLoss = 1000 TrendMA = 200, ShortMA = 4, LongMA = 10
// 30min = Legnth = 7, Source = ohlc4,MaxLoss = 1000 TrendMA = 200, ShortMA = 10, LongMA = 20
strategy("Mathias & Christer Timeframe RSI", shorttitle="M&C_RSI",overlay=true, process_orders_on_close = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)
len = input(9, title="Length", type=input.integer)
src = input(ohlc4, title="Source", type=input.source)
//show4h = input(true, title="show 4h", type=input.bool)
maxLoss = input(3000)
rsiCurrent = rsi(src, len)
//rsi4h = security(syminfo.ticker, "240", rsi(src, len))
rsi4h = rsi(src, len)
//--------------------------------------------------
//MA
trendMAInput = input(200, title="trendMA", type=input.integer)
shortMAInput = input(30, title="shortMA", type=input.integer)
longMAInput = input(50, title="longMA", type=input.integer)
trendMA = ema(close,trendMAInput)
shortMA = ema(close,shortMAInput)
longMA = ema(close,longMAInput)
plot(trendMA, color=color.black, linewidth=5)
plot(shortMA, color=color.red, linewidth=2)
plot(longMA, color=color.green, linewidth=2)
bgcolor(crossunder(shortMA,longMA) ? color.black : na, transp=10)
//--------------------------------------------------
//RSI
BuySignalBarssince = barssince(rsi4h[1]<rsi4h[0] and rsi4h[1]<20)
BuySignal = (rsi4h[1]<rsi4h[0] and rsi4h[1]<20 and BuySignalBarssince[1]>10)
BuySignalOut = crossunder(longMA[1],shortMA[1])
bgcolor(BuySignal ? color.green : na, transp=70)
bgcolor(BuySignalOut ? color.green : na, transp=10)
SellSignalBarssince = barssince(rsi4h[1]>rsi4h[0] and rsi4h[1]>80)
SellSignal = (rsi4h[1]>rsi4h[0] and rsi4h[1]>80 and SellSignalBarssince[1]>10)
SellSignalOut = crossunder(shortMA[1],longMA[1])
bgcolor(SellSignal ? color.red : na, transp=70)
bgcolor(SellSignalOut ? color.red : na, transp=10)
if BuySignal
strategy.close("short", comment = "Exit short")
strategy.entry("long", true)
strategy.exit("Max Loss", "long", loss = maxLoss)
if BuySignalOut
strategy.close("long", comment = "Exit Long")
if SellSignal
// Enter trade and issue exit order on max loss.
strategy.close("long", comment = "Exit Long")
strategy.entry("short", false)
strategy.exit("Max Loss", "short", loss = maxLoss)
if SellSignalOut
// Force trade exit.
strategy.close("short", comment = "Exit short")
//--------------------------------------------------
//ATR
MyAtr = atr(10)
AtrFactor = 10
mySLBuy = close[BuySignalBarssince]
mySLSell = close[SellSignalBarssince]
plotchar(BuySignal, "BuySignal", "⬆", location.belowbar, color.lime,size =size.huge )
plotchar(BuySignalOut, "BuySignalOut", "█", location.belowbar, color.lime,size =size.small)
plotchar(SellSignal, "SellSignal", "⬇", location.abovebar ,color.red,size =size.huge)
plotchar(SellSignalOut, "SellSignalOut", "█", location.abovebar, color.red,size =size.small)