Блог им. autotrade
Settings={ Name="ADAPTMA", n=5, m=10, line= { --[[ { Name = "cur1", Type =TYPE_LINE, Width = 1, Color = RGB(0,0, 0) }, { Name = "cur2", Type =TYPE_LINE, Width = 1, Color = RGB(0,0, 0) }, { Name = "cur3", Type =TYPE_LINE, Width = 1, Color = RGB(0,0, 0) }, { Name = "cur4", Type =TYPE_LINE, Width = 1, Color = RGB(0,0, 0) }, { Name = "cur5", Type =TYPE_LINE, Width = 1, Color = RGB(0,0, 0) }, --]] { Name = "cur6", Type =TYPE_LINE, Width = 1, Color = RGB(255,0, 0) } } } --[[ -- кривая сдвига описание свойств: delta: сдвиг в барах от цены вправо --]] function Init() ma={} val={} return 1 end function OnCalculate(index) n = Settings.n m = Settings.m ma[index]={} val[index]={} for i=1, n do if index > 1 then if ma[index-1][i] ~= nil then ma[index][i] = ma[index-1][i] + O(index) else ma[index][i] = O(index) end else ma[index][i] = O(index) end period = i*10 if index - period > 1 then if ma[index-period][i] ~= nil then val[index][i] = (ma[index][i] - ma[index-period][i])/period else val[index][i] = ma[index][i] end else val[index][i] = nil end end k = n p = 0 for j=n, 1,-1 do e = 0 pj = 0 if index-m > 1 then for i=index-m, index-1 do if val[i-1][j] ~= nil and val[i][j] ~= nil then if ( val[i-1][j] <= O(i-1) and val[i][j] > O(j) or val[i-1][j] >= O(i-1) and val[i][j] < O(j) ) then e = e + 1 end end end pj = -O(index)*0.001*e if O(index) >= O(index-m) then pj = O(index) - O(index-m) + pj else pj = O(index-m) - O(index) + pj end end if pj > p then p = pj k = j end end val[index][n+1] = val[index][k] --return ma[index] -- return val[index][1], val[index][2], val[index][3], val[index][4], val[index][5], val[index][6] return val[index][n+1] --[[ val[1] ={} val[1][index] = 9 return val[1][index] --]] end