--[[ параметры: 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
Settings={ Name="MNKKANAL_new", period=200, delta=0, line= { { Name = "cur1", Type =TYPE_LINE, Width = 1, Color = RGB(0,255, 0) }, { Name = "cur2", Type =TYPE_LINE, Width = 2, Color = RGB(255,0, 0) }, { Name = "cur3", Type =TYPE_LINE, Width = 2, Color = RGB(255,0, 0) } } } --[[ описание свойств: period - период, за каротрый делается расчет назначение: построение тенденции использовался: метод наименьших квадратов (аппроксимация линией) --]] function Init() a1_0 = {} a2_0 = {} a3_0 = {} a4_0 = {} a1_1 = {} a2_1 = {} a3_1 = {} a4_1 = {} return 3 end function OnCalculate(index) sz = Size() n = Settings.period d = Settings.delta if index == 1 then a1_0[index] = 0 a2_0[index] = 0 a3_0[index] = 0 a4_0[index] = 0 i = index a1_1[index] = i*C(i) a2_1[index] = i a3_1[index] = C(i) a4_1[index] = i*i else i = index a1_1[index] = a1_1[index-1]+i*C(i) a2_1[index] = a2_1[index-1]+i a3_1[index] = a3_1[index-1]+C(i) a4_1[index] = a4_1[index-1]+i*i end y = nil y1 = nil y2 = nil if index-n > 0 then i = index-n a1_0[index] = a1_0[index-1]+i*C(i) a2_0[index] = a2_0[index-1]+i a3_0[index] = a3_0[index-1]+C(i) a4_0[index] = a4_0[index-1]+i*i a1 = a1_1[index]-a1_0[index] a2 = a2_1[index]-a2_0[index] a3 = a3_1[index]-a3_0[index] a4 = a4_1[index]-a4_0[index] if((n*a4 - a2*a2) ~= 0) then a = (n*a1 - a2*a3)/(n*a4 - a2*a2) b = (a3 - a*a2)/n c1 = 0 c2 = 0 n1 = 0 n2 = 0 for j=index-n+1, index do y = a*j + b if C(j) < y then c1 = c1 + (y -C(j)) n1 = n1 + 1 end if C(j) > y then c2 = c2 + (C(j) - y) n2 = n2 + 1 end end if n1 ~= 0 then c1 = c1/n1 end if n2 ~= 0 then c2 = c2/n2 end j = index-d y = a*j + b y1 = y-2*c1 y2 = y+2*c2 end else a1_0[index] = 0 a2_0[index] = 0 a3_0[index] = 0 a4_0[index] = 0 end return y,y1,y2 end
Settings={ Name="MNKKANAL", period=200, delta=0, line= { { Name = "cur1", Type =TYPE_LINE, Width = 1, Color = RGB(0,0, 0) }, { Name = "cur2", Type =TYPE_LINE, Width = 1, Color = RGB(0,0, 0) }, { Name = "cur2", Type =TYPE_LINE, Width = 1, Color = RGB(0,255, 0) } } } --[[ описание свойств: period - период, за каротрый делается расчет delta - смещение назад назначение: осцелятор по каналу использовался: метод наименьших квадратов (аппроксимация линией) --]] function Init() return 3 end function OnCalculate(index) sz = Size() n = Settings.period d = Settings.delta y = nil y1 = nil y2 = nil if index-n-d > 0 then a1 = 0 a2 = 0 a3 = 0 a4 = 0 for i=index-n+1-d, index-d do a1 = a1+i*C(i) a2 = a2+i a3 = a3+C(i) a4 = a4+i*i end if((n*a4 - a2*a2) ~= 0) then a = (n*a1 - a2*a3)/(n*a4 - a2*a2) b = (a3 - a*a2)/n c1 = 0 c2 = 0 n1 = 0 n2 = 0 for j=index-n+1-d, index-d do y = a*j + b if C(j) < y then c1 = c1 + (y -C(j)) n1 = n1 + 1 end if C(j) > y then c2 = c2 + (C(j) - y) n2 = n2 + 1 end end if n1 ~= 0 then c1 = c1/n1 end if n2 ~= 0 then c2 = c2/n2 end j = index-d y = a*j + b y1 = y-2*c1 y2 = y+2*c2 end end return y1, y2, y end
Settings={ Name="MNKOSC", period=200, delta=0, line= { { Name = "cur1", Type =TYPE_LINE, Width = 1, Color = RGB(0,0, 0) }, { Name = "cur2", Type =TYPE_LINE, Width = 1, Color = RGB(255,0, 0) }, { Name = "cur3", Type =TYPE_LINE, Width = 1, Color = RGB(0,0, 0) }, { Name = "cur4", Type =TYPE_LINE, Width = 1, Color = RGB(0,0, 0) } } } --[[ описание свойств: period - период, за каротрый делается расчет delta - смещение назад назначение: осцелятор по каналу использовался: метод наименьших квадратов (аппроксимация линией) --]] function Init() return 4 end function OnCalculate(index) sz = Size() n = Settings.period d = Settings.delta y = nil y1 = nil y2 = nil if index-n-d > 0 then a1 = 0 a2 = 0 a3 = 0 a4 = 0 for i=index-n+1-d, index-d do a1 = a1+i*C(i) a2 = a2+i a3 = a3+C(i) a4 = a4+i*i end if((n*a4 - a2*a2) ~= 0) then a = (n*a1 - a2*a3)/(n*a4 - a2*a2) b = (a3 - a*a2)/n c1 = 0 c2 = 0 n1 = 0 n2 = 0 for j=index-n+1-d, index-d do y = a*j + b if C(j) < y then c1 = c1 + (y -C(j)) n1 = n1 + 1 end if C(j) > y then c2 = c2 + (C(j) - y) n2 = n2 + 1 end end if n1 ~= 0 then c1 = c1/n1 end if n2 ~= 0 then c2 = c2/n2 end j = index-d y = a*j + b y1 = -2*c1 y2 = 2*c2 j = index-d y = C(j) - a*j - b end end return 0, y, y1, y2 end