Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=6
- // Combined by Kordan
- // Version 2
- indicator(title="Chandelier Exit + RSIDiff + EMA Indicators", shorttitle="CE+RSID+EMA", format=format.price, precision=2)
- ////////////////////////////////////////////////////////////////////////////////////////
- // ======================================================
- // Differencial RSI Indicators - отдельная панель
- //=======================================================
- // Входные параметры для RSI
- var string GroupRSI = 'Differencial RSI Indicators'
- rsiFastLength = input.int(25, minval=1, title="RSI Fast", group=GroupRSI)
- rsiSlowLength = input.int(100, minval=2, title="RSI Slow", group=GroupRSI)
- // Проверка на корректность значений и вывод предупреждения
- var label warningLabel = na // Переменная для метки предупреждения
- if (rsiSlowLength <= rsiFastLength)
- // Удаляем предыдущую метку, если она существует
- if (not na(warningLabel))
- label.delete(warningLabel)
- // Создаем новую метку предупреждения
- warningLabel := label.new(bar_index-100, na, "Ошибка! : RSI Slow должен быть > RSI Fast", color=color.red, style=label.style_label_down)
- else
- // Удаляем метку предупреждения, если значения корректны
- if (not na(warningLabel))
- label.delete(warningLabel)
- // Функция для расчета RSI
- f_rsi(source, length) =>
- change = ta.change(source)
- up = ta.rma(math.max(change, 0), length)
- down = ta.rma(-math.min(change, 0), length)
- down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
- // Расчет RSI и их разности
- rsiSlow = f_rsi(close, rsiSlowLength)
- rsiFast = f_rsi(close, rsiFastLength)
- rsiDifference = rsiFast - rsiSlow
- colB = color.red
- colS = color.green
- // Отрисовка линий
- plot(0, "Zero Level", color=color.silver, editable=false)
- plot(rsiDifference, "RSI Difference", style=plot.style_histogram, color=(rsiDifference > 0 ? colS : colB), editable=false)
- ////////////////////////////////////////////////////////////////////////////////////////
- //=======================================================
- // Chandelier Exit Indicator
- //=======================================================
- var string calcGroupCE = 'Chandelier Exit Indicator'
- // Группа параметров для визуализации и оповещений
- showLabels = input.bool(title='Показать Buy/Sell Labels', defval=true, group=calcGroupCE)
- length = input.int(title='ATR Period', defval=1, group=calcGroupCE)
- mult = input.float(title='ATR Multiplier', step=0.1, defval=1.85, group=calcGroupCE)
- // Расчет ATR и уровней стоп-лоссов
- atr = mult * ta.atr(length)
- longStop = ta.highest(high, length) - atr
- longStopPrev = nz(longStop[1], longStop)
- longStop := close[1] > longStopPrev ? math.max(longStop, longStopPrev) : longStop
- shortStop = ta.lowest(low, length) + atr
- shortStopPrev = nz(shortStop[1], shortStop)
- shortStop := close[1] < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop
- // Определение направления тренда
- var int dir = 1
- dir := close > shortStopPrev ? 1 : close < longStopPrev ? -1 : dir
- // Цвета для визуализации
- var color longColor = color.green
- var color shortColor = color.red
- var color textColor = color.white
- // Условия для сигналов покупки и продажи
- buySignal = dir == 1 and dir[1] == -1
- sellSignal = dir == -1 and dir[1] == 1
- plotshape(buySignal and showLabels ? longStop : na, title='Buy Label', text='Buy', location=location.absolute,
- style=shape.labelup, size=size.tiny, color=longColor, textcolor=textColor,
- force_overlay=true, editable=false)
- plotshape(sellSignal and showLabels ? shortStop : na, title='Sell Label', text='Sell', location=location.absolute,
- style=shape.labeldown, size=size.tiny, color=shortColor,textcolor=textColor,
- force_overlay=true, editable=false)
- // Условия для оповещений
- awaitCondition = barstate.isconfirmed
- alertcondition(dir != dir[1] and awaitCondition , title='Alert: CE Direction Change' , message='Chandelier Exit has changed direction!')
- alertcondition(buySignal and awaitCondition , title='Alert: CE Buy' , message='Chandelier Exit Buy!')
- alertcondition(sellSignal and awaitCondition , title='Alert: CE Sell' , message='Chandelier Exit Sell!')
- ////////////////////////////////////////////////////////////////////////////////////////
- //=======================================================
- // EMA Indicator
- //=======================================================
- var string calcGroupEMA = 'EMA Indicator'
- len = input.int(50, minval=1, title="EMA Period", group=calcGroupEMA)
- plot(ta.ema(close, len), title="EMA", color=color.orange, offset=0, linewidth=2,force_overlay=true)
- ////////////////////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement