usdrub -> 61 руб ближайшая цель
Авто-репост. Читать в блоге >>>
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
Settings={ Name="STATDIVVOL", period=10, 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() return 2 end function OnCalculate(index) local sum1=0 local sum2=0 if index < Settings.period then return nil, nil else for i=index-Settings.period+1, index do if C(i) > O(i) then sum1 = sum1 + (C(i) - O(i))*V(i) sum2 = sum2 + (C(i) - O(i))*V(i) else sum2 = sum2 + (O(i) - C(i))*V(i) end end sum1 = sum1/sum2 end return sum1, 0.5 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="XXX", period=25, line= { { Name="curve", Color=RGB(255,0,0), Type=TYPE_LINE, Width=1 } } } function Init() return 1 end function OnCalculate(index) if index < Settings.period then return nil else for i=index-Settings.period+1, index do do j=1 end for k=1, 10 do do j=1 end end return 2 end endесли второй цикл убираю for k=1, 10 do do j=1 end
Settings={ Name="STATDIV3", period=50, 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 }, { Name="MA", Color=RGB(0,0,255), Type=TYPE_LINE, Width=1 }, { Name="MA2", Color=RGB(0,128,128), Type=TYPE_LINE, Width=1 }, { Name="line2", Color=RGB(0,0,255), Type=TYPE_LINE, Width=1 }, { Name="line3", Color=RGB(0,128,128), Type=TYPE_LINE, Width=1 } } } function Init() cache_ind={} cache_ind2={} cache_ind3={} return 2 end function OnCalculate(index) if index < Settings.period then return nil else local sum1=0 local sum2=0 local sum0=0 local sum02=0 local sum03=0 for i=index-Settings.period+1, index do do if C(i) > O(i) then sum1 = sum1 + C(i) - O(i) sum2 = sum2 + C(i) - O(i) else sum2 = sum2 + O(i) - C(i) end end cache_ind[index] = sum1/sum2 if index > Settings.period+12 then --[[ sum0 = 1*cache_ind[index]+ (1)*cache_ind[index-1]+ (1)*cache_ind[index-2]+ (1)*cache_ind[index-3]+ (1)*cache_ind[index-4]+ (1)*cache_ind[index-5]+ (1)*cache_ind[index-6]+ (1)*cache_ind[index-7]+ (1)*cache_ind[index-8]+ (1/2)*cache_ind[index-9]+ (1/3)*cache_ind[index-10]+ (1/4)*cache_ind[index-11]+ (1/5)*cache_ind[index-12] --]] sum0 = 1*cache_ind[index]+ (1/2)*cache_ind[index-1]+ (1/3)*cache_ind[index-2]+ (1/4)*cache_ind[index-3]+ (1/5)*cache_ind[index-4]+ (1/6)*cache_ind[index-5]+ (1/7)*cache_ind[index-6]+ (1/8)*cache_ind[index-7]+ (1/9)*cache_ind[index-8]+ (1/10)*cache_ind[index-9]+ (1/11)*cache_ind[index-10]+ (1/12)*cache_ind[index-11]+ (1/13)*cache_ind[index-12] end --[[ sum0 = sum0/(1+1+1+1+1+1+1+1+1+1/2+1/3+1/4+1/5) --]] sum0 = sum0/(1+1/2+1/3+1/4+1/5+1/6+1/7+1/8+1/9+1/10+1/11+1/12+1/13) cache_ind2[index] = sum0 if index > Settings.period+50 then sum02 = 1*cache_ind2[index]+ (1)*cache_ind2[index-1]+ (1)*cache_ind2[index-2]+ (1)*cache_ind2[index-3]+ (1)*cache_ind2[index-4]+ (1)*cache_ind2[index-5]+ (1)*cache_ind2[index-6]+ (1)*cache_ind2[index-7]+ (1/2)*cache_ind2[index-8]+ (1/3)*cache_ind2[index-9]+ (1/4)*cache_ind2[index-10]+ (1/5)*cache_ind2[index-11]+ (1/6)*cache_ind2[index-12] --[[ sum02 = 1*cache_ind2[index]+ (1/2)*cache_ind2[index-1]+ (1/3)*cache_ind2[index-2]+ (1/4)*cache_ind2[index-3]+ (1/5)*cache_ind2[index-4]+ (1/6)*cache_ind2[index-5]+ (1/7)*cache_ind2[index-6]+ (1/8)*cache_ind2[index-7]+ (1/9)*cache_ind2[index-8]+ (1/10)*cache_ind2[index-9]+ (1/11)*cache_ind2[index-10]+ (1/12)*cache_ind2[index-11]+ (1/13)*cache_ind2[index-12] --]] end sum02 = sum02/(1+1+1+1+1+1+1+1+1/2+1/3+1/4+1/5+1/6) --[[ sum02 = sum02/(1+1/2+1/3+1/4+1/5+1/6+1/7+1/8+1/9+1/10+1/11+1/12+1/13) --]] cache_ind3[index] = sum0 - sum02 if index > Settings.period+50 then sum03 = 1*cache_ind3[index]+ (1/2)*cache_ind3[index-1]+ (1/3)*cache_ind3[index-2]+ (1/4)*cache_ind3[index-3]+ (1/5)*cache_ind3[index-4]+ (1/6)*cache_ind3[index-5]+ (1/7)*cache_ind3[index-6]+ (1/8)*cache_ind3[index-7]+ (1/9)*cache_ind3[index-8]+ (1/10)*cache_ind3[index-9]+ (1/11)*cache_ind3[index-10]+ (1/12)*cache_ind3[index-11]+ (1/13)*cache_ind3[index-12] end sum03 = sum03/(1+1/2+1/3+1/4+1/5+1/6+1/7+1/8+1/9+1/10+1/11+1/12+1/13) end if sum1/sum2 > 0.5 and sum03 > 0 then sum1 = sum03 else if sum1/sum2 < 0.5 and sum03 < 0 then sum1 = sum03 else sum1 = 0 end end return sum1, 0 end end