Не пойму, в чем проблема..
Выдает ошибку attempt to compare number with nil когда индикатор растет или падает и не обнаруживает пиков\впадин
При успешном обнаружении пика\впадины выдает текстовое сообщение как положено
Код:
require("w32")
Settings = {
Tiker = "\210\232\234\229\240",
Name = "Kalman SndMsg",
Mode = 6,
KF = 50,
line = {
{
Name = "Kalman",
Color = RGB(0, 255, 0),
Type = TYPE_LINE,
Width = 2
}
}
}
function Init()
return 1
end
i = 0
value = 0
count = 0
function OnCalculate(_ARG_0_)
if _ARG_0_ == 1 then
kalman ={}
Distance = 0
Error = 0
value = dValue(1, Settings.Mode)
Velocity = 0
i = 0
count = Size()
end
if _ARG_0_ > 1 then
if _ARG_0_ > i then
i = _ARG_0_
Distance = dValue(i, Settings.Mode) - value
Error = value + Distance * math.sqrt(Settings.KF / 1000)
Velocity = Velocity + Distance * (Settings.KF / 1000)
value = Error + Velocity
kalman[i] = value
if kalman[i-1] < kalman[i-2] and kalman[i-2] >= kalman[i-3] then
if _ARG_0_ >= count then
message(Settings.Tiker .. ": DOWN trend", 1)
w32.MessageBeep(w32.MB_OK)
count = _ARG_0_
end
end
if kalman[i-1] > kalman[i-2] and kalman[i-2] <= kalman[i-3] then
if _ARG_0_ >= count then
message(Settings.Tiker .. ": UP trend", 1)
w32.MessageBeep(w32.MB_OK)
count = _ARG_0_
end
end
end
end
return kalman[i]
end
function dValue(_ARG_0_, _ARG_1_)
if (_ARG_1_ or 0) == 1 then
return O(_ARG_0_)
elseif (_ARG_1_ or 0) == 2 then
return H(_ARG_0_)
elseif (_ARG_1_ or 0) == 3 then
return L(_ARG_0_)
elseif (_ARG_1_ or 0) == 0 then
return C(_ARG_0_)
elseif (_ARG_1_ or 0) == 4 then
return (H(_ARG_0_) + L(_ARG_0_)) / 2
elseif (_ARG_1_ or 0) == 5 then
return (H(_ARG_0_) + L(_ARG_0_) + C(_ARG_0_)) / 3
elseif (_ARG_1_ or 0) == 6 then
return (H(_ARG_0_) + L(_ARG_0_) + 2 * C(_ARG_0_)) / 4
else
return C(_ARG_0_)
end
end
Выдает ошибку attempt to compare number with nil когда индикатор растет или падает и не обнаруживает пиков\впадин
При успешном обнаружении пика\впадины выдает текстовое сообщение как положено
Код:
require("w32")
Settings = {
Tiker = "\210\232\234\229\240",
Name = "Kalman SndMsg",
Mode = 6,
KF = 50,
line = {
{
Name = "Kalman",
Color = RGB(0, 255, 0),
Type = TYPE_LINE,
Width = 2
}
}
}
function Init()
return 1
end
i = 0
value = 0
count = 0
function OnCalculate(_ARG_0_)
if _ARG_0_ == 1 then
kalman ={}
Distance = 0
Error = 0
value = dValue(1, Settings.Mode)
Velocity = 0
i = 0
count = Size()
end
if _ARG_0_ > 1 then
if _ARG_0_ > i then
i = _ARG_0_
Distance = dValue(i, Settings.Mode) - value
Error = value + Distance * math.sqrt(Settings.KF / 1000)
Velocity = Velocity + Distance * (Settings.KF / 1000)
value = Error + Velocity
kalman[i] = value
if kalman[i-1] < kalman[i-2] and kalman[i-2] >= kalman[i-3] then
if _ARG_0_ >= count then
message(Settings.Tiker .. ": DOWN trend", 1)
w32.MessageBeep(w32.MB_OK)
count = _ARG_0_
end
end
if kalman[i-1] > kalman[i-2] and kalman[i-2] <= kalman[i-3] then
if _ARG_0_ >= count then
message(Settings.Tiker .. ": UP trend", 1)
w32.MessageBeep(w32.MB_OK)
count = _ARG_0_
end
end
end
end
return kalman[i]
end
function dValue(_ARG_0_, _ARG_1_)
if (_ARG_1_ or 0) == 1 then
return O(_ARG_0_)
elseif (_ARG_1_ or 0) == 2 then
return H(_ARG_0_)
elseif (_ARG_1_ or 0) == 3 then
return L(_ARG_0_)
elseif (_ARG_1_ or 0) == 0 then
return C(_ARG_0_)
elseif (_ARG_1_ or 0) == 4 then
return (H(_ARG_0_) + L(_ARG_0_)) / 2
elseif (_ARG_1_ or 0) == 5 then
return (H(_ARG_0_) + L(_ARG_0_) + C(_ARG_0_)) / 3
elseif (_ARG_1_ or 0) == 6 then
return (H(_ARG_0_) + L(_ARG_0_) + 2 * C(_ARG_0_)) / 4
else
return C(_ARG_0_)
end
end