RSI 가격 차이 정량적 전략 지표 동적 모니터링 및 적응 최적화 시스템

RSI TP SL
생성 날짜: 2025-01-10 16:20:25 마지막으로 수정됨: 2025-01-10 16:20:25
복사: 5 클릭수: 421
avatar of ChaoZhang ChaoZhang
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!")