-- График должен быть открыт в Quik'е
Class = "SPBFUT" -- "CETS_MTL" "CETS"
SecId="BRK4" -- "NGJ4" "GLDRUB_TOM" "USD000UTSTOM" "SiZ3"
Intrvl = INTERVAL_H1 -- D1 -- M5
Header = "<TICKER>;<PER>;<DATE>;<TIME>;"..
"<OPEN>;<HIGH>;<LOW>;<CLOSE>;<VOL>"
Period = "60" -- Дневки - 0, W1, MN1, H4, H2 - недопустимо
function Log (i)
local t = DS:T(i)
local ymd = string.format ("%04d%02d%02d", t.year, t.month, t.day)
local hms = string.format ("%02d%02d%02d", t.hour, t.min, t.sec);
if not (IniDt <= ymd and ymd <= FinDt) or
not (IniTm <= hms and hms <= FinTm) then return end
local str = string.format ("%s;%s;%s;%s;%.4f;%.4f;%.4f;%.4f;%.0f\n"
,SecId, Period, ymd, hms
,DS:O(i), DS:H(i), DS:L(i), DS:C(i), DS:V(i))
F:write (str)
end -- Log()
function OnInit (scriptPath)
qu = require ("QuikUtil(qu)") -- lu,qc,tu
ScriptDir, ScriptName = lu.

-- Настройки
SEC_CODE = "SBER" -- Код инструмента
CLASS_CODE = "TQBR" -- Код класса инструмента
SHORT_MA_PERIOD = 10 -- Период короткой скользящей средней
LONG_MA_PERIOD = 50 -- Период длинной скользящей средней
QTY = 1 -- Количество лотов
-- Переменные
short_ma = {}
long_ma = {}
prices = {}
position = 0 -- Текущая позиция: 0 - нет позиции, 1 - лонг, -1 - шорт
-- Функция для расчета скользящей средней
function calculate_ma(prices, period)
local sum = 0
for i = #prices-period+1, #prices do
sum = sum + prices[i]
end
return sum / period
end
-- Функция для обработки новых тиков
function OnAllTrade(alltrade)
if alltrade.sec_code == SEC_CODE and alltrade.class_code == CLASS_CODE then
table.insert(prices, alltrade.price)
if #prices >= LONG_MA_PERIOD then
table.

local Titles, Entries, Desk = {}, {}, {}
local Wn1_Hndl
local Wn1_Field1, Wn1_Field2, Wn1_Field3, Wn1_Field4, Wn1_Field5
= "Код CALL", "Страйк", "Дельта CALL", "Дельта расч", "Теор. расч"
function OnInit (scriptPath)
qu = require ("QuikUtil(qu)") -- qc, lu, tu
blk = require ("BlackScholes(blk)")
glb_ScriptDir, glb_ScriptName = lu.SplitPath (scriptPath)
message (glb_ScriptName .." started")
server = require ("OptionDesk")
end -- OnInit()
function OnStop (signal)
if Wn1_Hndl then DestroyTable (Wn1_Hndl) end
StopFlag = true
return 1000 -- 1 sec
end
local function ShowWin (cols)
for k = 1, #Desk do
local calCode = Desk[k][Entries[Wn1_Field1]]
if calCode:sub (3,3) == "0" then
calCode = calCode:sub (1,2) .