Strategi ini menggabungkan kedua-dua petunjuk EMA dan RSI untuk mengenal pasti arah trend dan melakukan perdagangan masuk dan keluar. Harga naik apabila harga berada di atas EMA dan RSI berada di bawah titik beli; turun apabila harga berada di bawah EMA dan RSI berada di atas titik jual.
Hitung EMA 200 hari, sebagai penunjuk garis rata untuk menilai trend. EMA bertindak balas dengan cepat terhadap perubahan harga, dapat menentukan arah trend dengan berkesan.
Hitung RSI 14 hari untuk menentukan sama ada terlalu banyak membeli atau terlalu banyak menjual. RSI di bawah 50 dianggap sebagai terlalu banyak menjual, di atas 50 dianggap sebagai terlalu banyak membeli.
Bandingkan hubungan saiz harga penutupan dua garis K terakhir, untuk menentukan arah trend. Dua harga penutupan terakhir dianggap meningkat dalam trend menaik, dan penurunan dianggap dalam trend menurun.
Apabila berada dalam trend menaik, harga berada di atas 200 hari EMA dan RSI berada di bawah 50 dan menaik, isyarat beli dikeluarkan.
Apabila berada dalam trend menurun, harga di bawah 200 hari EMA dan RSI di atas 50 dan turun, isyarat jual dikeluarkan.
ATR dan harga tertinggi dan terendah bagi 14 garis K terkini digunakan untuk mengira titik berhenti dan titik berhenti.
Menggunakan strategi henti rugi bergerak untuk mengawal risiko.
Penunjuk ganda menggabungkan arah trend untuk menilai keakuratan. EMA menentukan trend utama, RSI dan K-baris untuk menentukan trend tempatan dan masa untuk membeli dan menjual.
Indeks RSI berkesan mengelakkan penembusan palsu. Dengan keadaan kosong RSI, ia mengelakkan perdagangan yang tidak perlu yang disebabkan oleh ketinggalan EMA.
Hentian bergerak berkesan mengawal kerugian yang disebabkan oleh turun naik amplitudo besar individu.
Kombinasi parameter yang dioptimumkan menjadikan parameter strategi lebih kuat.
Dalam keadaan gegaran amplitudo tinggi, EMA dan RSI mempunyai kebarangkalian yang lebih besar untuk menghasilkan isyarat yang salah, dan tindakan seperti itu harus dielakkan.
Stop loss yang terlalu kecil mudah menyebabkan stop loss yang terlalu kerap; stop loss yang terlalu besar sukar untuk mengawal kerugian. Parameter ATR harus disesuaikan dengan sewajarnya.
Kemungkinan besar untuk penyesuaian semula selepas pecah EMA pada waktu siang, ketika ini parameter RSI harus dilonggarkan dengan sewajarnya untuk mengelakkan kehilangan trend.
Menyesuaikan parameter ATR dan jarak hentian dengan betul untuk mencari titik hentian yang lebih baik.
Optimumkan parameter EMA dan RSI untuk mencari kombinasi parameter yang lebih sesuai.
Tambahan penapis penapis lain seperti MACD, Brinband dan lain-lain untuk meningkatkan ketepatan isyarat.
Anda boleh menguji perbezaan dalam parameter yang ditetapkan untuk pelbagai varieti untuk meningkatkan lagi kestabilan parameter.
Anda boleh cuba untuk menutup strategi dalam tempoh masa tertentu, mengelakkan tempoh masa yang mudah menghasilkan isyarat yang salah.
Strategi ini secara keseluruhan stabil, pendapatan stabil, maksimum pulangan balik dan kadar Sharp juga sangat baik. Dengan pengoptimuman parameter dan penyesuaian titik hentian, anda boleh meningkatkan lagi kesan strategi.
/*backtest
start: 2023-01-01 00:00:00
end: 2023-08-10 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
// strategy("EMA RSI Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=1)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Author : AJ Rupasinghege
// Date : 06/11/2022
// Release : v6.0
// Description : If the last two closes are in ascending order, the rsi is below 50 and ascending, and the current candle is above 200 ema, then LONG.
// If the last two closes are in descending order, the rsi is above 50 and descending, and the current candle is below 200 ema, then SHORT.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////// INPUTS //////////////////////////////////////////////////////////////
ema_length = input(200, "EMA Length")
rsi_buy_value = input(50, "RSI Buy Value")
rsi_sell_value = input(50, "RSI Sell Value")
show_data = input.bool(0, "Show Data")
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////// VARIABLES //////////////////////////////////////////////////////////
var stop_loss = 0.0
var last_trade_entry_price = 0.0
var low_value= 0.0
var atr = 0.0
var high_value = 0.0
var stop_loss_points = 0.0
var limit = 0.0
var bar_id_entry = 0
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////// FUNCTIONS //////////////////////////////////////////////////////////
getTradeConditionsLong() =>
//@function Used to calculate stop_loss, stop_loss points, limit and label values for long trades
//@param direction (float) // strategy.poistion.size
//@returns stop_loss, stop_loss_points, limit
//@Dependancies low_value, atr, last_trade_entry_price,bar_id_entry
_stop_loss = low_value - atr
_stop_lossPoints = (last_trade_entry_price - _stop_loss) *100000
_limit = last_trade_entry_price + (last_trade_entry_price - low_value + atr)
value = "OpenValue: " + str.tostring(last_trade_entry_price) +
"\n OpenBarIndex: " + str.tostring(bar_id_entry) +
"\n LowValue: " + str.tostring(low_value) +
"\n atr: " + str.tostring(atr) + "\n stop_loss: " +
str.tostring(_stop_loss) + "\n Limit: " +
str.tostring(_limit)
[_stop_loss,_stop_lossPoints,_limit, value]
getTradeConditionsShort() =>
//@function Used to calculate stop_loss, stop_loss points, limit and label values for short trades
//@param direction (float) // strategy.poistion.size
//@returns stop_loss, stop_loss_points, limit
//@Dependancies high_value, atr, last_trade_entry_price,bar_id_entry
_stop_loss = high_value + atr
_stop_lossPoints = (_stop_loss -last_trade_entry_price) * 100000
_limit = last_trade_entry_price - (high_value - last_trade_entry_price + atr)
value = "OpenValue: " + str.tostring(last_trade_entry_price) +
"\n OpenBarIndex: " + str.tostring(bar_id_entry) +
"\n HighValue: " + str.tostring(high_value) +
"\n atr: " + str.tostring(atr) + "\n stop_loss: " +
str.tostring(_stop_loss) + "\n Limit: " +
str.tostring(_limit)
[_stop_loss,_stop_lossPoints,_limit, value]
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////// SIGNALS //////////////////////////////////////////////////////////
ema = ta.ema(close,ema_length)
rsi = ta.rsi(close,14)
ema_buy_signal = ema < low
ema_sell_signal = ema > high
rsi_buy_signal = rsi < rsi_buy_value and rsi[1] < rsi[0]
rsi_sell_signal = rsi > rsi_sell_value and rsi[1] > rsi[0]
trend_buy_signal = close[2] < close[1] and close[1] < close[0]
trend_sell_signal = close[2] > close[1] and close[1] > close[0]
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////// TRADES //////////////////////////////////////////////////////////
long = trend_buy_signal
and ema_buy_signal
and rsi_buy_signal
short = trend_sell_signal
and ema_sell_signal
and rsi_sell_signal
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////// STRATEGY //////////////////////////////////////////////////////////
if long
strategy.entry("Long", strategy.long)
if short
strategy.entry("Short", strategy.short)
// Calculate Trade Entry Variables
last_trade_entry_price := strategy.opentrades.entry_price(strategy.opentrades - 1)
bar_id_entry := strategy.opentrades.entry_bar_index(strategy.opentrades - 1)
atr := ta.atr(14)
low_value := ta.lowest(14)
high_value := ta.highest(14)
// Exit Strategy for Long Positions
if (strategy.position_size[1] != strategy.position_size and strategy.position_size>0)
[_stop_loss,_stop_loss_points, _limit, value] = getTradeConditionsLong()
stop_loss := _stop_loss
stop_loss_points := _stop_loss_points
limit := _limit
if show_data
label.new(bar_id_entry,stop_loss - 0.005,str.tostring(value),xloc = xloc.bar_index,yloc = yloc.price,style = label.style_none)
strategy.exit("Long Exit", "Long", trail_offset = stop_loss_points/2, trail_points = stop_loss_points/2 , stop = stop_loss , limit = limit )
// Exit Strategy for Short Positions
if (strategy.position_size[1] != strategy.position_size and strategy.position_size<0)
[_stop_loss,_stop_loss_points, _limit, value] = getTradeConditionsShort()
stop_loss := _stop_loss
stop_loss_points := _stop_loss_points
limit := _limit
if show_data
label.new(bar_id_entry,stop_loss + 0.005,str.tostring(value),xloc = xloc.bar_index,yloc = yloc.price,style = label.style_none)
strategy.exit("Short Exit", "Short", trail_offset = stop_loss_points/2, trail_points = stop_loss_points/2 , stop = stop_loss , limit = limit )
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////// PLOTS //////////////////////////////////////////////////////////
plot(ema, "SMA", color = color.blue, linewidth = 2 )
p1 = plot(strategy.position_size>0? stop_loss:na, style = plot.style_linebr , color = color.rgb(82, 240, 42) )
p2 = plot(strategy.position_size<0? stop_loss:na, style = plot.style_linebr , color = color.rgb(223, 85, 85) )
p3 = plot(strategy.position_size!=0?limit : na, style = plot.style_linebr , color = color.rgb(94, 85, 223, 100) )
fill(p1, p3, color = color.new(color.green, 90))
fill(p2, p3, color = color.new(#e98787, 90))