Доработал индикатор, внес параметр весовых коэффициентов
Settings=
{
Name = "AT-obl_can", -- название индикатора
delta=2.0, -- параметр индикатора
rep=5,
shif=0,
wt=1,
line=
{
{
Name = "ln1",
Type =TYPE_LINE,
Width = 2,
Color = RGB(255, 0, 0)
},
{
Name = "ln2",
Type =TYPE_LINE,
Width = 2,
Color = RGB(255, 0, 0)
}
}
}
function Init()
vMin = 0
vMax = 0
vMinindex = 0
vMaxindex = 0
voldMinindex = 0
voldMaxindex = 0
return 2
end
function OnCalculate(index)
rep = Settings.rep
shif = Settings.shif
wt = Settings.wt
sz = Size()-shif
if index <= sz then
if index <= 1 then
vMin = C(index)
vMax = C(index)
vMinindex = index
vMaxindex = index
voldMinindex = index
voldMaxindex = index
v = C(index)
else
if voldMaxindex >= voldMinindex then
--if vMin~=nil then
if C(index) > (1 + Settings.delta/100)*vMin then
vMin = C(index)
vMax = C(index)
vMaxindex = index
voldMinindex = vMinindex
vFrom = vMinindex
else
if vMin > C(index) then
vMin = C(index)
vMinindex = index
vFrom = voldMaxindex
else
vFrom = vMinindex
end
end
--end
else
if voldMaxindex <= voldMinindex then
--if vMax~=nil then
if C(index) < (1 - Settings.delta/100)*vMax then
vMax = C(index)
vMin = C(index)
vMinindex = index
voldMaxindex = vMaxindex
vFrom = vMaxindex
else
if vMax < C(index) then
vMax = C(index)
vMaxindex = index
vFrom = voldMinindex
else
vFrom = vMaxindex
end
end
--end
end
end
--if vFrom~=nil then
--[[
for i = vFrom, index do
k = (C(index)- C(vFrom))/(index- vFrom);
v = i*k + C(index) - index*k
SetValue(i, 1, v)
end --]]
--end
if index == sz then
for k = 1, 2 do
vf = 1
vs = 0
if k == 1 then
if vMinindex < vMaxindex then
vf = vMinindex
vs = vMaxindex
up = 0
elseif vMinindex > vMaxindex then
vs = vMinindex
vf = vMaxindex
up = 1
end
elseif k == 2 then
if voldMinindex < voldMaxindex then
vf = voldMinindex
vs = voldMaxindex
up = 0
elseif voldMinindex > voldMaxindex then
vs = voldMinindex
vf = voldMaxindex
up = 1
end
end
n = 0
xy = 0
x = 0
y = 0
xx = 0
m = 0
for i = vf, vs do
m = m +1
n = n + 1*(1+wt*m)
xy = xy + i*C(i)*(1+wt*m)
x = x + i*(1+wt*m)
y = y + C(i)*(1+wt*m)
xx = xx + i*i*(1+wt*m)
end
if (n*xx - x*x) ~= 0 and n ~= 0 then
a = (n*xy - x*y)/(n*xx - x*x)
b = (y - a*x)/n
for j = 1, rep do
n = 0
xy = 0
x = 0
y = 0
xx = 0
m = 0
for i = vf, vs do
v = a*i + b
clc = 0
if up == 1 and C(i) > v then
clc = 1
end
if up == 0 and C(i) < v then
clc = 1
end
if clc == 1 then
m = m + 1
n = n + 1*(1+wt*m)
xy = xy + i*C(i)*(1+wt*m)
x = x + i*(1+wt*m)
y = y + C(i)*(1+wt*m)
xx = xx + i*i*(1+wt*m)
end
end --[[--]]
if (n*xx - x*x) ~= 0 and n ~= 0 and n > 2 then
a = (n*xy - x*y)/(n*xx - x*x)
b = (y - a*x)/n --[[ --]]
end
end
for i = vf, sz do
v = a*i + b
if up == 1 and v >= C(vs) or up == 0 and v <= C(vs) then
SetValue(i, k, v)
end
end
end
end
end
end
end
end
телеграм:
t.me/autotradering