Settings = {
Name = "*BB (Bollinger Bands) %B oscillator",
Period = 20,
Metod = «SMA», --(SMA, MMA, EMA, WMA, SMMA, VMA)
VType = «Close», --(Open, High, Low, Close, Volume, Median, Typical, Weighted, Difference)
Shift=2,
line = {{
Name = «Horizontal line (top)»,
Type = TYPE_LINE,
Color = RGB(221, 44, 44)
},
{
Name = «Horizontal line (bottom)»,
Type = TYPE_LINE,
Color = RGB(221, 44, 44)
},
{
Name = «Bollinger Bands %B oscillator line»,
Type = TYPE_LINE,
Color = RGB(255, 255, 255)
}
},
Round = «off»,
Multiply = 1,
Horizontal_line=«0»
}
function Init()
func = BB_B()
return #Settings.line
end
function OnCalculate(Index)
local Out = ConvertValue(Settings, func(Index, Settings))
local HL = tonumber(Settings.Horizontal_line)
if HL then
return 1+HL,HL,Out
else
return nil,nil,Out
end
end
function BB_B() --Bollinger Bands %B oscillator («BB_B»)
local BB_MA=MA()
local BB_SD=SD()
local it = {p=0, l=0}
return function (I, Fsettings, ds)
local Fsettings=(Fsettings or {})
local P = (Fsettings.Period or 20)
local M = (Fsettings.Metod or SMA)
local S = (Fsettings.Shift or 2)
local VT = (Fsettings.VType or CLOSE)
if (P > 0) then
if I == 1 then
it = {p=0, l=0}
end
local b_ma = BB_MA(I, {Period=P, Metod = M, VType=VT}, ds)
local b_sd = BB_SD(I, {Period=P, Metod = SMA, VType=VT}, ds)
if CandleExist(I,ds) then
if I~=it.p then it={p=I, l=it.l+1} end
if it.l >= P and b_ma and b_sd then