Блог им. autotrade
--[[ индикатор: --]] Settings= { Name = "A_channel_nested", -- название индикатора leng=50, -- длина proc=5, delt=10, line= { { Name = "cur1", Type =TYPE_LINE, Width = 2, Color = RGB(0,0,0) }, { Name = "cur2", Type =TYPE_LINE, Width = 2, Color = RGB(0,0,0) }, { Name = "cur3", Type =TYPE_LINE, Width = 2, Color = RGB(0,0,0) }, { Name = "cur4", Type =TYPE_LINE, Width = 2, Color = RGB(0,0,0) }, { Name = "cur5", Type =TYPE_LINE, Width = 2, Color = RGB(0,0,0) }, { Name = "cur6", Type =TYPE_LINE, Width = 2, Color = RGB(255,0,0) }, { Name = "cur7", Type =TYPE_LINE, Width = 2, Color = RGB(0,0,255) }, { Name = "cur8", Type =TYPE_LINE, Width = 2, Color = RGB(255,0,0) }, { Name = "cur9", Type =TYPE_LINE, Width = 2, Color = RGB(0,0,255) }, { Name = "cur10", Type =TYPE_LINE, Width = 2, Color = RGB(0,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) }, { Name = "cur13", Type =TYPE_LINE, Width = 2, Color = RGB(0,0,0) }, { Name = "cur14", Type =TYPE_LINE, Width = 2, Color = RGB(0,0,0) } } } function Init() 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 v14=nil return 14 end function recalcline(num1, num2, vFrom, vTo, index, delt) --[[ 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 --]] 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, vTo do y = a*i + b if C(i) < y and i <= vTo then if y-C(i) > vminus then vminus = y-C(i) end end if C(i) > y and i <= vTo then if C(i)-y > vplus then vplus = C(i)-y 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 --]] -- 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 --]] -- end end --end for i = vFrom, vTo+delt do if i <= index then y = a*i + b SetValue(i, num1, y+vplus) SetValue(i, num2, y-vminus) end end end return 0 end function OnCalculate(index) leng = Settings.leng delt = Settings.delt proc = Settings.proc proc = proc/100 sz = Size() if index-leng > 0 and index == sz then a1 = 0 a2 = 0 a3 = 0 a4 = 0 n = 0 a = 0 b = 0 for i = index-leng, index 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 = index-leng, index do y = a*i + b if y>C(i) and y-C(i) > vminus then vminus = y - C(i) end if y<C(i) and C(i)-y > vplus then vplus = C(i) - y end end --[[ if vminus_n ~= 0 then vminus = 2*vminus/vminus_n end if vplus_n ~= 0 then vplus = 2*vplus/vplus_n end --]] x1 = index-leng x2 = index-leng x3 = index-leng y1 = C(x1) y2 = C(x2) y3 = C(x3) --de = 0.5*(vplus + vminus)/C(index-leng) --/(C(index-leng) - (a*(index-leng) + b - vminus)) de = proc*C(index-leng) for i = index-leng, index do y = a*i + b SetValue(i, 1, y + vplus) --SetValue(i, 2, y) SetValue(i, 3, y - vminus) --vl = C(i) -- (y - vminus) vl = C(i) - (y - vminus) if i == index-leng then y1 = vl y2 = vl y3 = vl else if (vl > y1+de and y1 < y2) or (x1==index-leng and vl > y1) then x3 = x2 y3 = y2 x2 = x1 y2 = y1 x1 = i y1 = vl end if vl > y1 and vl > y2 then x1 = i y1 = vl end if (vl < y1-de and y1 > y2) or (x1==index-leng and vl < y1) then x3 = x2 y3 = y2 x2 = x1 y2 = y1 x1 = i y1 = vl end if vl < y1 and vl < y2 then x1 = i y1 = vl end end end --[[ k = (C(x1)- C(x2))/(x1- x2) for i = x2, x1 do curv = i*k + C(x1) - x1*k SetValue(i, 4, curv) end k = (C(x2)- C(x3))/(x2- x3) for i = x3, x2 do curv = i*k + C(x2) - x2*k SetValue(i, 5, curv) end --]] recalcline(6, 7, x2, x1, index, delt) recalcline(8, 9, x3, x2, index, delt) end end return v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11 , v12, v13, v14 end
Как мне кажется, стоит сделать такого рода фильтрацию, чтобы входить по тренду, образованному внешним каналом, с наименьшим стопом.