//@version=4
//Tiếng Việt Mua Bán Version Chăn Trâu Phố Tường Rev A March 11-2022 Edited by Tu Nguyen. Original Dan Đang
// Copyright (c) 2019-present, Alex Orekhov (everget)
// Chandelier Exit script may be freely distributed under the terms of the GPL-3.0 license.
study("Chandelier Exit Mod", shorttitle="CE Mod", overlay=true)

length = input(title="ATR Period", type=input.integer, defval=1)
mult = input(title="ATR Multiplier", type=input.float, step=0.1, defval=1.8)
showLabels = input(title="Show Buy/Sell Labels ?", type=input.bool, defval=true)
useClose = input(title="Use Close Price for Extremums ?", type=input.bool, defval=false)
highlightState = input(title="Highlight State ?", type=input.bool, defval=false)

atr = mult * atr(length)

longStop = (useClose ? highest(close, length) : highest(length)) - atr
longStopPrev = nz(longStop, longStop)
longStop := close > longStopPrev ? max(longStop, longStopPrev) : longStop

shortStop = (useClose ? lowest(close, length) : lowest(length)) + atr
shortStopPrev = nz(shortStop, shortStop)
shortStop := close < shortStopPrev ? 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

//longStopPlot = plot(dir == 1 ? longStop : na, title="Long Stop", style=plot.style_linebr, linewidth=2, color=longColor)
buySignal = dir == 1 and dir == -1
//plotshape(buySignal ? longStop : na, title="Long Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=longColor, transp=0)
plotshape(buySignal and showLabels ? longStop : na, title="Buy Label", text="Mua", location=location.belowbar, style=shape.labelup, size=size.small, color=longColor, textcolor=color.red, transp=0)

//shortStopPlot = plot(dir == 1 ? na : shortStop, title="Short Stop", style=plot.style_linebr, linewidth=2, color=shortColor)
sellSignal = dir == -1 and dir == 1
//plotshape(sellSignal ? shortStop : na, title="Short Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=shortColor, transp=0)
plotshape(sellSignal and showLabels ? shortStop : na, title="Sell Label", text="Bán", location=location.abovebar, style=shape.labeldown, size=size.small, color=shortColor, textcolor=color.white, transp=0)

midPricePlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0, display=display.none, editable=false)

//longFillColor = highlightState ? (dir == 1 ? longColor : na) : na
//shortFillColor = highlightState ? (dir == -1 ? shortColor : na) : na
//fill(midPricePlot, longStopPlot, title="Long State Filling", color=longFillColor)
//fill(midPricePlot, shortStopPlot, title="Short State Filling", color=shortFillColor)

changeCond = dir != dir

myrsi = rsi(open, 10)
buyrsi = myrsi < 30

alertcondition(changeCond, title="Alert: CE Direction Change", message="Chandelier Exit has changed direction!")
alertcondition(buySignal and buyrsi , title="Alert: CE Buy", message="Chandelier Exit Buy & RSI < 30")
alertcondition(sellSignal, title="Alert: CE Sell", message="Chandelier Exit Sell!")
Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.