//@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[1],up)
up := close[1] > up1 ? max(up,up1) : up
dn=src+(Multiplier*atr)
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? min(dn, dn1) : dn
trend = 1
trend := nz(trend[1], 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] == -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] == 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[1]
alertcondition(changeCond, title="SuperTrend Direction Change",
message="SuperTrend has changed direction!")
lookback1 = input(defval=5, title='# of Candles to Look Back')
lookback2 = input(defval=10, title='# of Candles to Look Back')
lookback3 = input(defval=20, title='# of Candles to Look Back')
src2 = 'Close'
pivothigh_1 = pivothigh(high, lookback1, lookback1)
pivothigh_2 = pivothigh(high, lookback1, lookback1)
pivot_high1 = src2 == 'Close' ? pivothigh_1 : pivothigh_2
pivotlow_1 = pivotlow(low, lookback1, lookback1)
pivotlow_2 = pivotlow(low, lookback1, lookback1)
pivot_low1 = src2 == 'Close' ? pivotlow_1 : pivotlow_2
pivothigh_3 = pivothigh(high, lookback2, lookback2)
pivothigh_4 = pivothigh(high, lookback2, lookback2)
pivot_high2 = src2 == 'Close' ? pivothigh_3 : pivothigh_4
pivotlow_3 = pivotlow(low, lookback2, lookback2)
pivotlow_4 = pivotlow(low, lookback2, lookback2)
pivot_low2 = src2 == 'Close' ? pivotlow_3 : pivotlow_4
pivothigh_5 = pivothigh(high, lookback3, lookback3)
pivothigh_6 = pivothigh(high, lookback3, lookback3)
pivot_high3 = src2 == 'Close' ? pivothigh_5 : pivothigh_6
pivotlow_5 = pivotlow(low, lookback3, lookback3)
pivotlow_6 = pivotlow(low, lookback3, lookback3)
pivot_low3 = src2 == 'Close' ? pivotlow_5 : pivotlow_6
valuewhen_1 = valuewhen(pivot_high1, high[lookback1], 0)
valuewhen_2 = valuewhen(pivot_high1, high[lookback1], 0)
plot_high1 = src2 == 'Close' ? valuewhen_1 : valuewhen_2
valuewhen_3 = valuewhen(pivot_low1, low[lookback1], 0)
valuewhen_4 = valuewhen(pivot_low1, low[lookback1], 0)
plot_low1 = src2 == 'Close' ? valuewhen_3 : valuewhen_4
valuewhen_5 = valuewhen(pivot_high2, high[lookback2], 0)
valuewhen_6 = valuewhen(pivot_high2, high[lookback2], 0)
plot_high2 = src2 == 'Close' ? valuewhen_5 : valuewhen_6
valuewhen_7 = valuewhen(pivot_low2, low[lookback2], 0)
valuewhen_8 = valuewhen(pivot_low2, low[lookback2], 0)
plot_low2 = src2 == 'Close' ? valuewhen_7 : valuewhen_8
valuewhen_9 = valuewhen(pivot_high3, high[lookback3], 0)
valuewhen_10 = valuewhen(pivot_high3, high[lookback3], 0)
plot_high3 = src2 == 'Close' ? valuewhen_9 : valuewhen_10
valuewhen_11 = valuewhen(pivot_low3, low[lookback3], 0)
valuewhen_12 = valuewhen(pivot_low3, low[lookback3], 0)
plot_low3 = src2 == 'Close' ? valuewhen_11 : valuewhen_12
resistance1 = plot(plot_high1, style=plot.style_line, title='R1',
color=color.new(color.white, 0), show_last=1, linewidth=1, trackprice=true)
support1 = plot(plot_low1, style=plot.style_line, title='S1',
color=color.new(color.white, 0), show_last=1, linewidth=1, trackprice=true)
resistance2 = plot(plot_high2, style=plot.style_line, title='R2',
color=color.new(color.yellow, 0), show_last=1, linewidth=2, trackprice=true)
support2 = plot(plot_low2, style=plot.style_line, title='S2',
color=color.new(color.yellow, 0), show_last=1, linewidth=2, trackprice=true)
resistance3 = plot(plot_high3, style=plot.style_line, title='R3',
color=color.new(color.orange, 0), show_last=1, linewidth=3, trackprice=true)
support3 = plot(plot_low3, style=plot.style_line, title='S3',
color=color.new(color.orange, 0), show_last=1, linewidth=3, trackprice=true)
alertcondition(close > plot_high1, title='Price Over Resistance 1',
message='Price Over Resistance 1')
alertcondition(close < plot_low1, title='Price Under Support 1',
message='Price Under Support 1')
alertcondition(close > plot_high2, title='Price Over Resistance 2',
message='Price Over Resistance 2')
alertcondition(close < plot_low2, title='Price Under Support 2',
message='Price Under Support 2')
alertcondition(close > plot_high3, title='Price Over Resistance 3',
message='Price Over Resistance 3')
alertcondition(close < plot_low3, title='Price Under Support 3',
message='Price Under Support 3')
ema1 = input(34, minval=1, maxval=300, title="EMA UpTrend")
shema = input(true, title="Show EMA Trend is Based On?")
usedEma = ema(close, ema1)
emaUpColor() => hlc3 >= usedEma
emaDownColor() => hlc3 < usedEma
col = hlc3 >= usedEma ? color.lime : hlc3 < usedEma ? color.red : color.white
barcolor(emaUpColor() ? color.lime: emaDownColor() ? color.red : na)
plot(shema and usedEma ? usedEma : na, title="EMA",linewidth=3, color=col)
//More important indicator list
//Smart Money Concepts [LuxAlgo]
//Nadaraya-Watson Envelope [LuxAlgo]
//RSI Primed [ChartPrime]
//Volume
No comments:
Post a Comment