
트렌드를 추적하는 이동 평균 RSI 전략은 동향 분석과 오버 바이 오버 시드 지표를 동시에 사용하는 주식 자동 거래 전략이다. 이 전략은 간단한 이동 평균을 사용하여 시장의 경향 방향을 판단하고, 상대적으로 강한 지수 ((RSI) 지표와 결합하여 거래 신호를 발산하여 트렌드를 판단하고 추적한다.
이 전략은 크게 세 부분으로 구성됩니다.
트렌드 판단: 장기 트렌드의 200일 간단한 이동 평균을 계산하고, 단기 트렌드의 30일 및 50일 간단한 이동 평균을 계산한다. 단기 이동 평균 상에서 장기 이동 평균을 가로질러 낙관 신호로, 아래로 가로질러 낙하 신호로 시장의 장기 단기 트렌드를 판단한다.
오버 바이 오버 셀 판단: 14일 RSI를 계산하여, RSI가 80보다 높으면 오버 바이 지역이고, 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)