Синяя точка под свечой — сигнал на покупку, красная над свечой — сигнал на продажу.
Настройки индикатора:
Параметр RISK — чем больше значение, тем реже сигналы.
Код нужно сохранить в файл с расширением .lua и поместить в папку LuaIndicators в папке квика (создать, если нет).
Код:
Settings=
{
Name = «ASCTrend LUA&»,
RISK = 3,
line =
{
{
Name = «asc_buy»,
Color = RGB(40,240,250),
Type = TYPE_POINT,
Width = 6
}---[[
,{
Name = «asc_sell»,
Color = RGB(255,140,250),
Type = TYPE_POINT,
Width = 6
}
--]]
}
}
value10=nil
value11=nil
x1 = nil
x2 = nil
min_rates_total = nil
WPR_Handle = {}
--[[ инициализация индикатора
--]]
function Init()
x1=67+Settings.RISK
x2=33-Settings.RISK
value10=2
value11=value10
min_rates_total = math.max( 3 + Settings.RISK * 2, 4 ) + 1
return 2
end
--[[ вычисление индикатора
Функция вызывается при поступлении новой или изменении существующей свечки в источнике данных для индикатора.
Параметры
index – индекс свечки в источнике данных. Начинается с «1».
--]]
function OnCalculate(index)
if index < min_rates_total then
return nil, nil
end
Vel = 0
WPR={}
local bar = index
Range=0
AvgRange=0
— здесь движемся в прошлое, от текущего бара bar
for count = bar, bar-9, -1 do
AvgRange = AvgRange + math.abs(H(count)-L(count))
end
Range = AvgRange/10
count = bar
TrueCount = 0
— движемся от бара bar в прошлое
while count > bar-9 and TrueCount < 1 do
if math.abs(O(count) — C(count-1)) >= Range * 2 then
TrueCount = TrueCount + 1
end
count = count — 1
end
if TrueCount>=1 then
MRO1=count
else
MRO1=-1
end
count = bar
TrueCount = 0
— движемся от бара bar в прошлое
while count > bar-6 and TrueCount < 1 do
if math.abs(C(count-3) — C(count)) >= Range * 4.6 then
TrueCount = TrueCount + 1
end
count = count — 1
end
if TrueCount>=1 then
MRO2=count
else
MRO2=-1
end
if MRO1>-1 then
value11=0
else
value11=value10
end
if MRO2>-1 then
value11=1
else
value11=value10
end
WPR_Handle[0] = iWPR(bar, 3)
WPR_Handle[1] = iWPR(bar, 4)
WPR_Handle[2] = iWPR(bar, 3+Settings.RISK*2)
--получить из индикатора WPR одно значение.
WPR[0] = WPR_Handle[value11]
if WPR[0] == nil then
return nil, nil
end
value2 = 100 — math.abs(tonumber(WPR[0]))
value3 = 0
if value2 < x2 then
iii=1
--go to past
while bar-iii > 1 do
WPR_Handle[0] = iWPR(bar-iii, 3)
WPR_Handle[1] = iWPR(bar-iii, 4)
WPR_Handle[2] = iWPR(bar-iii, 3+Settings.RISK*2)
WPR[0] = WPR_Handle[value11]
if WPR[0] == nil then
return nil, nil
end
Vel=100-math.abs(tonumber(WPR[0]))
if(Vel >= x2 and Vel <= x1) then
iii = iii + 1
else
break
end
end
if Vel > x1 then
value3 = H(bar) + Range*0.5
return nil, value3
end
end
if value2 > x1 then
iii=1
while bar-iii > 1 do
WPR_Handle[0] = iWPR(bar-iii, 3)
WPR_Handle[1] = iWPR(bar-iii, 4)
WPR_Handle[2] = iWPR(bar-iii, 3+Settings.RISK*2)
WPR[0] = WPR_Handle[value11]
if WPR[0] == nil then
return nil, nil
end
Vel=100-math.abs(tonumber(WPR[0]))
if(Vel>=x2 and Vel<=x1) then
iii = iii + 1
else
break
end
end
if Vel < x2 then
value3=L(bar)-Range*0.5
return value3, nil
end
end
return nil, nil
end
--[[ функция вычисления индикатора Williams percent range
Параметры
index — индекс текущей свечи
n — количество периодов (свечей), включая последнюю, т.е.:
если n=3, тогда считаем по 4-м свечам, от index-3 по index включительно
--]]
function iWPR(index, n)
--[[ формула WPR
HIGH(n)-CLOSE
WRP = — * 100
HIGH(n)-LOW(n)
Where:
CLOSE — is last closing price;
HIGH(n) — is the highest high over a number (n) of previous periods;
LOW(n) — is the lowest low over a number (n) of previous periods.
--]]
if index < n + 1 then
return nil
else
--let's find highest and lowest values
local highestHigh = H(index — n)
local lowestLow = L(index — n)
for i = index — n + 1, index do
if H(i) > highestHigh then
highestHigh = H(i)
end
if L(i) < lowestLow then
lowestLow = L(i)
end
end
wpr = ((highestHigh — C(index)) / (highestHigh — lowestLow)) * (-100)
return wpr
end
end