Блог им. autotrade
Settings= { Name = "AT-obl_can", -- название индикатора delta=1.0, -- параметр индикатора rep=5, shif=0, line= { { Name = "ln1", Type =TYPE_LINE, Width = 1, Color = RGB(120,90, 140) }, { Name = "ln2", 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 2 end function OnCalculate(index) rep = Settings.rep shif = Settings.shif sz = Size()-shif if index <= sz then 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 vMin~=nil 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 --end else if voldMaxindex <= voldMinindex then --if vMax~=nil 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 end --if vFrom~=nil then --[[ 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 if index == sz then for k = 1, 2 do vf = 1 vs = 0 if k == 1 then if vMinindex < vMaxindex then vf = vMinindex vs = vMaxindex up = 0 elseif vMinindex > vMaxindex then vs = vMinindex vf = vMaxindex up = 1 end elseif k == 2 then if voldMinindex < voldMaxindex then vf = voldMinindex vs = voldMaxindex up = 0 elseif voldMinindex > voldMaxindex then vs = voldMinindex vf = voldMaxindex up = 1 end end n = 0 xy = 0 x = 0 y = 0 xx = 0 for i = vf, vs do n = n + 1 xy = xy + i*C(i) x = x + i y = y + C(i) xx = xx + i*i end if (n*xx - x*x) ~= 0 and n ~= 0 then a = (n*xy - x*y)/(n*xx - x*x) b = (y - a*x)/n for j = 1, rep do n = 0 xy = 0 x = 0 y = 0 xx = 0 for i = vf, vs do v = a*i + b clc = 0 if up == 1 and C(i) > v then clc = 1 end if up == 0 and C(i) < v then clc = 1 end if clc == 1 then n = n + 1 xy = xy + i*C(i) x = x + i y = y + C(i) xx = xx + i*i end end --[[--]] if (n*xx - x*x) ~= 0 and n ~= 0 and n > 2 then a = (n*xy - x*y)/(n*xx - x*x) b = (y - a*x)/n --[[ --]] end end for i = vf, sz do v = a*i + b if up == 1 and v >= C(vs) or up == 0 and v <= C(vs) then SetValue(i, k, v) end end end end end end end endтелеграм: t.me/autotradering
Полезней было провести линии линейной регрессии. Относительно них можно хотя бы стандартное отклонение построить.
По закрытию ерунда получается. имхо.