Тема: Задержка расчетов индикатора.
Здравствуйте! Помогите пожалуйста вставить в код индикатора задержку между расчетами, или расчет по предыдущей свече.
Проблема в том, что spred иногда выносит в макс или в мин (не все данные приходят одновременно) на доли секунды, и max_price и low_price тоже соответственно искажаются, потом spred принимает нормальное значение а max и low - нет...
--- Вычислить спред.
-- @param index номер свечи на графике
-- @return значение спреда или nil, если оно неопределено
local function getSpread(index)
local timeCode = getTimeCode(T(index))
local securityPrice = C(index)
if securityPrice == nil then
return nil
end
-- Получение свечей дополнительных инструментов
local candle1 = getCandleByTimeCode(Settings.tag1, timeCode)
local candle2 = getCandleByTimeCode(Settings.tag2, timeCode)
if candle1 == nil or candle2 == nil then
return nil
end
-- Получение цен дополнительных инструментов
local price1 = candle1.close
local price2 = candle2.close
if price1 == nil or price2 == nil then
return nil
end
-- Вычисление спреда
local spread = (50 - (100 / (1 + price1 / price2)))*Settings.k
-- Вычисление максимума минимума среднего для спреда
if index == 1 then
max_price = nill
med_price = nill
low_price = nill
elseif T(index).hour < T(index-1).hour then
max_price = nill
med_price = nill
low_price = nill
end
if max_price == nill then
max_price = spread
elseif spread > max_price then
max_price = spread
low_price = spread - Settings.a
med_price = (max_price+low_price)/2
end
if low_price == nill then
low_price = spread
elseif spread < low_price then
low_price = spread
max_price = spread + Settings.a
med_price = (max_price+low_price)/2
end
if med_price == nill then
med_price = (max_price+low_price)/2
elseif spread < low_price then
med_price = (max_price+low_price)/2
elseif spread > max_price then
med_price = (max_price+low_price)/2
end
return spread, (max_price+low_price)/2 , max_price, low_price
end
function OnCalculate(index)
if index > 1 then
local spread = getSpread(index - 1)
if spread then
SetValue(index - 1, 1, spread)
SetValue(index , 2, med_price)
SetValue(index , 3, max_price)
SetValue(index , 4, low_price)
end
end
return getSpread(index), med_price , max_price, low_price
end
Извиняюсь, я не программист, лепил из того что было...