Вот стандартный индикатор из квика, он выдает значение индикатора на текущей свече, а как получить значение на предыдущей свече?
function OnCalculate(Index) return tonumber(Settings.Horizontal_line),ConvertValue(Settings,func(Index, Settings))
end
function MACD() --Moving Average Convergence/Divergence ("MACD")
local MACD_MA = MA()
local Short_MA = MA()
local Long_MA = MA()
local it = {p=0, l=0}
return function (I, Fsettings, ds)
local Fsettings=(Fsettings or {})
local ShortP = (Fsettings.SHORT_Period or 12)
local LongP = (Fsettings.LONG_Period or 26)
local M = (Fsettings.Metod or EMA)
local VT = (Fsettings.VType or CLOSE)
local SM = (Fsettings.Signal_Metod or SMA)
local SP = (Fsettings.Signal_Period or 9)
local Percent = (Fsettings.Percent or 1)
if (ShortP>0) and (LongP>0) and (SP>0) then
if I == 1 then
it = {p=0, l=0}
end
local So = Short_MA(I, {Period=ShortP, Metod = M, VType=VT}, ds)
local Lo = Long_MA(I, {Period=LongP, Metod = M, VType=VT}, ds)
if CandleExist(I,ds) then
if I~=it.p then it={p=I, l=it.l+1} end
local i = it.l - math.max(ShortP, LongP) + 1
if (i>0) then
if Percent==0 then
t_MACD=So - Lo
else
t_MACD=100*(So - Lo) / Lo
end
if (SM~=SMA) and (SM~=EMA) then SM=SMA end
return t_MACD, MACD_MA(i, {Period=SP, Metod = SM, VType=ANY}, {[i] = t_MACD})
end
end
end
return nil, nil
end
end
function OnCalculate(Index) return tonumber(Settings.Horizontal_line),ConvertValue(Settings,func(Index, Settings))
end
function MACD() --Moving Average Convergence/Divergence ("MACD")
local MACD_MA = MA()
local Short_MA = MA()
local Long_MA = MA()
local it = {p=0, l=0}
return function (I, Fsettings, ds)
local Fsettings=(Fsettings or {})
local ShortP = (Fsettings.SHORT_Period or 12)
local LongP = (Fsettings.LONG_Period or 26)
local M = (Fsettings.Metod or EMA)
local VT = (Fsettings.VType or CLOSE)
local SM = (Fsettings.Signal_Metod or SMA)
local SP = (Fsettings.Signal_Period or 9)
local Percent = (Fsettings.Percent or 1)
if (ShortP>0) and (LongP>0) and (SP>0) then
if I == 1 then
it = {p=0, l=0}
end
local So = Short_MA(I, {Period=ShortP, Metod = M, VType=VT}, ds)
local Lo = Long_MA(I, {Period=LongP, Metod = M, VType=VT}, ds)
if CandleExist(I,ds) then
if I~=it.p then it={p=I, l=it.l+1} end
local i = it.l - math.max(ShortP, LongP) + 1
if (i>0) then
if Percent==0 then
t_MACD=So - Lo
else
t_MACD=100*(So - Lo) / Lo
end
if (SM~=SMA) and (SM~=EMA) then SM=SMA end
return t_MACD, MACD_MA(i, {Period=SP, Metod = SM, VType=ANY}, {[i] = t_MACD})
end
end
end
return nil, nil
end
end