
이것은 RSI 지표와 EMA 평균선에 기반한 동적 위조 거래 전략이다. 이 전략은 쌍 RSI 시간 주기 ((RSI-14 및 RSI-2) 을 삼중 EMA 평균선 ((50·100·200) 과 결합하여 시장의 추세 반전 기회를 포착하고, 동적 포지션 관리로 상쇄 효과를 달성한다. 이 전략의 핵심 특징은 진입 조건이 충족될 때 포지션을 점진적으로 증가시키며, 동시에 RSI에 기반한 과매 과매의 정지 조건을 설정한다.
이 전략은 RSI-14과 RSI-2의 서로 다른 시기의 상대적으로 강한 지수를 사용하여 EMA-50, EMA-100 및 EMA-200의 세 개의 평행선과 함께 거래 신호를 결정합니다. 다중 조건은 RSI-14이 31보다 낮고 RSI-2이 10을 상향으로 돌파하며 3 개의 평행선이 공백 배열을 표시하도록 요구합니다.
이는 동력과 추세를 결합한 종합적인 전략으로, 다중 기술 지표의 조합을 통해 거래의 정확성을 향상시킵니다. 전략의 혁신은 동적인 포지션 관리 방식과 헤지 메커니즘을 채택하는 데 있습니다, 그러나 동시에 더 높은 위험을 수반합니다. 위험 제어 메커니즘을 최적화하고 더 많은 필터링 조건을 도입함으로써 전략은 실제 거래에서 더 나은 성과를 낼 것으로 예상됩니다. 실제 수다를 사용하기 전에 충분한 피드백과 변수 최적화를 권장합니다.
/*backtest
start: 2024-11-26 00:00:00
end: 2024-12-03 00:00:00
period: 10m
basePeriod: 10m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Custom RSI EMA Strategy Hedge", overlay=true, default_qty_type=strategy.fixed, default_qty_value=1)
// Definování vstupních podmínek
rsi_14 = ta.rsi(close, 14)
rsi_2 = ta.rsi(close, 2)
ema_50 = ta.ema(close, 50)
ema_100 = ta.ema(close, 100)
ema_200 = ta.ema(close, 200)
// Pákový efekt
leverage = 20
// Podmínky pro long pozici
longCondition = (rsi_14[1] < 31) and ta.crossover(rsi_2, 10) and (ema_50 < ema_100) and (ema_100 < ema_200)
// Podmínky pro short pozici
shortCondition = (rsi_14[1] > 69) and ta.crossunder(rsi_2, 90) and (ema_50 > ema_100) and (ema_100 > ema_200)
// Identifikátory pozic
long_id = "Long"
short_id = "Short"
// Definování průměrné ceny pozice pro long a short
var float long_avg_price = na
var float short_avg_price = na
// Sledujeme, zda se velikost pozice změnila
var float last_long_position_size = na
var float last_short_position_size = na
// Přerušení průměrné ceny pozice při změně pozice
if (last_long_position_size != strategy.position_size and strategy.position_size > 0)
long_avg_price := na
if (last_short_position_size != strategy.position_size and strategy.position_size < 0)
short_avg_price := na
// Aktualizace průměrné ceny pozice
if (strategy.position_size > 0)
long_avg_price := strategy.position_avg_price
else
long_avg_price := na
if (strategy.position_size < 0)
short_avg_price := strategy.position_avg_price
else
short_avg_price := na
// Uložení aktuální velikosti pozice pro příští bar
if (strategy.position_size > 0)
last_long_position_size := strategy.position_size
else if (strategy.position_size < 0)
last_short_position_size := strategy.position_size
// Podmínky pro take profit
takeProfitLongCondition = (rsi_14 > 69) and (rsi_2 > 90) and (long_avg_price < close)
takeProfitShortCondition = (rsi_14 < 31) and (rsi_2 < 10) and (short_avg_price > close)
// Velikost pozice
new_long_position_size = strategy.position_size == 0 ? na : math.abs(strategy.position_size) * 2
new_short_position_size = strategy.position_size == 0 ? na : math.abs(strategy.position_size) * 2
// Úprava velikosti pozice s ohledem na pákový efekt
position_value = strategy.equity * leverage
trade_qty_long = position_value / close
trade_qty_short = position_value / close
// Vstup do long pozice s dvojnásobkem aktuální pozice nebo standardní velikostí při první pozici
if (longCondition)
strategy.entry(long_id, strategy.long, qty=new_long_position_size == na ? trade_qty_long : new_long_position_size)
// Vstup do short pozice s dvojnásobkem aktuální pozice nebo standardní velikostí při první pozici
if (shortCondition)
strategy.entry(short_id, strategy.short, qty=new_short_position_size == na ? trade_qty_short : new_short_position_size)
// Výstup z long pozice při splnění podmínek pro take profit
if (takeProfitLongCondition)
strategy.close(long_id)
// Výstup z short pozice při splnění podmínek pro take profit
if (takeProfitShortCondition)
strategy.close(short_id)
// Zvýraznění části grafu, kde platí podmínky pro long
highlightLongCondition = (ema_50 < ema_100) and (ema_100 < ema_200)
bgcolor(highlightLongCondition ? color.new(color.green, 90) : na)
// Zvýraznění části grafu, kde platí podmínky pro short
highlightShortCondition = (ema_50 > ema_100) and (ema_100 > ema_200)
bgcolor(highlightShortCondition ? color.new(color.red, 90) : na)
// Přidání bodů pozic do grafu
plotshape(series=longCondition, location=location.belowbar, color=color.green, style=shape.labelup, text="L")
plotshape(series=shortCondition, location=location.abovebar, color=color.red, style=shape.labeldown, text="S")
// Vykreslení průměrné ceny pozice pro long a short pouze pokud pozice existuje
plot(strategy.position_size > 0 ? long_avg_price : na, title="Long Avg Price", color=color.blue, linewidth=2)
plot(strategy.position_size < 0 ? short_avg_price : na, title="Short Avg Price", color=color.orange, linewidth=2)
// Zvýraznění čtverců pro RSI14 > 70 (červeně) a RSI14 < 30 (zeleně)
var int rsi_above_70_start = na
var int rsi_below_30_start = na
var float top_value_above_70 = na
var float bottom_value_above_70 = na
var float top_value_below_30 = na
var float bottom_value_below_30 = na
// Identifikace začátku a konce období pro RSI14 > 70
if (rsi_14[1] > 70 and rsi_14[2] > 70)
if na(rsi_above_70_start)
rsi_above_70_start := bar_index
top_value_above_70 := high
bottom_value_above_70 := low
else
top_value_above_70 := math.max(top_value_above_70, high)
bottom_value_above_70 := math.min(bottom_value_above_70, low)
else
if not na(rsi_above_70_start)
// box.new(left = rsi_above_70_start, right = bar_index - 1, top = top_value_above_70, bottom = bottom_value_above_70, border_color = color.red, border_width = 2, bgcolor=color.new(color.red, 90))
rsi_above_70_start := na
top_value_above_70 := na
bottom_value_above_70 := na
// Identifikace začátku a konce období pro RSI14 < 30
if (rsi_14[1] < 30 and rsi_14[2] < 30)
if na(rsi_below_30_start)
rsi_below_30_start := bar_index
top_value_below_30 := high
bottom_value_below_30 := low
else
top_value_below_30 := math.max(top_value_below_30, high)
bottom_value_below_30 := math.min(bottom_value_below_30, low)
else
if not na(rsi_below_30_start)
// box.new(left = rsi_below_30_start, right = bar_index - 1, top = top_value_below_30, bottom = bottom_value_below_30, border_color = color.green, border_width = 2, bgcolor=color.new(color.green, 90))
rsi_below_30_start := na
top_value_below_30 := na
bottom_value_below_30 := na