Settings={ Name="Buy_osc_v01", period=50, delta=0, lim=100.0, line= { { Name = "cur1", Type =TYPE_LINE, Width = 1, Color = RGB(0, 0, 255) }, { Name = "cur2", Type =TYPE_LINE, Width = 1, Color = RGB(0, 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 2 end function OnCalculate(index) sz = Size() n = Settings.period d = Settings.delta lim = Settings.lim y = 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 if a==0 then y = 0 else y = (c1+c2)/a if y > lim then y = lim else if y < -lim then y = -lim end end end end end return y,0 end
--[[ параметры: Procent - процент зигзага --]] Settings={ Name="ZIGZAGPROF", Procent=1, line= { { Name = "cur1", Type =TYPE_LINE, Width = 2, Color = RGB(0,0, 0) }, { Name = "cur2", Type =TYPE_LINE, Width = 2, Color = RGB(0,0, 255) } } } function Init() y1 = nil y2 = nil x1 = 1 x2 = 1 return 1 end function OnCalculate(index) de = Settings.Procent delt = 0.01 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) 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) 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 --]] lev = nil if x1 ~= x2 then k = (C(x1)- C(x2))/(x1- x2) maxd = 0 for i = x2, x1 do lev = i*k + C(x1) - x1*k if C(x2) > C(x1) and lev <= H(i) then if maxd < H(i) - lev then maxd = H(i) - lev end --maxd = 0.5 end if C(x2) < C(x1) and lev >= L(i) then if maxd > L(i) - lev then maxd = L(i) - lev end --maxd = -0.5 end end lev = nil --[[if x1 < index and ( C(x2) > C(x1) and C(x1) < C(index) or C(x2) < C(x1) and C(x1) > C(index) ) then --]] lev = index*k + C(x1) - x1*k + maxd --end --[[ map = 10 lev = 0 if index-map+1 > 0 then for i = index-map+1, index do lev = lev + C(i) end lev = lev/map ma = lev end map = 30 lev2 = 0 if index-map+1 > 0 then for i = index-map+1, index do lev2 = lev2 + C(i) end lev2 = lev2/map ma2 = lev2 end if C(x2) > C(x1) and C(x1) < C(index) and C(index) > lev and C(index) - C(x1) > C(index)*delt or C(x2) > C(x1) and C(x1) < C(index) and C(index) > lev2 then lev = C(x1)--*(1-delt) prev = lev else if C(x2) < C(x1) and C(x1) > C(index) and C(index) < lev and C(x1) - C(index) > C(index)*delt or C(x2) < C(x1) and C(x1) > C(index) and C(index) < lev2 then lev = C(x1)--*(1+delt) prev = lev else lev = lev2 end end if C(x1) > C(x2) and ( lev < C(index) or prev == C(x2) ) then lev = C(x2)--*(1+delt) prev = lev end if C(x1) < C(x2) and ( lev > C(index) or prev == C(x2) ) then lev = C(x2)--*(1-delt) prev = lev end if C(x1) < C(x2) and ( lev < C(index) or prev == C(x1) ) then lev = C(x1) prev = lev end if C(x1) > C(x2) and ( lev > C(index) or prev == C(x1) ) then lev = C(x1) prev = lev end --]] end return lev end
Settings={ Name="ADAPTMA", n=5, m=10, 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 = "cur3", Type =TYPE_LINE, Width = 1, Color = RGB(0,0, 0) }, { Name = "cur4", Type =TYPE_LINE, Width = 1, Color = RGB(0,0, 0) }, { Name = "cur5", Type =TYPE_LINE, Width = 1, Color = RGB(0,0, 0) }, --]] { Name = "cur6", Type =TYPE_LINE, Width = 1, Color = RGB(255,0, 0) } } } --[[ -- кривая сдвига описание свойств: delta: сдвиг в барах от цены вправо --]] function Init() ma={} val={} return 1 end function OnCalculate(index) n = Settings.n m = Settings.m ma[index]={} val[index]={} for i=1, n do if index > 1 then if ma[index-1][i] ~= nil then ma[index][i] = ma[index-1][i] + O(index) else ma[index][i] = O(index) end else ma[index][i] = O(index) end period = i*10 if index - period > 1 then if ma[index-period][i] ~= nil then val[index][i] = (ma[index][i] - ma[index-period][i])/period else val[index][i] = ma[index][i] end else val[index][i] = nil end end k = n p = 0 for j=n, 1,-1 do e = 0 pj = 0 if index-m > 1 then for i=index-m, index-1 do if val[i-1][j] ~= nil and val[i][j] ~= nil then if ( val[i-1][j] <= O(i-1) and val[i][j] > O(j) or val[i-1][j] >= O(i-1) and val[i][j] < O(j) ) then e = e + 1 end end end pj = -O(index)*0.001*e if O(index) >= O(index-m) then pj = O(index) - O(index-m) + pj else pj = O(index-m) - O(index) + pj end end if pj > p then p = pj k = j end end val[index][n+1] = val[index][k] --return ma[index] -- return val[index][1], val[index][2], val[index][3], val[index][4], val[index][5], val[index][6] return val[index][n+1] --[[ val[1] ={} val[1][index] = 9 return val[1][index] --]] end
Settings={ Name="VDIV", period=20, periodma=15, line= { { Name = "cur1", Type =TYPE_LINE, Width = 1, Color = RGB(255,0,0) }, { Name = "cur2", Type =TYPE_LINE, Width = 1, Color = RGB(0,0,0) } } } --[[ -- кривая объемов описание свойств: period: сколько баров берутся в подсчет weighted: =0 - обычная, =1 - взвешанная proportional: =1- считается: volume*(close-open)/(hight-low), =0 - считается: volume*sign(close-open) --]] function Init() mas = {} return 3 end function OnCalculate(index) sumv1 = 0 sumv2 = 0 if index >= Settings.period then for i=index-Settings.period+1, index do if V(i) ~= nil and C(i) ~= nil then if C(i) > O(i) then sumv1 = sumv1+V(i)*(C(i) - O(i)) else sumv2 = sumv2+V(i)*(O(i) - C(i)) end end end else sumv1 = nil sumv2 = nil end if sumv2 ~= 0 and sumv2 ~= nil then vdiv = sumv1/sumv2 vdiv2 = sumv2/sumv1 vdiv3 = vdiv - vdiv2 else vdiv = nil vdiv2 = nil vdiv3 = nil end mas[index] = vdiv3 ma = 0 if index >= Settings.periodma then for i=index-Settings.periodma+1, index do if mas[i] ~= nil then ma = ma + mas[i] end end end ma = ma/Settings.periodma return ma, 0 end
Settings={ Name="VCUR", period=50, periodma=15, weighted=1, weightedma=1, proportional=1, line= { { Name = "cur1", Type =TYPE_LINE, Width = 1, Color = RGB(155,0, 0) }, { Name = "cur2", Type =TYPE_LINE, Width = 1, Color = RGB(0,0,155) }, { Name = "cur3", Type =TYPE_LINE, Width = 1, Color = RGB(0,0, 0) } } } --[[ -- кривая объемов описание свойств: period: сколько баров берутся в подсчет weighted: =0 - обычная, =1 - взвешанная proportional: =1- считается: volume*(close-open)/(hight-low), =0 - считается: volume*sign(close-open) --]] function Init() mas={} return 2 end function OnCalculate(index) sumv = 0 wsum = 0 if index >= Settings.period then for i=index-Settings.period+1, index do if sumv == nil then sumv = 0 end if C(i-1) ~= nil then wsum = wsum + i-(index-Settings.period) if C(i-1) > O(i-1) then if Settings.proportional == 0 then prop = 1 else if (H(i-1)-L(i-1)) == 0 then prop = 0 else prop = (C(i-1)-O(i-1))/(H(i-1)-L(i-1)) end end if Settings.weighted == 0 then sumv = sumv + prop*V(i-1) else sumv = sumv + prop*V(i-1)*(i-(index-Settings.period))--/Settings.period end else if Settings.proportional == 0 then prop = 1 else if (H(i-1)-L(i-1)) == 0 then prop = 0 else prop = (O(i-1)-C(i-1))/(H(i-1)-L(i-1)) end end if Settings.weighted == 0 then sumv = sumv - prop*V(i-1) else sumv = sumv - prop*V(i-1)*(i-(index-Settings.period))--/Settings.period end end end end else sumv = nil end if Settings.weighted ~= 0 then if sumv ~= nil then sum =sumv/wsum end end mas[index]=sumv ma = 0 wsum = 0 if index >= Settings.periodma then for i=index-Settings.periodma+1, index do if mas[i] ~= nil then wsum = wsum + i-(index-Settings.periodma) if Settings.weightedma == 0 then ma = ma + mas[i] else ma = ma + mas[i]*(i-(index-Settings.periodma))--/Settings.periodma end end end end if Settings.weightedma == 0 then if ma ~= nil then ma = ma/Settings.periodma end else ma = ma/wsum end return sumv, ma--, 0 end
Settings={ Name="VCUR", period=20, weighted=0, line= { { Name = "cur1", Type =TYPE_LINE, Width = 2, Color = RGB(140,181, 242) } } } --[[ -- кривая объемов описание свойств: period: сколько баров берутся в подсчет weighted: =0 - обычная, =1 - взвешанная --]] function Init() sumv = 0 return 1 end function OnCalculate(index) if index >= Settings.period then for i=index-Settings.period-1, index do if sumv == nil then sumv = 0 end if C(i-1) ~= nil then if C(i-1) > O(i-1) then if Settings.weighted == 0 then sumv = sumv + V(i-1) else sumv = sumv + V(i-1)*(i-(index-Settings.period))/Settings.period end else if Settings.weighted == 0 then sumv = sumv - V(i-1) else sumv = sumv - V(i-1)*(i-(index-Settings.period))/Settings.period end end end end else sumv = nil end return sumv end