
Strategi ini merancang satu sistem perdagangan automatik yang lebih terbuka berdasarkan indeks yang agak kuat (RSI). Ia boleh mengeluarkan isyarat yang lebih terbuka secara automatik untuk perdagangan automatik apabila RSI mencapai kawasan overbought dan oversold.
Strategi ini menghasilkan nilai RSI dalam julat 0-100 dengan mengira kenaikan dan penurunan saham dalam tempoh tertentu. Apabila RSI berada di bawah 30, ia adalah keadaan jual beli, dan apabila ia berada di atas 70, ia adalah keadaan beli beli.
Khususnya, strategi pertama mengira nilai RSI 15 kitaran. Apabila RSI turun ke bawah 20, dianggap sebagai keadaan oversold, ketika itu masuk ke atas 200 hari pergerakan rata-rata. Apabila RSI naik ke lebih dari 80, dianggap sebagai keadaan overbuy, ketika itu masuk ke dalam kosong.
Selain itu, strategi ini juga menggambarkan garis tanda dan label yang berkaitan dengan isyarat harga, menjadikan isyarat perdagangan lebih intuitif.
Langkah-langkah kawalan risiko termasuk: mengoptimumkan parameter RSI, menyesuaikan nilai terhad overbought dan oversold untuk pelbagai jenis, menetapkan titik hentian yang munasabah, dan mengelakkan perdagangan yang bertentangan dengan indikator trend.
Strategi overall adalah strategi perdagangan automatik yang menggunakan RSI untuk menilai overbought dan oversold. Ia menghantar isyarat perdagangan apabila RSI mencapai kawasan melampau overbought dan oversold, dan boleh melakukan operasi membeli dan menjual secara automatik. Strategi ini mudah difahami, mudah dilaksanakan, dan sesuai sebagai strategi asas perdagangan automatik.
/*backtest
start: 2023-10-22 00:00:00
end: 2023-10-29 00:00:00
period: 15m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("RSI Improved strategy", overlay=true)
higherTF1 = input.timeframe('15' , "Resolution", options = ['5', '15', '1H', 'D', 'W', 'M'])
dailyopen = request.security(syminfo.tickerid, higherTF1, close)
Reward = input(1600)
Risk = input(1600)
length = input( 5 )
overSold = input( 30 )
overBought = input( 70 )
EMA = input(200)
price = close
vrsi = ta.rsi(price, length)
RSIlowest = vrsi[1] > vrsi ? true : false
RSIhighest = vrsi[1] < vrsi ? true : false
//ro = ta.crossunder(vrsi, 20)
//ru = ta.crossover(vrsi, 80)
co = ta.crossunder(vrsi, overSold)
cu = ta.crossunder(vrsi, overBought)
plot(ta.ema(close, EMA))
plot(ta.ema(close, 50), color = color.orange)
UponEMA = close > ta.ema(close, EMA) ? true : false
belowEMA = close < ta.ema(close, EMA) ? true : false
//transfer 'float' to 'int' to 'string'
r = int(vrsi)
value = str.tostring(r)
m = int(strategy.openprofit)
money = str.tostring(m)
if (not na(vrsi))
//when price stand up on 200ema and rsi is at oversold area, open long position
// if (co and UponEMA)
// strategy.order("Rsi long", strategy.long, 1 , comment = "Rsi long")
if(vrsi < 20 and RSIlowest)
// line1 = line.new(x1=bar_index, y1=dailyopen, x2=bar_index+1, y2=dailyopen, xloc=xloc.bar_index, style=line.style_solid,extend=extend.right, color=color.aqua, width = 2)
// line.delete(line1[1]) // remove the previous line when new bar appears
// label1 = label.new(x=bar_index, y=dailyopen,yloc=yloc.belowbar, text = value,textcolor = color.white, color = color.green, style = label.style_label_up)
// label.delete(label1[1])
strategy.order("Rsi long", strategy.long, 1 , comment = "Rsi long")
strategy.exit("exit", "Rsi long", profit = Reward, loss = Risk, comment = "Rsi long exit")
//strategy.close("Rsi short", comment = "Rsi close")
if(vrsi > 80 and RSIhighest)
// line2 = line.new(x1=bar_index, y1=dailyopen, x2=bar_index+1, y2=dailyopen, xloc=xloc.bar_index, style=line.style_solid,extend=extend.right, color = #e65100, width = 2)
// line.delete(line2[1]) // remove the previous line when new bar appears
// label2 = label.new(x=bar_index, y=dailyopen,yloc=yloc.abovebar, text = value, textcolor = color.white, color = color.red)
// label.delete(label2[1])
strategy.order("Rsi short",strategy.short, 1, comment = "Rsi short ")
strategy.exit("exit", "Rsi short", profit = Reward,loss = Risk, comment = "Rsi short exit")
// if(UponEMA)
// strategy.close("Rsi short", comment = "Rsi short close")
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_cross)
//plotshape(confirmPH, title="Label",offset = 1,text="Bull",style=shape.labeldown,location=location.abovebar,color=color.green,textcolor=color.green)
//when Rsi reaches overbought, draw a Horizontal Ray to close prices, similarly when it comes to oversold.(accomplished)
//detects when there is more lower/higher RSI values, adjust horizontal Ray and label to new posistion.(accomplished)