0% found this document useful (1 vote)
175 views

BB Signal

This document contains the source code for a trading script that includes multiple indicators: 1) It defines functions to calculate a normalized moving average (NMA) using two standard moving averages. 2) It plots the NMA, VWAP, Bollinger Bands, and Kahlman-adjusted Hull Moving Average trends. 3) Alerts are triggered when the long and short Hull MA plots cross, signaling buys and sells.

Uploaded by

sukabumi junior
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
175 views

BB Signal

This document contains the source code for a trading script that includes multiple indicators: 1) It defines functions to calculate a normalized moving average (NMA) using two standard moving averages. 2) It plots the NMA, VWAP, Bollinger Bands, and Kahlman-adjusted Hull Moving Average trends. 3) Alerts are triggered when the long and short Hull MA plots cross, signaling buys and sells.

Uploaded by

sukabumi junior
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// https://t.

me/vip_binary_indicators

//@version=4
// Moving Average 3.0 (3rd Generation) script may be freely distributed under the
MIT license. Copyright (c) 2018-present, (everget)
study("IDEAL BB with MA (With Alerts)", overlay=true)

length1 = input(title="1st Length", type=input.integer, minval=1, defval=120)


length2 = input(title="2nd Length", type=input.integer, minval=1, defval=12)
maInput = input(title="MA Type", defval="EMA", options=["EMA", "SMA", "VWMA",
"WMA"])
src = input(title="Source", type=input.source, defval=hl2)

getMA(src, length) =>


ma = 0.0

if maInput == "EMA"
ma := ema(src, length)

if maInput == "SMA"
ma := sma(src, length)

if maInput == "VWMA"
ma := vwma(src, length)

if maInput == "WMA"
ma := wma(src, length)
ma

getNMA(src, length1, length2) =>


lambda = length1 / length2
alpha = lambda * (length1 - 1) / (length1 - lambda)

ma1 = getMA(src, length1)


ma2 = getMA(ma1, length2)

nma = (1 + alpha) * ma1 - alpha * ma2

nma = getNMA(src, length1, length2)


//emaLength = input(90, minval=1, title="EMA Length")
//emaSource = input(close, title="EMA Source")
//ema = ema(emaSource, emaLength)

plot(nma, title="NMA Black Line", linewidth=2, style=plot.style_stepline,


color=color.black, transp=0)
//plot(ema, title="EMA", linewidth=1, color=color.red, transp=0)

//VWAP BANDS
lenvwap = input(1, minval=1, title="VWAP Length")
src1a = input(close, title="VWAP Source")
offsetvwap = input(title="VWAP Offset", type=input.integer, defval=0, minval=-500,
maxval=500)
srcvwap = hlc3
vvwap = vwap(srcvwap)
line1 = sma(src1a, lenvwap)
plot(vvwap, color=#e91e63, linewidth=2, style=plot.style_line, title="VWAP MIDDLE")

// Boll Bands
emaSource = close
emaPeriod = 20
devMultiple = 2
baseline = sma(emaSource, emaPeriod)
plot(baseline, title = "BB Red Line", color = color.red)
stdDeviation = devMultiple * (stdev(emaSource, emaPeriod))
upperBand = (baseline + stdDeviation)
lowerBand = (baseline - stdDeviation)
p1 = plot(upperBand, title = "BB Top", color = color.blue)
p2 = plot(lowerBand, title = "BB Bottom", color = #311b92)
fill(p1, p2, color = color.blue)

//HULL TREND WITH KAHLMAN


srchull = input(hl2, "Price Data")
lengthhull = input(24, "Lookback")
showcross = input(true, "Show cross over/under")
gain = input(10000, "Gain")
k = input(true, "Use Kahlman")

hma(_srchull, _lengthhull) =>


wma((2 * wma(_srchull, _lengthhull / 2)) - wma(_srchull, _lengthhull),
round(sqrt(_lengthhull)))

hma3(_srchull, _lengthhull) =>


p = lengthhull/2
wma(wma(close,p/3)*3 - wma(close,p/2) - wma(close,p),p)

kahlman(x, g) =>
kf = 0.0
dk = x - nz(kf[1], x)
smooth = nz(kf[1],x)+dk*sqrt((g/10000)*2)
velo = 0.0
velo := nz(velo[1],0) + ((g/10000)*dk)
kf := smooth+velo

a = k ? kahlman(hma(srchull, lengthhull), gain) : hma(srchull, lengthhull)


b = k ? kahlman(hma3(srchull, lengthhull), gain) : hma3(srchull, lengthhull)
c = b > a ? color.lime : color.red
crossdn = a > b and a[1] < b[1]
crossup = b > a and b[1] < a[1]

p1hma = plot(a,color=c,linewidth=1,transp=75, title="Long Plot")


p2hma = plot(b,color=c,linewidth=1,transp=75, title="Short Plot")
fill(p1hma,p2hma,color=c,transp=55,title="Fill")
plotshape(showcross and crossdn ? a : na, location=location.abovebar,
style=shape.labeldown, color=color.red, size=size.tiny, text="Sell",
textcolor=color.white, transp=0, offset=-1)
plotshape(showcross and crossup ? a : na, location=location.belowbar,
style=shape.labelup, color=color.green, size=size.tiny, text="Buy",
textcolor=color.white, transp=0, offset=-1)

//ALERTS
alertcondition(crossup, title='Buy', message='Go Long')
alertcondition(crossdn, title='Sell', message='Go Short')

You might also like