Advertisement
Kordan

Chandelier Exit + RSIDiff + EMA Indicators

Apr 23rd, 2025 (edited)
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
RBScript 5.13 KB | Source Code | 0 0
  1. //@version=6
  2. // Combined by Kordan
  3. // Version 2
  4. indicator(title="Chandelier Exit + RSIDiff + EMA Indicators", shorttitle="CE+RSID+EMA", format=format.price, precision=2)
  5.  
  6. ////////////////////////////////////////////////////////////////////////////////////////
  7.  
  8. // ======================================================
  9. // Differencial RSI Indicators - отдельная панель
  10. //=======================================================
  11.  
  12. // Входные параметры для RSI
  13. var string GroupRSI = 'Differencial RSI Indicators'
  14. rsiFastLength = input.int(25, minval=1, title="RSI Fast", group=GroupRSI)
  15. rsiSlowLength = input.int(100, minval=2, title="RSI Slow", group=GroupRSI)
  16.  
  17. // Проверка на корректность значений и вывод предупреждения
  18. var label warningLabel = na  // Переменная для метки предупреждения
  19.  
  20. if (rsiSlowLength <= rsiFastLength)
  21.     // Удаляем предыдущую метку, если она существует
  22.     if (not na(warningLabel))
  23.         label.delete(warningLabel)
  24.    
  25.     // Создаем новую метку предупреждения
  26.     warningLabel := label.new(bar_index-100, na, "Ошибка! : RSI Slow должен быть > RSI Fast",  color=color.red, style=label.style_label_down)
  27.  
  28. else
  29.     // Удаляем метку предупреждения, если значения корректны
  30.     if (not na(warningLabel))
  31.         label.delete(warningLabel)
  32.  
  33. // Функция для расчета RSI
  34. f_rsi(source, length) =>
  35.     change = ta.change(source)
  36.     up = ta.rma(math.max(change, 0), length)
  37.     down = ta.rma(-math.min(change, 0), length)
  38.     down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
  39.  
  40. // Расчет RSI и их разности
  41. rsiSlow = f_rsi(close, rsiSlowLength)
  42. rsiFast = f_rsi(close, rsiFastLength)      
  43. rsiDifference = rsiFast - rsiSlow
  44.  
  45. colB = color.red
  46. colS = color.green
  47.  
  48. // Отрисовка линий
  49. plot(0, "Zero Level", color=color.silver, editable=false)
  50. plot(rsiDifference, "RSI Difference", style=plot.style_histogram, color=(rsiDifference > 0 ? colS : colB), editable=false)
  51.  
  52. ////////////////////////////////////////////////////////////////////////////////////////
  53.  
  54. //=======================================================
  55. // Chandelier Exit Indicator
  56. //=======================================================
  57.  
  58. var string calcGroupCE = 'Chandelier Exit Indicator'
  59.  
  60. // Группа параметров для визуализации и оповещений
  61. showLabels = input.bool(title='Показать Buy/Sell Labels', defval=true, group=calcGroupCE)
  62.  
  63. length = input.int(title='ATR Period', defval=1, group=calcGroupCE)
  64. mult = input.float(title='ATR Multiplier', step=0.1, defval=1.85, group=calcGroupCE)
  65.  
  66. // Расчет ATR и уровней стоп-лоссов
  67. atr = mult * ta.atr(length)
  68.  
  69. longStop = ta.highest(high, length) - atr
  70. longStopPrev = nz(longStop[1], longStop)
  71. longStop := close[1] > longStopPrev ? math.max(longStop, longStopPrev) : longStop
  72.  
  73. shortStop = ta.lowest(low, length) + atr
  74. shortStopPrev = nz(shortStop[1], shortStop)
  75. shortStop := close[1] < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop
  76.  
  77. // Определение направления тренда
  78. var int dir = 1
  79. dir := close > shortStopPrev ? 1 : close < longStopPrev ? -1 : dir
  80.  
  81. // Цвета для визуализации
  82. var color longColor = color.green
  83. var color shortColor = color.red
  84. var color textColor = color.white
  85.  
  86. // Условия для сигналов покупки и продажи
  87. buySignal = dir == 1 and dir[1] == -1
  88. sellSignal = dir == -1 and dir[1] == 1
  89. plotshape(buySignal and showLabels ? longStop : na, title='Buy Label', text='Buy', location=location.absolute,
  90.           style=shape.labelup, size=size.tiny, color=longColor, textcolor=textColor,
  91.           force_overlay=true, editable=false)
  92. plotshape(sellSignal and showLabels ? shortStop : na, title='Sell Label', text='Sell', location=location.absolute,
  93.           style=shape.labeldown, size=size.tiny, color=shortColor,textcolor=textColor,
  94.           force_overlay=true, editable=false)
  95.  
  96. // Условия для оповещений
  97. awaitCondition = barstate.isconfirmed
  98. alertcondition(dir != dir[1] and awaitCondition , title='Alert: CE Direction Change' , message='Chandelier Exit has changed direction!')
  99. alertcondition(buySignal and awaitCondition , title='Alert: CE Buy' , message='Chandelier Exit Buy!')
  100. alertcondition(sellSignal and awaitCondition , title='Alert: CE Sell' , message='Chandelier Exit Sell!')
  101.  
  102. ////////////////////////////////////////////////////////////////////////////////////////
  103.  
  104. //=======================================================
  105. // EMA Indicator
  106. //=======================================================
  107.  
  108. var string calcGroupEMA = 'EMA Indicator'
  109.  
  110. len = input.int(50, minval=1, title="EMA Period", group=calcGroupEMA)
  111. plot(ta.ema(close, len), title="EMA", color=color.orange, offset=0, linewidth=2,force_overlay=true)
  112.  
  113. ////////////////////////////////////////////////////////////////////////////////////////
Tags: CE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement