Settings={ Name="STATDIVPROF", period=30, showprof=0, line= { { Name="curve", Color=RGB(0,0,255), Type=TYPE_LINE, Width=1 }, { Name="line", Color=RGB(255,0,0), Type=TYPE_LINE, Width=1 } } } function Init() prof=0 bp=0 prevval=0 return 2 end function OnCalculate(index) local sum1=0 local sum2=0 local j=0 local dprof=0 if index < Settings.period then return nil, nil else for i=index-Settings.period+1, index do j = j + 1 if C(i) > O(i) then sum1 = sum1 + (C(i) - O(i))*V(i)*j sum2 = sum2 + (C(i) - O(i))*V(i)*j else sum2 = sum2 + (O(i) - C(i))*V(i)*j end end sum1 = sum1/sum2 end if index > Settings.period+1 then if prevval < 0.5 and sum1 >= 0.5 then bp=C(index) end if prevval > 0.5 and sum1 <= 0.5 then if bp ~= 0 then prof=prof+C(index)-bp bp=0 end end if bp ~= 0 then dprof = C(index) - bp else dprof = 0 end end prevval=sum1 if Settings.showprof == 0 then return sum1, 0.5 end if Settings.showprof == 1 then return prof+dprof, nil end end
Settings= { Name = "Zigzag3", -- название индикатора delta=2, -- параметр индикатора line= { { Name = "zigzagline3", Type =TYPE_LINE, Width = 2, Color = RGB(120,90, 140) }, { Name = "upline", Type =TYPE_LINE, Width = 2, Color = RGB(255,0, 0) }, { Name = "lowline", Type =TYPE_LINE, Width = 2, Color = RGB(0,0, 255) } } } function Init() vMin = 0 vMax = 0 vMinindex = 0 vMaxindex = 0 voldMinindex = 0 voldMaxindex = 0 upval = 9999999 lowval = 9999999 upindex = 1 lowindex = 1 veu = nil vel = nil return 3 end function OnCalculate(index) local printz = 0 vsize = Size() 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 > C(vMinindex) - C(vsize)) then upval = C(vMinindex) - C(vsize) upindex = vMinindex end if (C(vMinindex) < C(vsize)) and (lowval > C(vsize)- C(vMinindex)) then lowval = C(vsize) - C(vMinindex) lowindex = vMinindex end else if vMin > C(index) then vMin = C(index) vMinindex = index vFrom = voldMaxindex vTo = index printz = 0 else vFrom = vMinindex vTo = index printz = 0 end 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 > C(vMaxindex) - C(vsize)) then upval = C(vMaxindex) - C(vsize) upindex = vMaxindex end if (C(vMaxindex) < C(vsize)) and (lowval > C(vsize)- C(vMaxindex)) then lowval = C(vsize) - C(vMaxindex) lowindex = vMaxindex end else if vMax < C(index) then vMax = C(index) vMaxindex = index vFrom = voldMinindex vTo = index printz = 0 else vFrom = vMaxindex vTo = index printz = 0 end 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 if upindex ~= nil then if C(upindex) > C(index) then for i = upindex, index do SetValue(i, 2, C(upindex)) end veu = C(upindex) end end if lowindex ~= nil then if C(lowindex) < C(index) then for i = lowindex, index do SetValue(i, 3, C(lowindex)) end vel = C(lowindex) end end end end end return ve, veu, vel end
Settings= { Name = "Zigzag2", -- название индикатора delta=2, -- параметр индикатора line= { { Name = "zigzagline2", Type =TYPE_LINE, Width = 2, Color = RGB(120,90, 140) } } } function Init() vMin = 0 vMax = 0 vMinindex = 0 vMaxindex = 0 voldMinindex = 0 voldMaxindex = 0 return 1 end function OnCalculate(index) local printz = 0 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 else if vMin > C(index) then vMin = C(index) vMinindex = index vFrom = voldMaxindex vTo = index printz = 0 else vFrom = vMinindex vTo = index printz = 0 end 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 else if vMax < C(index) then vMax = C(index) vMaxindex = index vFrom = voldMinindex vTo = index printz = 0 else vFrom = vMaxindex vTo = index printz = 0 end 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 end end end return ve end
Settings= { Name = "Zigzag", -- название индикатора delta=3, -- параметр индикатора line= { { Name = "zigzagline", Type =TYPE_LINE, Width = 1, Color = RGB(120,90, 140) } } } function Init() vMin = 0 vMax = 0 vMinindex = 0 vMaxindex = 0 voldMinindex = 0 voldMaxindex = 0 return 1 end function OnCalculate(index) if index == 1 then vMin = C(index) vMax = C(index) vMinindex = index vMaxindex = index voldMinindex = index voldMaxindex = index v = 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 = vMinindex else if vMin > C(index) then vMin = C(index) vMinindex = index vFrom = voldMaxindex else vFrom = vMinindex end 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 = vMaxindex else if vMax < C(index) then vMax = C(index) vMaxindex = index vFrom = voldMinindex else vFrom = vMaxindex end end end end for i = vFrom, index do k = (C(index)- C(vFrom))/(index- vFrom); v = i*k + C(index) - index*k SetValue(i, 1, v) end end end