이 전략은 EMA와 RSI의 두 지표를 결합하여 트렌드 방향을 식별하고 입출구를 한다. 가격이 EMA 위에 있고 RSI가 매수점보다 낮을 때 부어; 가격이 EMA 아래에 있고 RSI가 매수점보다 높을 때 부어. 또한 마지막 두 K 선의 종결 가격 크기와 관계로 트렌드 방향을 결정하고 트렌드 거래를 실현한다.
200일 EMA를 계산하여 트렌드를 판단하는 평균선 지표로 . EMA는 가격 변화에 빠르게 반응하여 트렌드 방향을 효과적으로 판단할 수 있다.
14일 RSI를 계산하여 과매매를 판단한다. RSI가 50보다 낮으면 과매매로 간주되며, 50보다 높으면 과매매로 간주된다. RSI의 상향 하향 경향을 결합하여 구매 시기를 판단한다.
마지막 두 개의 K 선의 종전 가격 크기와 관계를 비교하여 트렌드 방향을 판단한다. 마지막 두 개의 종전 가격 증가 추세는 상승 추세이며, 감소 추세는 하락 추세이다.
상승 추세에 있을 때, 가격이 200일 EMA보다 높고, RSI가 50보다 낮고 상승할 때, 구매 신호를 발산한다.
하향 추세에 있을 때, 가격이 200일 EMA보다 낮고, RSI가 50보다 높고 하향할 때, 판매 신호를 낸다.
ATR과 최근 14개의 K 라인의 최고 가격, 최저 가격은 스톱로즈와 스톱스톱을 계산하기 위해 사용된다.
이동적 손실을 방지하는 전략으로 위험을 통제하십시오.
이중 지표는 트렌드 방향을 판단하여 정확도를 높인다. EMA는 주 트렌드를 판단하고, RSI와 K 라인 관계는 지역 트렌드를 판단하고 매매 시기를 판단한다.
RSI 지표는 가짜 브레이크를 효과적으로 피한다. RSI의 공백 상태는 EMA 지표의 지연으로 인한 불필요한 거래를 피한다.
이동 중지 손실은 개별적으로 큰 진폭 변동으로 인한 손실을 효과적으로 제어한다.
최적화 된 변수 조합은 정책 변수가 더 강하다는 것을 의미합니다.
큰 진폭의 진동 상황에서, EMA와 RSI는 잘못된 신호를 생성할 가능성이 높으며, 이러한 상황을 피해야 한다.
스톱포인트가 너무 작으면 과도한 스톱포인트 손실이 발생할 수 있으며, 스톱포인트가 너무 크면 손실을 제어하기 어렵다. ATR 파라미터를 적절히 조정해야 한다.
낮에 EMA를 돌파한 후 다시 조정될 가능성이 높으며, RSI 파라미터를 적절히 완화하여 트렌드를 놓치지 않도록 해야 한다.
ATR 변수와 스톱 거리를 적절히 조정하여 더 나은 스톱 포인트를 찾습니다.
EMA와 RSI 지표 파라미터를 최적화하여 더 적합한 파라미터 조합을 찾습니다.
MACD, 브린 띠 등과 같은 다른 보조 지표를 추가하여 필터링하여 신호의 정확성을 향상시킵니다.
다양한 품종의 파라미터 설정의 차이를 테스트할 수 있으며, 파라미터의 안정성을 더욱 향상시킬 수 있다.
특정 기간 동안 전략을 종료하여 잘못된 신호가 발생할 수 있는 기간을 피하십시오.
이 전략은 전반적으로 안정적이며, 수익도 안정적이며, 최대 회수율과 샤프율도 매우 우수하다. 변수 최적화와 스톱포인트 조정으로 전략의 효과를 더욱 높일 수 있다. 또한 특정 상황에서 발생할 수 있는 잘못된 신호에 주의를 기울여야 하며, 보조 지표 또는 시간 필터를 통해 이러한 상황을 피한다. 이 전략은 지속적인 최적화를 통해 장기적으로 보유할 가치가 있는 안정적인 전략이 될 가능성이 있다.
/*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))