--[[ индикатор: канал на последнем зигзаге индикатор строит канал по зигзагу, показывает слом тренда при выходе цены за границы канала параметры: Procent - величина зигзага в % k - коэффизиент ширины канала Ext - =0-канал стоится по средним =1-канал стоится по экстремуму --]] Settings= { Name = "Zigzag_channel_inc", -- название индикатора Procent=5, -- величина зигзага в % k=2, -- коэффизиент ширины канала Ext=1, -- =0-канал стоится по средним =1-канал стоится по экстремуму shif=0, 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,200, 200) }, { Name = "cur3", Type =TYPE_LINE, Width = 2, Color = RGB(200,200, 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) }, { Name = "cur7", Type =TYPE_LINE, Width = 2, Color = RGB(255,0, 0) }, { Name = "cur8", Type =TYPE_LINE, Width = 2, Color = RGB(255,0, 0) }, { Name = "cur9", Type =TYPE_LINE, Width = 2, Color = RGB(255,0, 0) }, { Name = "cur10", Type =TYPE_LINE, Width = 2, Color = RGB(255,0, 0) }, { Name = "cur11", Type =TYPE_LINE, Width = 2, Color = RGB(0,0, 0) }, { Name = "cur12", Type =TYPE_LINE, Width = 2, Color = RGB(0,0, 0) } } } function Init() y1 = nil y2 = nil y3 = nil y4 = nil x1 = 1 x2 = 1 x3 = 1 x4 = 1 oldindex = 1 a_01 = 0 b_01 = 0 a_02 = 0 b_02 = 0 vminus_01 = 0 vplus_01 = 0 vminus_02 = 0 vplus_02 = 0 vFrom_01 = 1 vTo_01 = 1 vFrom_02 = 1 vTo_02 = 1 vminus = 0 vplus = 0 vminus_n = 0 vplus_n = 0 ret = 0 last_ind = 1 v1=nil v2=nil v3=nil v4=nil v5=nil v6=nil v7=nil v8=nil v9=nil v10=nil v11=nil v12=nil v13=nil return 13 end function recalcline(num, index, rec) if index == Size()-sh and rec == 0 then for i = 1, index do if m == 1 then SetValue(i, 3, nil) SetValue(i, 4, nil) end if m == 2 then SetValue(i, 6, nil) SetValue(i, 7, nil) end end end if index == Size()-sh or rec == 1 then if num == 1 then vFrom = 0 --[[ --]] vTo = 0 if x3 < x2 then vFrom = x3 vTo = x2 else vFrom = x2 vTo = x3 end end if num == 2 then vFrom = 0 vTo = 0 if x1 < x2 then vFrom = x1 vTo = x2 else vFrom = x2 vTo = x1 end end if vFrom < 1 then vFrom = 1 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 -- if oldindex ~= Size() 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 --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 end if num == 1 then a_01 = a b_01 = b vminus_01 = vminus vplus_01 = vplus vFrom_01 = vFrom vTo_01 = vTo end if num == 2 then a_02 = a b_02 = b vminus_02 = vminus vplus_02 = vplus vFrom_02 = vFrom vTo_02 = vTo end return 1 end return 0 end function levels(x, y, num, index, rec) if y ~= nil and x ~= 1 and (index ==Size() or rec==1) then for i = 1, index do if i >= x then SetValue(i, num, y) else SetValue(i, num, nil) end end end end function inclevels(x_1, y_1, x_2, y_2, y_3, index, num, rec) if y_2 ~= nil and x_2 ~= 1 and (index ==Size() or rec==1) then need = 1 for i = x_2+1, x_1-1 do y = ((y_2 - y_1)*i - x_1*y_2 + x_2*y_1 )/(x_2-x_1) if (y_1 < y_3 and C(i) < y ) or (y_1 > y_3 and C(i) > y ) then need = 0 break end end --need = 1 if need == 1 then for i = x_2, index do y = ((y_2 - y_1)*i - x_1*y_2 + x_2*y_1 )/(x_2-x_1) if i >= x_2 then if i > x_1 and (C(Size())*1.3 < y or C(Size())*0.7 > y) then SetValue(i, num, nil) else SetValue(i, num, y) end else SetValue(i, num, nil) end end end end end function OnCalculate(index) de = Settings.Procent kk = Settings.k ex = Settings.Ext sh = Settings.shif v1=nil v2=nil v3=nil v4=nil v5=nil v6=nil v7=nil v8=nil v9=nil v10=nil v11=nil v12=nil if index > Size()-sh then --return nil, nil, nil, nil, nil, nil, nil return v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11 , v12, v13 end vl = C(index) if index == 1 then y1 = vl y2 = vl else if C(index) > y1*(1+de/100) and y1 < y2 then x4 = x3 x3 = x2 x2 = x1 y4 = y3 y3 = y2 y2 = y1 x1 = index y1 = C(index) ret = recalcline(1, index, 0) ret = recalcline(2, index, 0) levels(x1, y1, 8, index, 0) levels(x2, y2, 9, index, 0) levels(x3, y3, 10, index, 0) levels(x4, y4, 11, index, 0) inclevels(x1, y1, x3, y3, y2, index, 12, 0) inclevels(x2, y2, x4, y4, y3, index, 13, 0) 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 x4 = x3 x3 = x2 x2 = x1 y4 = y3 y3 = y2 y2 = y1 x1 = index y1 = C(index) ret = recalcline(1, index, 0) ret = recalcline(2, index, 0) levels(x1, y1, 8, index, 0) levels(x2, y2, 9, index, 0) levels(x3, y3, 10, index, 0) levels(x4, y4, 11, index, 0) inclevels(x1, y1, x3, y3, y2, index, 12, 0) inclevels(x2, y2, x4, y4, y3, index, 13, 0) 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()-sh and ret == 0 then ret = recalcline(1, index, 1) ret = recalcline(2, index, 1) levels(x1, y1, 8, index, 1) levels(x2, y2, 9, index, 1) levels(x3, y3, 10, index, 1) levels(x4, y4, 11, index, 1) inclevels(x1, y1, x3, y3, y2, index, 12, 1) inclevels(x2, y2, x4, y4, y3, index, 13, 1) end if index == Size()-sh then --- and index ~= last_ind if vTo_01 - vFrom_01 > 500 then vFrom_01 = vTo_01-500 end for i = vFrom_01, index do y = a_01*i + b_01 + vplus_01 m = 0 if C(vTo_01) > C(vFrom_01) and y < C(vTo_01)+0.3*(C(vTo_01)-C(vFrom_01)) and y > C(vFrom_01)-0.3*(C(vTo_01)-C(vFrom_01)) then m = 1 end if C(vTo_01) < C(vFrom_01) and y < C(vFrom_01)+0.3*(C(vFrom_01)-C(vTo_01)) and y > C(vTo_01)-0.3*(C(vFrom_01)-C(vTo_01)) then m = 1 end if m == 1 then SetValue(i, 3, y) if i == index then v3 = y end end y = a_01*i + b_01 - vminus_01 m = 0 if C(vTo_01) > C(vFrom_01) and y < C(vTo_01)+0.3*(C(vTo_01)-C(vFrom_01)) and y > C(vFrom_01)-0.3*(C(vTo_01)-C(vFrom_01)) then m = 1 end if C(vTo_01) < C(vFrom_01) and y < C(vFrom_01)+0.3*(C(vFrom_01)-C(vTo_01)) and y > C(vTo_01)-0.3*(C(vFrom_01)-C(vTo_01)) then m = 1 end if m == 1 then SetValue(i, 4, y) if i == index then v4 = y end end end if vTo_02 - vFrom_02 > 500 then vFrom_02 = vTo_02-500 end for i = vFrom_02, index do y = a_02*i + b_02 + vplus_02 m = 0 if C(vTo_02) > C(vFrom_02) and y < C(vTo_02)+0.1*(C(vTo_02)-C(vFrom_02)) and y > C(vFrom_02)-0.1*(C(vTo_02)-C(vFrom_02)) then m = 1 end if C(vTo_02) < C(vFrom_02) and y < C(vFrom_02)+0.1*(C(vFrom_02)-C(vTo_02)) and y > C(vTo_02)-0.1*(C(vFrom_02)-C(vTo_02)) then m = 1 end if m == 1 then SetValue(i, 6, y) if i == index then v6 = y end end y = a_02*i + b_02 - vminus_02 m = 0 if C(vTo_02) > C(vFrom_02) and y < C(vTo_02)+0.1*(C(vTo_02)-C(vFrom_02)) and y > C(vFrom_02)-0.1*(C(vTo_02)-C(vFrom_02)) then m = 1 end if C(vTo_02) < C(vFrom_02) and y < C(vFrom_02)+0.1*(C(vFrom_02)-C(vTo_02)) and y > C(vTo_02)-0.1*(C(vFrom_02)-C(vTo_02)) then m = 1 end if m == 1 then SetValue(i, 7, y) if i == index then v7 = y end end end last_ind = index end return v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11 , v12, v13 end
Это же надо в очередной раз его в квик вносить, на графике разглядывать. А уж про перенос в систему с нормальным тестером и не вспоминаю.
Косяк непонятный.
Код из топика, тикер — RIM0, 4часа, Procent = 10
Наклонная, видимо это чёрная линия, которую видно примерно посередине между линиями наклонного канала.
Видимо с цветом линии что то не то?