Блог им. autotrade
--[[ параметры: Procent - процент зигзага --]] Settings={ Name="ZIG_SMA", Procent=2, lim=20, div=2.0, line= { { Name = "ZIG_SMA", Type =TYPE_LINE, Width = 2, Color = RGB(0,0, 0) } } } function Init() y1 = nil y2 = nil x1 = 1 x2 = 1 return 1 end function OnCalculate(index) de = Settings.Procent lim = Settings.lim div = Settings.div 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) else if C(index) > y1 and y1 >= y2 then x1 = index y1 = C(index) end end if C(index) < y1*(1-de/100) and y1 > y2 then x2 = x1 y2 = y1 x1 = index y1 = C(index) else if C(index) < y1 and y1 <= y2 then x1 = index y1 = C(index) end end end per = math.floor((x1 - x2)/div) if per < lim then per = lim end ss = 0 k=0 for i = index - per, index do if i >= 1 then ss = ss + C(i) k=k+1 end end if k ~= 0 then vl=ss/k end return vl end