//@version=4
study("TPS BUY SELL", overlay = true)
Periods = input(title="ATR Period", type=[Link], defval=10)
src = input(hl2, title="Source")
Multiplier = input(title="ATR Multiplier", type=[Link], step=0.1, defval=3.0)
changeATR= input(title="Change ATR Calculation Method ?", type=[Link],
defval=true)
showsignals = input(title="Show Buy/Sell Signals ?", type=[Link], defval=true)
highlighting = input(title="Highlighter On/Off ?", type=[Link], 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=[Link])
buySignal = trend == 1 and trend[1] == -1
plotshape(buySignal ? up : na, title="UpTrend Begins", location=[Link],
style=[Link], size=[Link], color=[Link], transp=0)
plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy",
location=[Link], style=[Link], size=[Link], color=[Link],
textcolor=[Link], transp=0)
dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr,
linewidth=2, color=[Link])
sellSignal = trend == -1 and trend[1] == 1
plotshape(sellSignal ? dn : na, title="DownTrend Begins",
location=[Link], style=[Link], size=[Link], color=[Link],
transp=0)
plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell",
location=[Link], style=[Link], size=[Link], color=[Link],
textcolor=[Link], transp=0)
mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)
longFillColor = highlighting ? (trend == 1 ? [Link] : [Link]) :
[Link]
shortFillColor = highlighting ? (trend == -1 ? [Link] : [Link]) :
[Link]
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!")
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////
len = input(50, "Hull MA Lenght")
hullMA_close = ema(2 * ema(hl2, len / 2) - ema(hl2, len), round(sqrt(len)))
hullMA_open = ema(2 * ema(open, len / 2) - ema(open, len), round(sqrt(len)))
longCond = crossover(hullMA_close , hullMA_open)
shortCond = crossunder(hullMA_close, hullMA_open)
// Plotting
coLor = hullMA_close > hullMA_open ? [Link] : [Link]
hclose = plot(hullMA_close, title="Close Series", color = coLor, linewidth = 1)
hopen = plot(hullMA_open, title="Open Series", color = coLor, linewidth = 1)
fill(hclose, hopen, color = coLor, transp = 70)
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////