//@version=4
study("Supertrend", overlay = true, format=format.price, precision=2, resolution="")

Periods = input(title="ATR Period", type=input.integer, defval=10)
src = input(hl2, title="Source")
Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)
changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)
showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true)
highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)
atr2 = sma(tr, Periods)
atr= changeATR ? atr(Periods) : atr2
up=src-(Multiplier*atr)
up1 = nz(up,up)
up := close > up1 ? max(up,up1) : up
dn=src+(Multiplier*atr)
dn1 = nz(dn, dn)
dn := close < dn1 ? min(dn, dn1) : dn
trend = 1
trend := nz(trend, trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)
buySignal = trend == 1 and trend == -1
plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)
plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)
dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)
sellSignal = trend == -1 and trend == 1
plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)
plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)
mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)
longFillColor = highlighting ? (trend == 1 ? color.green : color.white) : color.white
shortFillColor = highlighting ? (trend == -1 ? color.red : color.white) : color.white
fill(mPlot, upPlot, title="UpTrend Highligter", color=longFillColor)
fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)
alertcondition(buySignal, title="SuperTrend Buy", message="SuperTrend Buy!")
alertcondition(sellSignal, title="SuperTrend Sell", message="SuperTrend Sell!")
changeCond = trend != trend
alertcondition(changeCond, title="SuperTrend Direction Change", message="SuperTrend has changed direction!")


//destek
left = 50
right = 25
quick_right = 5 // Used to try and detect a more recent significant swing.

pivot_high = pivothigh(high, left, right)
pivot_lows = pivotlow(low, left, right)

quick_pivot_high = pivothigh(high, left, quick_right)
quick_pivot_lows = pivotlow(low, left, quick_right)

level1 = valuewhen(quick_pivot_high, high, 0)
level2 = valuewhen(quick_pivot_lows, low, 0)
level3 = valuewhen(pivot_high, high, 0)
level4 = valuewhen(pivot_lows, low, 0)
level5 = valuewhen(pivot_high, high, 1)
level6 = valuewhen(pivot_lows, low, 1)
level7 = valuewhen(pivot_high, high, 2)
level8 = valuewhen(pivot_lows, low, 2)

level1_col = close >= level1 ? color.green : color.red
level2_col = close >= level2 ? color.green : color.red
level3_col = close >= level3 ? color.green : color.red
level4_col = close >= level4 ? color.green : color.red
level5_col = close >= level5 ? color.green : color.red
level6_col = close >= level6 ? color.green : color.red
level7_col = close >= level7 ? color.green : color.red
level8_col = close >= level8 ? color.green : color.red

plot(level1, style=plot.style_circles, color=level1_col, show_last=3, linewidth=3, trackprice=true)
plot(level2, style=plot.style_circles, color=level2_col, show_last=3, linewidth=3, trackprice=true)
plot(level3, style=plot.style_circles, color=level3_col, show_last=3, linewidth=3, trackprice=true)
plot(level4, style=plot.style_circles, color=level4_col, show_last=3, linewidth=3, trackprice=true)
plot(level5, style=plot.style_circles, color=level5_col, show_last=3, linewidth=3, trackprice=true)
plot(level6, style=plot.style_circles, color=level6_col, show_last=3, linewidth=3, trackprice=true)
plot(level7, style=plot.style_circles, color=level7_col, show_last=3, linewidth=3, trackprice=true)
plot(level8, style=plot.style_circles, color=level8_col, show_last=3, linewidth=3, trackprice=true)
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.