Блог им. autotrade

--[[
вопросы к автору: https://smart-lab.ru/profile/autotrade/
Индикатор: адаптивная среднияя, задается минимаьный период,
на котором не может быть больше одного пересечения с ценой
параметры:
per - период поиска пересечений
SLP - стоплосс
sign - признак показывать сигналы
prf - признак показывать профит
tar - признак тариф
--]]
Settings={
Name="ADAPT_MA_PER_v1",
per=30,
-- SLP=2.0,
sign=0,
prf=0,
tar=0.03,
line=
{
{
Name = "cur1",
Type =TYPE_LINE,
Width = 2,
Color = RGB(255,0,255)
},
{
Name = "cur2",
Type =TYPE_LINE,
Width = 2,
Color = RGB(0,0,255)
},
{
Name = "TRIANGLE_DOWN",
Type =TYPE_TRIANGLE_DOWN,
Width = 5,
Color = RGB(255, 0, 0)
},
{
Name = "TRIANGLE_UP",
Type =TYPE_TRIANGLE_UP,
Width = 5,
Color = RGB(0, 0, 255)
},
{
Name = "cur5",
Type =TYPE_POINT,
Width = 5,
Color = RGB(255, 0, 255)
},
{
Name = "cur6",
Type =TYPE_POINT,
Width = 5,
Color = RGB(0, 0, 255)
},
{
Name = "cur7",
Type =TYPE_LINE,
Width = 2,
Color = RGB(255,0,0)
},
{
Name = "cur8",
Type =TYPE_LINE,
Width = 2,
Color = RGB(0,0,0)
}
}
}
function Init()
return 8
end
function OnCalculate(index)
--[[ --]]
per = Settings.per
if index == 1 then
sma = {}
sma[index] = O(index)
else
sma[index] = sma[index-1] + O(index)
end
pi = 10
if index > per then
for p = 20, 100, 5 do
cnt = 0
if index > p then
--y = (sma[index] - sma[index-p])/p
if index-p-per > 2 then
for i = index-1, index-per, -1 do
if i > p then
y = (sma[i] - sma[i-p])/p
y1 = (sma[i-1] - sma[i-p-1])/p
if O(i) > y and O(i-1) <= y1 or
O(i) < y and O(i-1) >= y1 then
cnt = cnt + 1 -- intersection
end
end
end
end
end
if cnt < 2 then
pi = p
break
end
end
end
ln2 = pi
if index == 1 then
sum01 = {}
sum01[index] = O(index)
ma01 = {}
else
sum01[index] = sum01[index-1] + O(index)
if index > ln2 then
ma01[index] = (sum01[index] - sum01[index-ln2])/ln2
else
ma01[index] = O(index)
end
end
SLP = Settings.SLP
-- trades
if index == 1 then
prof = {}
pos = {}
SLV = {}
deal = {}
dealx = {}
prof[index] = 0
pos[index] = 0
SLV[index] = 0
deal[index] = 0
dealx[index] = 1
else
prof[index] = prof[index-1]
pos[index] = pos[index-1]
SLV[index] = SLV[index-1]
deal[index] = deal[index-1]
dealx[index] = dealx[index-1]
if
(
O(index) > ma01[index] and pos[index] ~= 1
)
then -- long
pos[index] = 1
deal[index] = O(index)
dealx[index] = index
SLV[index] = SLP*O(index)/100
end
if
(
O(index) < ma01[index] and pos[index] ~= -1
)
then -- short
pos[index] = -1
deal[index] = O(index)
dealx[index] = index
SLV[index] = SLP*O(index)/100
end
end
--[[--]]
if deal[index] ~= 0 and pos[index] == 1 and
deal[index] - O(index) > SLV[index]--SLP*deal[index]/100
then -- cash
pos[index] = 0
deal[index] = 0
dealx[index] = 1
else
if deal[index] ~= 0 and pos[index] == -1 and
O(index) - deal[index] > SLV[index]--SLP*deal[index]/100
then -- cash
pos[index] = 0
deal[index] = 0
dealx[index] = 1
end
end
--[[
--]]
if index == Size() then
if Settings.sign == 1 then
for i = 2, Size() do
if pos[i] ~= nil and pos[i-1] ~= nil then
if pos[i-1] ~= 1 and pos[i] == 1 then
SetValue(i, 4, O(i))
else
if pos[i-1] ~= -1 and pos[i] == -1 then
SetValue(i, 3, O(i))
else
SetValue(i, 3, nil)
SetValue(i, 4, nil)
end
if pos[i] ~= pos[i-1] and pos[i] == 0 then
if pos[i-1] == 1 then
SetValue(i, 5, O(i))
else
SetValue(i, 6, O(i))
end
end
end
end
end
end
end
--[[--]]
-- profit
if Settings.prf==1 then
if pos[index-1] ~= nil then
if pos[index-1] == 1 then
prof[index] = prof[index-1] + (O(index) - O(index-1))
end
if pos[index-1] == -1 then
prof[index] = prof[index-1] + (O(index-1) - O(index))
end
if pos[index-1] == 0 then
prof[index] = prof[index-1]
end
if pos[index] ~= pos[index-1] then
if pos[index] == 0 or pos[index-1] == 0 then
prof[index] = prof[index] - Settings.tar*O(index)/100
else
prof[index] = prof[index] - 2*Settings.tar*O(index)/100
end
end
end
end
if Settings.prf==1 then
return prof[index] --per1[index], per2[index]
else
if Settings.sign==1 then
return nil
else
return ma01[index]
end
end
end
Это Арно-Леру? Или другая?
Но уже понятно, что другая. Сколько этих ма-шек развелось, и не сосчитать ))