Цитата |
---|
Egor Zaytsev написал: Нужен какой нибудь конкретный пример. Сообщите версию рабочего места и выложите для примера индикатор. |
Версия 8.6.0.97
Settings = {
Name = "%WR(BR_1)-STAT+Line",
Period = 14,
line = {{
Name = "Horizontal line (top)",
Type = TYPE_LINE,
Color = RGB(100, 100, 255)
},
{
Name = "Horizontal line (bottom)",
Type = TYPE_LINE,
Color = RGB(100, 100, 255)
},
{
Name = "WR",
Type = TYPE_LINE,
Color = RGB(255, 128, 0)
}
},
Round = "off",
Multiply = 1,
Horizontal_line="30" -- Задается отступ вверх/вниз от центральной линии(-50)
}
function Init()
func = WR()
return #Settings.line
end
--local Sound = 1 -- Если <1>, то проигрываем звук
local ldt = 0 -- last day-time
-- подключить библиотеку w32
local w32 = require ("w32") -- добавляем библиотеку
local FName = "c:\\BCS_Work\\Stat.txt"
local LastPrc = 0
local LastN = 0
local LastOut = -50
-- функция проигрывания файла
-- вызов: PlaySoundFile("имя файла")
function PlaySoundFile(file_name)
w32.mciSendString("CLOSE QUIK_MP3")
w32.mciSendString("OPEN \"" .. file_name .. "\" TYPE MpegVideo ALIAS QUIK_MP3")
w32.mciSendString("PLAY QUIK_MP3")
end
function OnCalculate(Index)
local N=getNumCandles("BR_1") -- Получаем число свечей в графике
local Out = ConvertValue(Settings, func(Index, Settings))
local HL = tonumber(Settings.Horizontal_line)
local HLine = -50+HL
local LLine = -50-HL
if HL then
dt1 = tonumber(os.date("%Y%m%d%H%M%S"))
if (Out == 0 or Out==-100) then
if N==Index then
if LastPrc ~= C(Index) or LastN ~= N then
local FStat = io.open(FName, "a")
FStat:write(os.date("%Y/%m/%d %H:%M:%S") .. " " .. tostring(C(Index)) .. " " .. tostring(Out) .. "\n")
FStat:flush()
FStat:close()
message("WR = " .. tostring(Out) .. "; EP = "..tostring(C(Index)))
LastPrc = C(Index)
LastN = N
end
if dt1-ldt > 10 then
if Out == 0 then
PlaySoundFile("C:\\BCS_Work\\QUIK_BCS\\LuaIndicators\\Higher.wav")
else
PlaySoundFile("C:\\BCS_Work\\QUIK_BCS\\LuaIndicators\\Paday.wav")
end
ldt = dt1
end
end
else
if N==Index then
if (Out <= HLine and LastOut > HLine) or (Out >= LLine and LastOut < LLine) then
if dt1-ldt > 10 then
PlaySoundFile("C:\\BCS_Work\\QUIK_BCS\\LuaIndicators\\Ring04.wav")
ldt = dt1
end
end
end
end
LastOut = Out
return HLine,LLine,Out
else
return nil,nil,Out
end
end
function WR() --Williams' % Range ("WR")
local H_tmp={}
local L_tmp={}
local it = {p=0, l=0}
return function (I, Fsettings, ds)
local Fsettings=(Fsettings or {})
local P = (Fsettings.Period or 10)
if (P>0) then
if I == 1 then
H_tmp={}
L_tmp={}
it = {p=0, l=0}
end
if CandleExist(I,ds) then
if I~=it.p then it={p=I, l=it.l+1} end
H_tmp[Squeeze(it.l,P)+1] = GetValueEX(it.p,HIGH,ds)
L_tmp[Squeeze(it.l,P)+1] = GetValueEX(it.p,LOW,ds)
if it.l>P then
local val_h=math.max(unpack(H_tmp))
local val_l=math.min(unpack(L_tmp))
return -100*(val_h-GetValueEX(it.p,CLOSE,ds))/(val_h-val_l)
end
end
end
return nil
end
end
SMA,MMA,EMA,WMA,SMMA,VMA = "SMA","MMA","EMA","WMA","SMMA","VMA"
OPEN,HIGH,LOW,CLOSE,VOLUME,MEDIAN,TYPICAL,WEIGHTED,DIFFERENCE,ANY = "O","H","L","C","V","M","T","W","D","A"
function CandleExist(I,ds)
return (type©=="function" and C(I)~=nil) or
(type(ds)=="table" and (ds[I]~=nil or (type(ds.Size)=="function" and (I>0) and (I<=ds:Size()))))
end
function Squeeze(I,P)
return math.fmod(I-1,P+1)
end
function ConvertValue(T,...)
local function r(V, R)
if R and string.upper®== "ON" then R=0 end
if V and tonumber® then
if V >= 0 then return math.floor(V * 10^R + 0.5) / 10^R
else return math.ceil(V * 10^R - 0.5) / 10^R end
else return V end
end
local arg = {...}
arg.n = select('#', ...)
if arg.n > 0 then
for i = 1, arg.n do
arg[i]=arg[i] and r(arg[i] * ((T and T.Multiply) or 1), (T and T.Round) or "off")
end
return unpack(arg)
else return nil end
end
function GetValueEX(I,VT,ds)
VT=(VT and string.upper(string.sub(VT,1,1))) or ANY
if VT == OPEN then --Open
return (O and O(I)) or (ds and ds:O(I))
elseif VT == HIGH then --High
return (H and H(I)) or (ds and ds:H(I))
elseif VT == LOW then --Low
return (L and L(I)) or (ds and ds:L(I))
elseif VT == CLOSE then --Close
return (C and C(I)) or (ds and ds:C(I))
elseif VT == VOLUME then --Volume
return (V and V(I)) or (ds and ds:V(I))
elseif VT == MEDIAN then --Median
return ((GetValueEX(I,HIGH,ds) + GetValueEX(I,LOW,ds)) / 2)
elseif VT == TYPICAL then --Typical
return ((GetValueEX(I,MEDIAN,ds) * 2 + GetValueEX(I,CLOSE,ds))/3)
elseif VT == WEIGHTED then --Weighted
return ((GetValueEX(I,TYPICAL,ds) * 3 + GetValueEX(I,OPEN,ds))/4)
elseif VT == DIFFERENCE then --Difference
return (GetValueEX(I,HIGH,ds) - GetValueEX(I,LOW,ds))
else --Any
return (ds and ds[I])
end
return nil
end