если индикатор больше 0, то покупаем, если ниже то продаем
скачать можно здесь:dropmefiles.com/09FCu
как устанавливать смотрите предыдущие статьи:
https://smart-lab.ru/blog/528424.php
название STATDIV3 это доработанный STATDIV
поведение индикатора на графике:
сам код индикатора:
Settings={
Name="STATDIV3",
period=50,
line=
{
{
Name="curve",
Color=RGB(0,0,255),
Type=TYPE_LINE,
Width=1
},
{
Name="line",
Color=RGB(255,0,0),
Type=TYPE_LINE,
Width=1
},
{
Name="MA",
Color=RGB(0,0,255),
Type=TYPE_LINE,
Width=1
},
{
Name="MA2",
Color=RGB(0,128,128),
Type=TYPE_LINE,
Width=1
},
{
Name="line2",
Color=RGB(0,0,255),
Type=TYPE_LINE,
Width=1
},
{
Name="line3",
Color=RGB(0,128,128),
Type=TYPE_LINE,
Width=1
}
}
}
function Init()
cache_ind={}
cache_ind2={}
cache_ind3={}
return 2
end
function OnCalculate(index)
if index < Settings.period then
return nil
else
local sum1=0
local sum2=0
local sum0=0
local sum02=0
local sum03=0
for i=index-Settings.period+1, index do
do
if C(i) > O(i) then
sum1 = sum1 + C(i) - O(i)
sum2 = sum2 + C(i) - O(i)
else
sum2 = sum2 + O(i) - C(i)
end
end
cache_ind[index] = sum1/sum2
if index > Settings.period+12 then
--[[
sum0 = 1*cache_ind[index]+
(1)*cache_ind[index-1]+
(1)*cache_ind[index-2]+
(1)*cache_ind[index-3]+
(1)*cache_ind[index-4]+
(1)*cache_ind[index-5]+
(1)*cache_ind[index-6]+
(1)*cache_ind[index-7]+
(1)*cache_ind[index-8]+
(1/2)*cache_ind[index-9]+
(1/3)*cache_ind[index-10]+
(1/4)*cache_ind[index-11]+
(1/5)*cache_ind[index-12]
--]]
sum0 = 1*cache_ind[index]+
(1/2)*cache_ind[index-1]+
(1/3)*cache_ind[index-2]+
(1/4)*cache_ind[index-3]+
(1/5)*cache_ind[index-4]+
(1/6)*cache_ind[index-5]+
(1/7)*cache_ind[index-6]+
(1/8)*cache_ind[index-7]+
(1/9)*cache_ind[index-8]+
(1/10)*cache_ind[index-9]+
(1/11)*cache_ind[index-10]+
(1/12)*cache_ind[index-11]+
(1/13)*cache_ind[index-12]
end
--[[
sum0 = sum0/(1+1+1+1+1+1+1+1+1+1/2+1/3+1/4+1/5)
--]]
sum0 = sum0/(1+1/2+1/3+1/4+1/5+1/6+1/7+1/8+1/9+1/10+1/11+1/12+1/13)
cache_ind2[index] = sum0
if index > Settings.period+50 then
sum02 = 1*cache_ind2[index]+
(1)*cache_ind2[index-1]+
(1)*cache_ind2[index-2]+
(1)*cache_ind2[index-3]+
(1)*cache_ind2[index-4]+
(1)*cache_ind2[index-5]+
(1)*cache_ind2[index-6]+
(1)*cache_ind2[index-7]+
(1/2)*cache_ind2[index-8]+
(1/3)*cache_ind2[index-9]+
(1/4)*cache_ind2[index-10]+
(1/5)*cache_ind2[index-11]+
(1/6)*cache_ind2[index-12]
--[[
sum02 = 1*cache_ind2[index]+
(1/2)*cache_ind2[index-1]+
(1/3)*cache_ind2[index-2]+
(1/4)*cache_ind2[index-3]+
(1/5)*cache_ind2[index-4]+
(1/6)*cache_ind2[index-5]+
(1/7)*cache_ind2[index-6]+
(1/8)*cache_ind2[index-7]+
(1/9)*cache_ind2[index-8]+
(1/10)*cache_ind2[index-9]+
(1/11)*cache_ind2[index-10]+
(1/12)*cache_ind2[index-11]+
(1/13)*cache_ind2[index-12]
--]]
end
sum02 = sum02/(1+1+1+1+1+1+1+1+1/2+1/3+1/4+1/5+1/6)
--[[
sum02 = sum02/(1+1/2+1/3+1/4+1/5+1/6+1/7+1/8+1/9+1/10+1/11+1/12+1/13)
--]]
cache_ind3[index] = sum0 - sum02
if index > Settings.period+50 then
sum03 = 1*cache_ind3[index]+
(1/2)*cache_ind3[index-1]+
(1/3)*cache_ind3[index-2]+
(1/4)*cache_ind3[index-3]+
(1/5)*cache_ind3[index-4]+
(1/6)*cache_ind3[index-5]+
(1/7)*cache_ind3[index-6]+
(1/8)*cache_ind3[index-7]+
(1/9)*cache_ind3[index-8]+
(1/10)*cache_ind3[index-9]+
(1/11)*cache_ind3[index-10]+
(1/12)*cache_ind3[index-11]+
(1/13)*cache_ind3[index-12]
end
sum03 = sum03/(1+1/2+1/3+1/4+1/5+1/6+1/7+1/8+1/9+1/10+1/11+1/12+1/13)
end
if sum1/sum2 > 0.5 and sum03 > 0 then
sum1 = sum03
else
if sum1/sum2 < 0.5 and sum03 < 0 then
sum1 = sum03
else
sum1 = 0
end
end
return sum1, 0
end
end
всем удачи!