Блог им. autotrade
--[[ параметры: Procent - процент зигзага --]] Settings={ Name="ZIGZAGLEVELS", Procent=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(255,0, 0) }, { Name = "cur5", Type =TYPE_LINE, Width = 2, Color = RGB(255,0, 0) }, { Name = "cur6", Type =TYPE_LINE, Width = 2, Color = RGB(255,0, 0) } } } function Init() y1 = nil y2 = nil x1 = 1 x2 = 1 levelsy={} levelsx={} cntlevels=0 return 6 end function OnCalculate(index) de = Settings.Procent sz = Size() vl = C(index) if index == 1 then y1 = vl y2 = vl 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 = 6 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 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, 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