Использовал этот Измеритель, чтобы сравнивать показания индикаторов Квика с оригинальной скользяшкой Б.Вильямса.
Возник такой вопрос, я создаю новую скользяшку при помощи возвратной функции r_RMA(), но таким способом я могу создать две скользяшки. А при попытке добавить третью код ломается (Квик не может отрендерить три линии).
Возник такой вопрос, я создаю новую скользяшку при помощи возвратной функции r_RMA(), но таким способом я могу создать две скользяшки. А при попытке добавить третью код ломается (Квик не может отрендерить три линии).
| Код |
|---|
Settings = {
Name = "*GAT (Bill Williams Alligator)",
Round = "off",
VType = "Median", --Median price
-- parameters
metod = "RMA",
kScaleFakr = 0.0001,
-- script is working up until I add third moving avrg line
schift_A = 3, --short shift forward
period_A = 5, --short period
schift_B = 5, --long shift forward
period_B = 8, --long period
--
line = {
{
Name = "GAT_0",
Type = TYPE_LINE,
Width = 1,
Color = RGB(0,255,0)
},{
Name = "GAT_1",
Type = TYPE_LINE,
Width = 1,
Color = RGB(255,159,64)
}
}
}
function Init()
func = r_MAIN()
return #Settings.line
end
function OnCalculate(Index)
return func(Index, Settings)
end
function r_MAIN()
local vA_MA=r_RMA()
local vB_MA=r_RMA()
return function(I, Fsettings, ds)
local Fsettings=(Fsettings or {})
local R = (Fsettings.Round or "off")
local VT = (Fsettings.VType or "Median")
local oA,oB --output values
oA = nil; oB = nil;
--
local M = (Fsettings.metod or "RMA")
local k_sc = (Fsettings.kScaleFakr or 0.0001)
--
local s_A = (Fsettings.schift_A or 3)
local p_A = (Fsettings.period_A or 5)
local s_B = (Fsettings.schift_B or 5)
local p_B = (Fsettings.period_B or 8)
-- local s_C = (Fsettings.schift_C or 8)
-- local p_C = (Fsettings.period_C or 13)
--
vA = vA_MA(I, VT, ds, p_A)
vB = vB_MA(I, VT, ds, p_B)
--
if ( vA ~= nil ) then oA=vA end
if ( vB ~= nil ) then oB=vB end
--
return oA,oB
end
end
-----------------
function r_RMA()
local RMA={}
return function(I ,VT, ds, Period)
local P = ((Period) or 5)
local value = nil
local grace = 15 --grace period to filter out bad initial period
--
-- we perform logarithm over price often
-- so we must use positive value, this time its 1.0
if (I==1) then --protection from candle(1) not-existing
RMA[I]=1.0; return RMA[I];
end
--
if (CandleExist(I)) then
value = (H(I)+L(I))*0.5 --median
if (value~=nil) then
if (I < grace) then
-- early values are getting averaged
-- so they get faster to real indicator
RMA[I] = 0.5*( value + RMA[I-1] )
else
RMA[I] = ( (P-1) * RMA[I-1] + value )/P
end
else -- candle exist, but value does not
RMA[I]=RMA[I-1]
end
--
else -- candle does not exist
RMA[I]=RMA[I-1]
end
--
return RMA[I]
end
end
|