--[[ параметры: Procent - процент зигзага --]] Settings={ Name="ZIGZAGPROF", Procent=1, line= { { Name = "cur1", Type =TYPE_LINE, Width = 2, Color = RGB(0,0, 0) } } } function Init() y1 = nil y2 = nil x1 = 1 x2 = 1 return 1 end function OnCalculate(index) de = Settings.Procent 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 return vl 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=20, periodma=20, weighted=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 3 end function OnCalculate(index) --sumv = 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 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 mas[index]=sumv 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 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
Settings={ Name="GVOL", period=200, maxline=20, width=4, count=50, xshift=0, vlm=1, line={} } --[[ описание свойств: xshift - сдвиг по горизонтали count - количество черточек по вертикали period- сколько баров берутся в подсчет maxline - количество баров для максимальной черточки width - толщина черточки vlm - 1-c учетом оъема 0-просто распределение без объема, --]] function Init() n=Settings.count vol={} for j = 1, n do vol[j]=0 Settings.line[j] = {Color=RGB(192,192,192),Type=TYPE_LINE,Width=Settings.width} --for i=Size()-Settings.xshift-Settings.maxline, Size()-Settings.xshift do for i=1, Size() do SetValue(i, j, nil) end end return Settings.count end function OnCalculate(index) if (index < Size()-Settings.xshift)or(index > Size()-Settings.xshift) then return nil else n=Settings.count maxv=0 maxc=0 minc=9999 for i=Size()-Settings.xshift-Settings.period, Size()-Settings.xshift do if C(i) ~= nil then if maxc < C(i) then maxc = C(i) end if minc > C(i) then minc = C(i) end end end delta = (maxc - minc)/n for i=Size()-Settings.xshift-Settings.period, Size()-Settings.xshift do for j = 1, n do if C(i) ~= nil then if (C(i) > minc + (j-1)*delta) and (C(i) <= minc + j*delta) then if Settings.vlm == 1 then if V(i) ~= nil then vol[j]=vol[j]+V(i) end else vol[j]=vol[j]+1 end end end end end for j = 1, n do vol[j] = math.floor(vol[j]+0.5) if maxv < vol[j] then maxv = vol[j] end end k = 0 for i=Size()-Settings.xshift-Settings.maxline+1, Size()-Settings.xshift do k = k + 1 for j = 1, n do if vol[j] >= (Settings.maxline - k)*maxv/Settings.maxline then SetValue(i, j, minc + j*delta) else SetValue(i, j, nil) end end end end end
Settings= { Name = "Zigzag5", -- название индикатора delta=2, -- параметр индикатора deltaY=1, -- параметр индикатора linedeltaY=0.75, -- параметр индикатора line= { { Name = "zigzagline3", Type =TYPE_LINE, Width = 2, Color = RGB(0,255, 0) }, { Name = "upline", Type =TYPE_LINE, Width = 2, Color = RGB(255,0, 0) }, { Name = "lowline", Type =TYPE_LINE, Width = 2, Color = RGB(0,0, 255) }, { Name = "declineline", Type =TYPE_LINE, Width = 2, Color = RGB(255,0, 0) }, { Name = "upline2", Type =TYPE_LINE, Width = 1, Color = RGB(255,0, 0) }, { Name = "lowline2", Type =TYPE_LINE, Width = 1, Color = RGB(0,0, 255) }, { Name = "declineline2", Type =TYPE_LINE, Width = 1, Color = RGB(255,0, 0) } } } function getradius(x, y) return math.sqrt(Settings.deltaY*y*y+x*x) end function koef(val) return 1 - 1/(1-1/val) end function Init() vMin = 0 vMax = 0 vMinindex = 0 vMaxindex = 0 voldMinindex = 0 voldMaxindex = 0 upval = 0 lowval = 0 upindex = 1 lowindex = 1 veu = nil vel = nil curfrom = 1 curto = 1 return 7 end function OnCalculate(index) local printz = 0 vsize = Size() ve = nil veu = nil vel = nil curv = nil veu2 = nil vel2 = nil curv2 = nil if index == 1 then vMin = C(index) vMax = C(index) vMinindex = index vMaxindex = index voldMinindex = index voldMaxindex = index ve = C(index) else if voldMaxindex >= voldMinindex then if C(index) > (1 + Settings.delta/100)*vMin then vMin = C(index) vMax = C(index) vMaxindex = index voldMinindex = vMinindex vFrom = voldMaxindex vTo = vMinindex printz = 1 if (C(vMinindex) > C(vsize)) and (upval > koef(getradius(vsize - vMinindex, C(vMinindex) - C(vsize)))) then upval = koef(getradius(vsize - vMinindex, C(vMinindex) - C(vsize))) upindex = vMinindex end if (C(vMinindex) < C(vsize)) and (lowval > koef(getradius(vsize - vMinindex, C(vMinindex) - C(vsize)))) then lowval = koef(getradius(vsize - vMinindex, C(vMinindex) - C(vsize))) lowindex = vMinindex end curfrom = voldMaxindex curto = voldMinindex else if vMin > C(index) then vMin = C(index) vMinindex = index vFrom = voldMaxindex vTo = index printz = 0 curto = index else vFrom = vMinindex vTo = index printz = 0 end curfrom = voldMaxindex end else if voldMaxindex <= voldMinindex then if C(index) < (1 - Settings.delta/100)*vMax then vMax = C(index) vMin = C(index) vMinindex = index voldMaxindex = vMaxindex vFrom = voldMinindex vTo = vMaxindex printz = 1 if (C(vMaxindex) > C(vsize)) and (upval > koef(getradius(vsize - vMaxindex, C(vMaxindex) - C(vsize)))) then upval = koef(getradius(vsize - vMaxindex, C(vMaxindex) - C(vsize))) upindex = vMaxindex end if (C(vMaxindex) < C(vsize)) and (lowval > koef(getradius(vsize - vMaxindex, C(vMaxindex) - C(vsize)))) then lowval = koef(getradius(vsize - vMaxindex, C(vMaxindex) - C(vsize))) lowindex = vMaxindex end curfrom = voldMinindex curto = voldMaxindex else if vMax < C(index) then vMax = C(index) vMaxindex = index vFrom = voldMinindex vTo = index printz = 0 curto = index else vFrom = vMaxindex vTo = index printz = 0 end curfrom = voldMinindex end end end if (printz == 1) or (Size() == index) then for i = vFrom, vTo do k = (C(vTo)- C(vFrom))/(vTo- vFrom) v = i*k + C(vTo) - vTo*k SetValue(i, 1, v) ve = v end if (Size() == index) then ve = C(index) if voldMaxindex >= voldMinindex then vFrom = voldMaxindex vTo = vMinindex end if voldMaxindex <= voldMinindex then vFrom = voldMinindex vTo = vMaxindex end for i = vFrom, vTo do k = (C(vTo)- C(vFrom))/(vTo- vFrom) v = i*k + C(vTo) - vTo*k SetValue(i, 1, v) end -- up level line if upindex ~= nil then if C(upindex) > C(index) then for i = upindex, index do SetValue(i, 2, C(upindex)) SetValue(i, 5, C(upindex)-Settings.linedeltaY*C(vsize)/100) end veu = C(upindex) end end -- low level line if lowindex ~= nil then if C(lowindex) < C(index) then for i = lowindex, index do SetValue(i, 3, C(lowindex)) SetValue(i, 6, C(lowindex)+Settings.linedeltaY*C(vsize)/100) end vel = C(lowindex) end end if voldMaxindex >= voldMinindex then vsign = -1 if curfrom == voldMinindex then vsign = -1 end if curfrom == voldMaxindex then vsign = 1 end -- inclined line if curto- curfrom > 0 then maxcurv = 0 k = (C(curto)- C(curfrom))/(curto- curfrom) for i = curfrom, curto do curv = i*k + C(curto) - curto*k if vsign == -1 then if L(i) < curv then if maxcurv < curv - L(i) then maxcurv = curv - L(i) end end else if H(i) > curv then if maxcurv < H(i) - curv then maxcurv = H(i) - curv end end end end for i = curfrom, index do curv = i*k + C(curto) - curto*k + vsign*maxcurv SetValue(i, 4,curv) curv2 = curv+ vsign*Settings.linedeltaY*C(vsize)/100 SetValue(i, 7,curv2) end end curv = nil end if voldMaxindex <= voldMinindex then vsign = -1 if curfrom == voldMaxindex then vsign = 1 end if curfrom == voldMinindex then vsign = -1 end -- inclined line if curto- curfrom > 0 then maxcurv = 0 k = (C(curto)- C(curfrom))/(curto- curfrom) for i = curfrom, curto do curv = i*k + C(curto) - curto*k if vsign == -1 then if L(i) < curv then if maxcurv < curv - L(i) then maxcurv = curv - L(i) end end else if H(i) > curv then if maxcurv < H(i) - curv then maxcurv = H(i) - curv end end end end for i = curfrom, index do k = (C(curto)- C(curfrom))/(curto- curfrom) curv = i*k + C(curto) - curto*k + vsign*maxcurv SetValue(i, 4,curv) curv2 = curv+ vsign*Settings.linedeltaY*C(vsize)/100 SetValue(i, 7,curv2) end end curv = nil end end end end return ve, veu, vel, curv, veu2, vel2, curv2 end