<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title>Форум QUIK [тема: Прошу помочь исправить ошибку в коде]</title>
		<link>http://forum.quik.ru</link>
		<description>Новое в теме Прошу помочь исправить ошибку в коде форума  на сайте Форум QUIK [forum.quik.ru]</description>
		<language>ru</language>
		<docs>http://backend.userland.com/rss2</docs>
		<pubDate>Sat, 02 May 2026 14:11:36 +0300</pubDate>
		<item>
			<title>Прошу помочь исправить ошибку в коде</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message57821/topic6688/">Прошу помочь исправить ошибку в коде</a></b> <i>Скрипт при запуске в QUIK выдаёт ошибку: &quot;18: attempt to index a nil value (global 'ds')&quot;</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			<br />====quote====<br /><a class="blog-p-user-name" id="bp_fDF2T0XC" href="/user/17/" bx-tooltip-user-id="17">Sergey Gorokhov</a> написал:<br /> <br />====quote====<br /><noindex><a href="/user/15130/" target="_blank" rel="nofollow">Алексей</a></noindex> написал:<br />Class_Code = &quot;QJSIM&quot; &nbsp; &nbsp; &nbsp; &nbsp; -- класс торгуемого инструмента<br />=============<br /> <br />точно ли код класса указан верно?<br />Такой класс есть только на нашем демо контуре, у брокеров нужно указать TQBR<br />=============<br />Спасибо. Действительно, код класса исправил и всё заработало. <br />
			<i>07.09.2021 16:09:36, Алексей.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message57821/topic6688/</link>
			<guid>http://forum.quik.ru/messages/forum10/message57821/topic6688/</guid>
			<pubDate>Tue, 07 Sep 2021 16:09:36 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>Прошу помочь исправить ошибку в коде</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message57798/topic6688/">Прошу помочь исправить ошибку в коде</a></b> <i>Скрипт при запуске в QUIK выдаёт ошибку: &quot;18: attempt to index a nil value (global 'ds')&quot;</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			<br />====quote====<br /><a class="blog-p-user-name" id="bp_y1x6f5l0" href="/user/15130/" bx-tooltip-user-id="15130">Алексей</a> написал:<br />Class_Code = "QJSIM" &nbsp; &nbsp; &nbsp; &nbsp; -- класс торгуемого инструмента<br />=============<br /><br />точно ли код класса указан верно?<br />Такой класс есть только на нашем демо контуре, у брокеров нужно указать TQBR <br />
			<i>06.09.2021 09:50:00, Sergey Gorokhov.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message57798/topic6688/</link>
			<guid>http://forum.quik.ru/messages/forum10/message57798/topic6688/</guid>
			<pubDate>Mon, 06 Sep 2021 09:50:00 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>Прошу помочь исправить ошибку в коде</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message57797/topic6688/">Прошу помочь исправить ошибку в коде</a></b> <i>Скрипт при запуске в QUIK выдаёт ошибку: &quot;18: attempt to index a nil value (global 'ds')&quot;</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			Здравствуйте.<br />Прошу помочь устранить ошибку в коде скрипта. Скрипт при запуске в QUIK выдаёт ошибку: &quot;18: attempt to index a nil value (global &#39;ds&#39;)&quot;.<br />Вот код скрипта:<br /><br />-- переменная для прырывания цикла при срабатывании функции обратного вызова OnStop<br /><br />is_run = true<br /><br />-- присванивание переменным начальных базовых значений торгового алгоритма<br /><br />Account = &quot;L01-00000F00&quot; &nbsp; &nbsp; -- торговый счет<br />Class_Code = &quot;QJSIM&quot; &nbsp; &nbsp; &nbsp; &nbsp; -- класс торгуемого инструмента<br />Sec_Code = &quot;SBERP&quot; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- код торгуемого инструмента<br />TF = INTERVAL_D1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- торговый таймфрейм<br />g_lots = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- количество торгуемых лот<br /><br />function main()<br /> &nbsp; &nbsp;-- подписываемся на получение данных свечей по инструменту в массив ds<br /> &nbsp; &nbsp;ds=CreateDataSource (Class_Code, Sec_Code, TF )<br /> &nbsp; &nbsp;while is_run do<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sleep(1000) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- обрабатываем цикл с задержкой 1сек.<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ds:SetEmptyCallback() &nbsp;-- обновляем данные по инструменту в массиве ds<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;local serv_time=tonumber(timeformat(getInfoParam(&quot;SERVERTIME&quot;))) -- помещене в переменную времени сервера в формате HHMMSS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if isConnected()==1 and serv_time&gt;=10000 and serv_time&lt;235000 then -- проверка наличия соеденения с сервером и поподания в торговое окно<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- место для размещения торговой логики<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- расчет значения скользящей средней<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local SMA = 0<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local period = 20<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local count_candle = ds:size()<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if count_candle&gt;20 then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;local sum = 0<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for i=0 , period-1 do &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sum = sum + ds:C(count_candle-i)<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SMA = sum / period<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;local lots = get_lots() &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- получение количества лот в клиентском портфеле по инструменту<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ds:C(count_candle)&gt;SMA and lots&lt;g_lots then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- получение минимального шага цены для организации величины проскальзываня в ордере<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;local step=tonumber(getParamEx(Class_Code, Sec_Code, &quot;SEC_PRICE_STEP&quot;).param_value)<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;local price_order = ds:C(count_candle)+(step*20)<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- цена для ордера будет = цена закрытия + 20-ть минимальных шагов инст.<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;send_order(&quot;B&quot;, math.abs(g_lots-lots) , price_order)<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ds:C(count_candle)&lt;SMA and lots&gt;(g_lots*(-1)) then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- получение минимального шага цены для организации величины проскальзываня в ордере<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;local step=tonumber(getParamEx(Class_Code, Sec_Code, &quot;SEC_PRICE_STEP&quot;).param_value)<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;local price_order = ds:C(count_candle)-(step*20) &nbsp; &nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- цена для ордера будет = цена закрытия - 20-ть минимальных шагов инст.<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;send_order(&quot;S&quot;, math.abs(g_lots+lots) , price_order)<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br /> &nbsp; &nbsp;end<br /> end <br /><br />-- функция возвращает количество лот в клиентском портфеле по заданному инструменту<br />function get_lots()<br /> &nbsp; &nbsp;local lots = 0<br /> &nbsp; &nbsp;local n = getNumberOf(&quot;futures_client_holding&quot;)<br /> &nbsp; &nbsp;local futures_client_holding={} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br /> &nbsp; &nbsp;for i=0,n-1 do &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; futures_client_holding = getItem(&quot;futures_client_holding&quot;, i)<br /> &nbsp; &nbsp; &nbsp; if tostring(futures_client_holding&#91;&quot;sec_code&quot;&#93;)==Sec_Code then<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lots=tonumber(futures_client_holding&#91;&quot;totalnet&quot;&#93;)<br /> &nbsp; &nbsp; &nbsp; end<br /> &nbsp; &nbsp;end &nbsp; &nbsp; &nbsp;<br /> &nbsp; &nbsp;return lots<br />end<br />----------------------<br /><br />-- отправка транзакции<br />function send_order(operation, quantity, price) &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp;-- получение минимального шага цены для округления цены отправляемого ордера<br /> &nbsp; &nbsp;local step=tonumber(getParamEx(Class_Code, Sec_Code, &quot;SEC_PRICE_STEP&quot;).param_value)<br /> &nbsp; &nbsp;local trans_params = <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CLIENT_CODE = Account,<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CLASSCODE = Class_Code,<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SECCODE = Sec_Code,<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ACCOUNT = Account,<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TYPE = &quot;L&quot;,<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TRANS_ID = tostring(1),<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OPERATION = tostring(operation),<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;QUANTITY = tostring(math.abs(quantity)),<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PRICE = tostring(math.floor(tonumber(price)/step)*step), &nbsp;-- округление цены при отправлении транзакции<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ACTION = &quot;NEW_ORDER&quot; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp;local res = sendTransaction(trans_params)<br /> &nbsp; &nbsp;if string.len(res) ~= 0 then<br /> &nbsp; &nbsp; &nbsp; &nbsp;message(&#39;Error: &#39;..res,3)<br /> &nbsp; &nbsp; &nbsp; &nbsp;return 0<br /> &nbsp; &nbsp;else<br /> &nbsp; &nbsp; &nbsp; &nbsp;return trans_id<br /> &nbsp; &nbsp;end &nbsp; &nbsp; &nbsp;<br />end<br /><br />function OnStop(stop_flag) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br /> &nbsp; &nbsp; is_run=false<br /> &nbsp; &nbsp; stop_flag=1<br /> &nbsp; &nbsp; ds:Close() <br />end<br /><br /><br />function timeformat(time_unf)<br /> &nbsp; &nbsp; local in1, in2=0,0<br /> &nbsp; &nbsp; local time_form=0 &nbsp; &nbsp; &nbsp;<br /> &nbsp; &nbsp; in1=string.find(time_unf,&quot;:&quot; , 0)<br /> &nbsp; &nbsp; if in1~=nil and in1~=0 then<br /> &nbsp; &nbsp; &nbsp; &nbsp;in2=string.find(time_unf,&quot;:&quot; , in1+1) <br /> &nbsp; &nbsp; &nbsp; &nbsp;time_form=string.sub(time_unf, 0 ,in1-1)..string.sub(time_unf, in1+1 ,in2-1)..string.sub(time_unf, in2+1 ,string.len(time_unf))<br /> &nbsp; &nbsp; end<br /> &nbsp; &nbsp; return time_form<br />end <br />
			<i>06.09.2021 09:02:28, Алексей.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message57797/topic6688/</link>
			<guid>http://forum.quik.ru/messages/forum10/message57797/topic6688/</guid>
			<pubDate>Mon, 06 Sep 2021 09:02:28 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
	</channel>
</rss>
