Блог им. autotrade
Settings= { Name = "Zigzag4", -- название индикатора 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) }, { Name = "declineline", Type =TYPE_LINE, Width = 2, Color = RGB(255,0, 0) } } } 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 curfrom = 1 curto = 1 return 4 end function OnCalculate(index) local printz = 0 local curv = nil 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 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 --[[ -- 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 H(i) > curv then if maxcurv < H(i) - curv then maxcurv = H(i) - curv end end end for i = curfrom, curto do --k = (C(curto)- C(curfrom))/(curto- curfrom) curv = i*k + C(curto) - curto*k + maxcurv SetValue(i, 4,curv) end end curv = nil --]] 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 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 --[[ -- 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 L(i) < curv then if maxcurv < curv - L(i) then maxcurv = curv - L(i) end end end for i = curfrom, curto do k = (C(curto)- C(curfrom))/(curto- curfrom) curv = i*k + C(curto) - curto*k - maxcurv SetValue(i, 4,curv) end end curv = nil --]] 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 if voldMaxindex >= voldMinindex then -- 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 H(i) > curv then if maxcurv < H(i) - curv then maxcurv = H(i) - curv end end end for i = curfrom, index do --k = (C(curto)- C(curfrom))/(curto- curfrom) curv = i*k + C(curto) - curto*k + maxcurv SetValue(i, 4,curv) end end curv = nil end if voldMaxindex <= voldMinindex then -- 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 L(i) < curv then if maxcurv < curv - L(i) then maxcurv = curv - L(i) end end end for i = curfrom, index do k = (C(curto)- C(curfrom))/(curto- curfrom) curv = i*k + C(curto) - curto*k - maxcurv SetValue(i, 4,curv) end end curv = nil end end end end --[[ if curto == nil then curto = 0 end--]] return ve, veu, vel, curv --, printz*1000+4000 end
Ибо код получается есть, а дальше — напильник ?