Блог им. autotrade
Procent - величина зигзага в % k - коэффизиент ширины канала Ext - =0-канал стоится по средним =1-канал стоится по экстремуму
--[[ индикатор: канал на последнем зигзаге индикатор строит канал по зигзагу, показывает слом тренда при выходе цены за границы канала параметры: Procent - величина зигзага в % k - коэффизиент ширины канала Ext - =0-канал стоится по средним =1-канал стоится по экстремуму --]] Settings= { Name = "Zigzag_channel", -- название индикатора Procent=5, -- величина зигзага в % k=2, -- коэффизиент ширины канала Ext=1, -- =0-канал стоится по средним =1-канал стоится по экстремуму line= { { Name = "zigzagline", Type =TYPE_LINE, Width = 1, Color = RGB(120,90, 140) }, { Name = "cur1", Type =TYPE_LINE, Width = 1, Color = RGB(0,0, 0) }, { Name = "cur2", Type =TYPE_LINE, Width = 2, Color = RGB(0,0, 255) }, { Name = "cur3", Type =TYPE_LINE, Width = 2, Color = RGB(255,0, 0) }, { Name = "cur4", Type =TYPE_LINE, Width = 1, Color = RGB(0,0, 0) }, { Name = "cur5", Type =TYPE_LINE, Width = 2, Color = RGB(0,0, 255) }, { Name = "cur6", Type =TYPE_LINE, Width = 2, Color = RGB(255,0, 0) } } } function Init() y1 = nil y2 = nil x1 = 1 x2 = 1 x3 = 1 return 7 end function OnCalculate(index) de = Settings.Procent kk = Settings.k ex = Settings.Ext vl = C(index) if index == 1 then y1 = vl y2 = vl else if C(index) > y1*(1+de/100) and y1 < y2 then x3 = x2 x2 = x1 y2 = y1 x1 = index y1 = C(index) 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 x3 = x2 x2 = x1 y2 = y1 x1 = index y1 = C(index) 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 curto ~= curfrom and curfrom ~= nil and curto ~= nil then if C(curto) ~= nil and C(curfrom) ~= nil then k = (C(curto)- C(curfrom))/(curto- curfrom) for i = curfrom, index do curv = i*k + C(curto) - curto*k --SetValue(i, 1, curv) end end end --[[ --]] if index == Size() then --[[ 111111111111111 --]] vFrom = 0 vTo = 0 if x3 < x2 then vFrom = x3 vTo = x2 else vFrom = x2 vTo = x3 end a1 = 0 a2 = 0 a3 = 0 a4 = 0 n = 0 a = 0 b = 0 for i = vFrom, vTo do n=n+1 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 vminus = 0 vplus = 0 vminus_n = 0 vplus_n = 0 for i = vFrom, index do y = a*i + b if C(i) < y and i <= vTo then if ex == 0 then vminus = vminus + y - C(i) vminus_n = vminus_n + 1 else if i == vFrom then vminus = 0 end if y-C(i) > vminus then vminus = y-C(i) end end end if C(i) > y and i <= vTo then if ex == 0 then vplus = vplus + C(i) - y vplus_n = vplus_n + 1 else if i == vFrom then vplus = 0 end if C(i)-y > vplus then vplus = C(i)-y end end end m = 0 if C(vTo) > C(vFrom) and y < C(vTo)+0.1*(C(vTo)-C(vFrom)) and y > C(vFrom)-0.1*(C(vTo)-C(vFrom)) then m = 1 end if C(vTo) < C(vFrom) and y < C(vFrom)+0.1*(C(vFrom)-C(vTo)) and y > C(vTo)-0.1*(C(vFrom)-C(vTo)) then m = 1 end if m == 1 then --SetValue(i, 2, y) end end if ex == 0 then if vminus_n ~= 0 then vminus = kk*vminus/vminus_n end if vplus_n ~= 0 then vplus = kk*vplus/vplus_n end end for i = vFrom, index do y = a*i + b + vplus m = 0 if C(vTo) > C(vFrom) and y < C(vTo)+0.1*(C(vTo)-C(vFrom)) and y > C(vFrom)-0.1*(C(vTo)-C(vFrom)) then m = 1 end if C(vTo) < C(vFrom) and y < C(vFrom)+0.1*(C(vFrom)-C(vTo)) and y > C(vTo)-0.1*(C(vFrom)-C(vTo)) then m = 1 end if m == 1 then SetValue(i, 3, y) end y = a*i + b - vminus m = 0 if C(vTo) > C(vFrom) and y < C(vTo)+0.1*(C(vTo)-C(vFrom)) and y > C(vFrom)-0.1*(C(vTo)-C(vFrom)) then m = 1 end if C(vTo) < C(vFrom) and y < C(vFrom)+0.1*(C(vFrom)-C(vTo)) and y > C(vTo)-0.1*(C(vFrom)-C(vTo)) then m = 1 end if m == 1 then SetValue(i, 4, y) end end end --[[ 2222222222222 --]] vFrom = 0 vTo = 0 if x1 < x2 then vFrom = x1 vTo = x2 else vFrom = x2 vTo = x1 end a1 = 0 a2 = 0 a3 = 0 a4 = 0 n = 0 a = 0 b = 0 for i = vFrom, vTo do n=n+1 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 vminus = 0 vplus = 0 vminus_n = 0 vplus_n = 0 for i = vFrom, index do y = a*i + b if C(i) < y and i <= vTo then if ex == 0 then vminus = vminus + y - C(i) vminus_n = vminus_n + 1 else if i == vFrom then vminus = 0 end if y-C(i) > vminus then vminus = y-C(i) end end end if C(i) > y and i <= vTo then if ex == 0 then vplus = vplus + C(i) - y vplus_n = vplus_n + 1 else if i == vFrom then vplus = 0 end if C(i)-y > vplus then vplus = C(i)-y end end end m = 0 if C(vTo) > C(vFrom) and y < C(vTo)+0.1*(C(vTo)-C(vFrom)) and y > C(vFrom)-0.1*(C(vTo)-C(vFrom)) then m = 1 end if C(vTo) < C(vFrom) and y < C(vFrom)+0.1*(C(vFrom)-C(vTo)) and y > C(vTo)-0.1*(C(vFrom)-C(vTo)) then m = 1 end if m == 1 then --SetValue(i, 5, y) end end if ex == 0 then if vminus_n ~= 0 then vminus = kk*vminus/vminus_n end if vplus_n ~= 0 then vplus = kk*vplus/vplus_n end end for i = vFrom, index do y = a*i + b + vplus m = 0 if C(vTo) > C(vFrom) and y < C(vTo)+0.1*(C(vTo)-C(vFrom)) and y > C(vFrom)-0.1*(C(vTo)-C(vFrom)) then m = 1 end if C(vTo) < C(vFrom) and y < C(vFrom)+0.1*(C(vFrom)-C(vTo)) and y > C(vTo)-0.1*(C(vFrom)-C(vTo)) then m = 1 end if m == 1 then SetValue(i, 6, y) end y = a*i + b - vminus m = 0 if C(vTo) > C(vFrom) and y < C(vTo)+0.1*(C(vTo)-C(vFrom)) and y > C(vFrom)-0.1*(C(vTo)-C(vFrom)) then m = 1 end if C(vTo) < C(vFrom) and y < C(vFrom)+0.1*(C(vFrom)-C(vTo)) and y > C(vTo)-0.1*(C(vFrom)-C(vTo)) then m = 1 end if m == 1 then SetValue(i, 7, y) end end end end return nil--vl end
Это терпеть, или в новых версиях было поправлено?