Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
3.1 kB
2
Indexable
Never
//@version=5
//
// @RD
// 2018-10-5
indicator(title='Double Bollinger Bands BY RD', shorttitle='DBB By RD', overlay=true)

//------------------------------ Inputs ------------------------------


length = input(20, title='length')
src = input(close, title='source')
std_dev_1 = input(1, title='BB1 stdDev')
std_dev_2 = input(2, title='BB2 stdDev')
offset = input(0, title='offset')

//ema lenta
len = input.int(260, minval=1, title="Length Ema Lenta")
offsetema = input.int(title="Offset Ema Lenta", defval=0, minval=-500, maxval=500)
out = ta.ema(src, len)
plot(out, title="EMA LENTA", color=color.black, offset=offsetema)

ma(source, length, type) =>
    switch type
        "SMA" => ta.sma(source, length)
        "EMA" => ta.ema(source, length)
        "SMMA (RMA)" => ta.rma(source, length)
        "WMA" => ta.wma(source, length)
        "VWMA" => ta.vwma(source, length)

typeMA = input.string(title = "Method", defval = "SMA", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="Smoothing")
smoothingLength = input.int(title = "Length", defval = 5, minval = 1, maxval = 100, group="Smoothing")

smoothingLine = ma(out, smoothingLength, typeMA)
plot(smoothingLine, title="Smoothing Line", color=#f37f20, offset=offset, display=display.none)


//------------------------------ Colors ------------------------------

color_gray = #eeeeee
color_green = #3fbe53
color_red = #ff4e3e

//------------------------------- Logic ------------------------------

median = ta.sma(src, length)
standard_deviation = ta.stdev(src, length)

standard_deviation_1 = standard_deviation * std_dev_1
upper_1 = median + standard_deviation_1
lower_1 = median - standard_deviation_1

standard_deviation_2 = standard_deviation * std_dev_2
upper_2 = median + standard_deviation_2
lower_2 = median - standard_deviation_2



//------------------------- Plotting & styling ------------------------

transp_bb_1 = 98
transp_bb_2 = 94

basis = plot(median, color=color.new(color_gray, 0), title='basis', offset=offset)

upper_band_1 = plot(upper_1, color=color_red, title='BB1 upper', offset=offset, transp=transp_bb_1)
lower_band_1 = plot(lower_1, color=color_green, title='BB1 lower', offset=offset, transp=transp_bb_1)

fill(basis, upper_band_1, color=color_red, title='background BB1 upper', transp=transp_bb_1)
fill(basis, lower_band_1, color=color_green, title='background BB1 lower', transp=transp_bb_1)

upper_band_2 = plot(upper_2, color=color_red, title='BB2 upper', offset=offset, transp=transp_bb_2)
lower_band_2 = plot(lower_2, color=color_green, title='BB2 lower', offset=offset, transp=transp_bb_2)

fill(upper_band_1, upper_band_2, color=color_red, title='background BB2 upper', transp=transp_bb_2)
fill(lower_band_1, lower_band_2, color=color_green, title='background BB2 lower', transp=transp_bb_2)
if close > upper_1 and close[1] < upper_1[1]
    alert('Upper1')
if close > upper_2 and close[1] < upper_2[1]
    alert('Upper2')
if close < lower_1 and close[1] > lower_1[1]
    alert('Lower1')
if close < lower_2 and close[1] > lower_2[1]
    alert('Lower2')