Индикатор AT-levels для отрисовки горизонтальных уровней для quik
сам код:
--[[
Индикатор горизонтальных уровней<br />параметры:
Procent - процент зигзага
levels - колич. уровней (макс. 6)
delta - доля от тек. цены, на растоянии которой показываются уровни
show - показывать или нет индикатор =1 - да, =0 - нет
--]]
Settings={
Name="AT-levels",
Procent=5.0,
levels=6,
delta=0.2,
show=1,
line=
{
{
Name = "cur1",
Type =TYPE_LINE,
Width = 2,
Color = RGB(0,0, 255)
},
{
Name = "cur2",
Type =TYPE_LINE,
Width = 2,
Color = RGB(0,0, 255)
},
{
Name = "cur3",
Type =TYPE_LINE,
Width = 2,
Color = RGB(0,0, 255)
},
{
Name = "cur4",
Type =TYPE_LINE,
Width = 2,
Color = RGB(0,0, 255)
},
{
Name = "cur5",
Type =TYPE_LINE,
Width = 2,
Color = RGB(0,0, 255)
},
{
Name = "cur6",
Type =TYPE_LINE,
Width = 2,
Color = RGB(0,0, 255)
}
}
}
function Init()
y1 = nil
y2 = nil
x1 = 1
x2 = 1
levelsy={}
levelsx={}
cntlevels=0
return 6
end
function OnCalculate(index)
de = Settings.Procent
levels = Settings.levels
delta = Settings.delta
sz = Size()
if Settings.show == 1 then
vl = C(index)
if index <= 1 then
y1 = vl
y2 = vl
cntlevels=0
else
if C(index) > y1*(1+de/100) and y1 < y2 then
x2 = x1
y2 = y1
x1 = index
y1 = C(index)
cntlevels = cntlevels + 1
levelsx[cntlevels]=x2
levelsy[cntlevels]=y2
end
if C(index) > y1 and C(index) > y2 then
x1 = index
y1 = C(index)
end
if C(index) < y1*(1-de/100) and y1 > y2 then
x2 = x1
y2 = y1
x1 = index
y1 = C(index)
cntlevels = cntlevels + 1
levelsx[cntlevels]=x2
levelsy[cntlevels]=y2
end
if C(index) < y1 and C(index) < y2 then
x1 = index
y1 = C(index)
end
end
if x1 ~= index then
curfrom = x1
curto = index
else
curfrom = x2
curto = x1
end
if sz == index then
cnt = levels
for k = 1, cnt do
for i = 1, index do
SetValue(i, k, nil)
end
end
-- cnt = 3
k = 0
for j = cntlevels, 1, -1 do
d = 0
if levelsy[j] > C(index) then
d = levelsy[j] - C(index)
end
if levelsy[j] < C(index) then
d = C(index) - levelsy[j]
end
if d < delta*C(index) and d > 0 then
k = k + 1
if k <= cnt then
y = levelsy[j]
for i = levelsx[j], index do
SetValue(i, k, y)
end
end
end
end
--[[
k = 0
for j = cntlevels, 1, -1 do
d = 0
if levelsy[j] < C(index) then
d = C(index) - levelsy[j]
end
if d < 0.2*C(index) and d > 0 then
if k <= cnt then
k = k + 1
y = levelsy[j]
for i = levelsx[j], index do
SetValue(i, k+3, y)
end
end
end
end
--]]
end
end
end
телеграм:
t.me/autotradering