You are on page 1of 3

//@version=4

//Basic Hull Ma Pack tinkered by InSilico


study("Hull Suite by InSilico and Supertrend", overlay=true)

//INPUT
src = input(close, title="Source")
modeSwitch = input("Hma", title="Hull Variation", options=["Hma", "Thma", "Ehma"])
length = input(55, title="Length(180-200 for floating S/R , 55 for swing entry)")
lengthMult = input(1.0, title="Length multiplier (Used to view higher timeframes
with straight band)")

useHtf = input(false, title="Show Hull MA from X timeframe? (good for scalping)")


htf = input("240", title="Higher timeframe", type=input.resolution)

switchColor = input(true, "Color Hull according to trend?")


candleCol = input(false,title="Color candles based on Hull's Trend?")
visualSwitch = input(true, title="Show as a Band?")
thicknesSwitch = input(1, title="Line Thickness")
transpSwitch = input(40, title="Band Transparency",step=5)

//FUNCTIONS
//HMA
HMA(_src, _length) => wma(2 * wma(_src, _length / 2) - wma(_src, _length),
round(sqrt(_length)))
//EHMA
EHMA(_src, _length) => ema(2 * ema(_src, _length / 2) - ema(_src, _length),
round(sqrt(_length)))
//THMA
THMA(_src, _length) => wma(wma(_src,_length / 3) * 3 - wma(_src, _length / 2) -
wma(_src, _length), _length)

//SWITCH
Mode(modeSwitch, src, len) =>
modeSwitch == "Hma" ? HMA(src, len) :
modeSwitch == "Ehma" ? EHMA(src, len) :
modeSwitch == "Thma" ? THMA(src, len/2) : na

//OUT
_hull = Mode(modeSwitch, src, int(length * lengthMult))
HULL = useHtf ? security(syminfo.ticker, htf, _hull) : _hull
MHULL = HULL[0]
SHULL = HULL[2]

//COLOR
hullColor = switchColor ? (HULL > HULL[2] ? #00ff00 : #ff0000) : #ff9800

//PLOT
///< Frame
Fi1 = plot(MHULL, title="MHULL", color=hullColor, linewidth=thicknesSwitch,
transp=50)
Fi2 = plot(visualSwitch ? SHULL : na, title="SHULL", color=hullColor,
linewidth=thicknesSwitch, transp=50)
alertcondition(crossover(MHULL, SHULL), title="Hull trending up.", message="Hull
trending up.")
alertcondition(crossover(SHULL, MHULL), title="Hull trending down.", message="Hull
trending down.")
///< Ending Filler
fill(Fi1, Fi2, title="Band Filler", color=hullColor, transp=transpSwitch)
///BARCOLOR
barcolor(color = candleCol ? (switchColor ? hullColor : na) : na)

// Trend Magic
// period=input(20,"CCI period")
// coeff=input(1,"ATR Multiplier")
// AP=input(5,"ATR Period")
// ATR=sma(tr,AP)
// srcTM=input(close)
// upT=low-ATR*coeff
// downT=high+ATR*coeff
// MagicTrend=0.0
// MagicTrend := cci(srcTM,period)>=0 ? (upT<nz(MagicTrend[1]) ?
nz(MagicTrend[1]) : upT) : (downT>nz(MagicTrend[1]) ? nz(MagicTrend[1]) : downT)
// color1= cci(srcTM,period)>=0 ? #0022FC : #FC0400
// plot(MagicTrend, title="MagicTrend", color=color1, linewidth=3)
// alertcondition(cross(close, MagicTrend), title="Cross Alert", message="Price -
MagicTrend Crossing!")
// alertcondition(crossover(low, MagicTrend), title="CrossOver Alarm", message="BUY
SIGNAL!")
// alertcondition(crossunder(high, MagicTrend), title="CrossUnder Alarm",
message="SELL SIGNAL!")

// Supertrend
Periods = input(title="ATR Period", type=input.integer, defval=10)
src_hs = input(close, title="Source")
Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=2.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_hs-(Multiplier*atr)
up1 = nz(up[1],up)
up := close[1] > up1 ? max(up,up1) : up
dn=src_hs+(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!")

You might also like