Блог им. autotrade

--[[
средние на разных TF(15/60/D) одной длины
--]]
Settings=
{
Name = "SMA_mult_template_v1", -- indicator name
ln=200, -- period
line=
{
{
Name = "SMA_TEMPL",
Type =TYPE_LINE,
Width = 1,
Color = RGB(0,0,255)
},
{
Name = "cur3",
Type =TYPE_LINE,
Width = 1,
Color = RGB(0,0,255)
},
{
Name = "cur4",
Type =TYPE_LINE,
Width = 1,
Color = RGB(0,0,255)
}
}
}
function Init()
return 3
end
function OnCalculate(index)
ln = Settings.ln
if index == 1 then
hour = {}
day = {}
sum = {}
sma = {}
n = {}
sumh = {}
smah = {}
nh = {}
nhi = {}
sumd = {}
smad = {}
nd = {}
ndi = {}
sum[index] = O(index)
n[index]=1
sumh[index] = O(index)
nh[index]=1
nhi[index]=1
sumd[index] = O(index)
nd[index]=1
ndi[index]=1
hour[index] = T(index).hour
day[index] = T(index).day
else
if index > ln then
sum[index] = sum[index-1] + O(index)
sum[index] = sum[index] - O(index-ln)
n[index] = n[index-1]
else
sum[index] = sum[index-1] + O(index)
n[index] = n[index-1] + 1
end
if hour[index-1] ~= T(index).hour then
nh[index] = nh[index-1] + 1
nhi[nh[index]] = index
if nh[index] > ln then
sumh[index] = sumh[index-1] + O(index)-O(nhi[nh[index]-ln])
smah[index] = sumh[index]/ln
else
sumh[index] = sumh[index-1] + O(index)
smah[index] = nil
end
else
nh[index] = nh[index-1]
sumh[index] = sumh[index-1]
smah[index] = nil
end
if day[index-1] ~= T(index).day then
nd[index] = nd[index-1] + 1
ndi[nd[index]] = index
if nd[index] > ln then
sumd[index] = sumd[index-1] + O(index)-O(ndi[nd[index]-ln])
smad[index] = sumd[index]/ln
else
sumd[index] = sumd[index-1] + O(index)
smad[index] = nil
end
else
nd[index] = nd[index-1]
sumd[index] = sumd[index-1]
smad[index] = nil
end
hour[index] = T(index).hour
day[index] = T(index).day
end
if n[index] ~= 0 then
sma[index] = sum[index]/n[index]
end
return sma[index], smah[index], smad[index]
end
ЕМА50 на н4 = ЕМА200 на н1 = ЕМА 800 на м15 ну и т.д.