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
--
-- Выполнение действий с массивами.
--
local pairs = pairs
local type = type
module(...)
--- Создать копию массива (таблицы)
-- @return копию массива (таблицы)
function copy(array)
local copy_array = {}
if type(array) ~= "table" then
return array
end
for k, v in pairs(array) do
if type(v) == "table" then
copy_array[k] = copy(v)
else
copy_array[k] = v
end
end
return copy_array
end
--- Узнать, начинается ли индексация в массиве с нуля или с единицы.
-- @return 0 или 1
function base(array)
if array[0] ~= nil then
return 0
else
return 1
end
end
--- Вычислить число элементов в массиве.
-- @return число элементов в массиве
function size(array)
local n = 0
for _, _ in pairs(array) do
n = n + 1
end
return n
end
--- Проверить пустой или нет массив.
-- @return true/false
function isEmpty(array)
for _, _ in pairs(array) do
return false
end
return true
end
--- Получить первый индекс массива, где ничего не записано. Поиск начинается с 1.
-- @return первый индекс массива, где ничего не записано
function firstEmptyIndex(array)
local i = 1
while array[i] ~= nil do
i = i + 1
end
return i
endСамый простой, по сути код. Но Lua выдаёт ошибку при компилировании без function main(), при том что Quik выполняет этот код без конструкции main или function. Раньше такой ошибки не было.message(«a»)
------------------------------Output------------------------------
>lua -e «io.stdout:setvbuf 'no'» «a.lua»
lua: a.lua:1: attempt to call global 'message' (a nil value)
stack traceback:
a.lua:1: in main chunk
[C]: ?
>Exit code: 1