<?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>Mon, 27 Apr 2026 18:58:17 +0300</pubDate>
		<item>
			<title>Помощь.</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message72498/topic8335/">Помощь.</a></b> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			Так сам квик сообщает что переменная num имеет значение nil.<br /><br />очевидно что price == nil <br />
			<i>01.11.2023 22:21:57, Станислав.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message72498/topic8335/</link>
			<guid>http://forum.quik.ru/messages/forum10/message72498/topic8335/</guid>
			<pubDate>Wed, 01 Nov 2023 22:21:57 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>Помощь.</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message72496/topic8335/">Помощь.</a></b> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			Здравствуйте. Помогите понять в чем причина. &nbsp;Quik ругается на эту строчку. <br /><br />(return math.floor (num * mult + 0.5) / mult) <br />attempt to perform arithmetic on a nil value (local &#39;num&#39;)<br /><br /><br />ACCOUNT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= &#39;NL0011100043&#39; &nbsp; -- Код счета<br />CLASS_CODE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = &#39;QJSIM&#39; &nbsp; &nbsp; &nbsp; &nbsp;-- Код класса<br />SEC_CODE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = &#39;SPBE&#39; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- Код инструмента<br />trans_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = os.time() &nbsp; &nbsp; &nbsp; -- ID транзакции<br />qty = &#39;1&#39;<br />operation= &#39;B&#39;<br />Kod_klienta = &quot;10265&quot;; -- нужно поставить свое значение<br /><br /><br />-- Округляет число до указанной точности<br />math_round = function (num, idp)<br /> &nbsp;local mult = 10^(idp or 0)<br /> &nbsp;return math.floor (num * mult + 0.5) / mult<br />end<br /><br /><br />-- Приводит переданную цену к требуемому для транзакции по инструменту виду<br />GetCorrectPrice = function(price) -- STRING<br /> &nbsp; -- Получает точность цены по инструменту<br /> &nbsp; local scale = getSecurityInfo(CLASS_CODE, SEC_CODE).scale<br /> &nbsp; -- Получает минимальный шаг цены инструмента<br /> &nbsp; local PriceStep = tonumber(getParamEx(CLASS_CODE, SEC_CODE, &quot;SEC_PRICE_STEP&quot;).param_value)<br /> &nbsp; -- Если после запятой должны быть цифры<br /> &nbsp; if scale &gt; 0 then<br /> &nbsp; &nbsp; &nbsp;price = tostring(price)<br /> &nbsp; &nbsp; &nbsp;-- Ищет в числе позицию запятой, или точки<br /> &nbsp; &nbsp; &nbsp;local dot_pos = price:find(&#39;.&#39;)<br /> &nbsp; &nbsp; &nbsp;local comma_pos = price:find(&#39;,&#39;)<br /> &nbsp; &nbsp; &nbsp;-- Если передано целое число<br /> &nbsp; &nbsp; &nbsp;if dot_pos == nil and comma_pos == nil then<br /> &nbsp; &nbsp; &nbsp; &nbsp; -- Добавляет к числу &#39;,&#39; и необходимое количество нулей и возвращает результат<br /> &nbsp; &nbsp; &nbsp; &nbsp; price = price..&#39;,&#39;<br /> &nbsp; &nbsp; &nbsp; &nbsp; for i=1,scale do price = price..&#39;0&#39; end<br /> &nbsp; &nbsp; &nbsp; &nbsp; return price<br /> &nbsp; &nbsp; &nbsp;else -- передано вещественное число &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; -- Если нужно, заменяет запятую на точку <br /> &nbsp; &nbsp; &nbsp; &nbsp; if comma_pos ~= nil then price:gsub(&#39;,&#39;, &#39;.&#39;) end<br /> &nbsp; &nbsp; &nbsp; &nbsp; -- Округляет число до необходимого количества знаков после запятой<br /> &nbsp; &nbsp; &nbsp; &nbsp; price = math_round(tonumber(price), scale)<br /> &nbsp; &nbsp; &nbsp; &nbsp; -- Корректирует на соответствие шагу цены<br /> &nbsp; &nbsp; &nbsp; &nbsp; price = math_round(price/PriceStep)*PriceStep<br /> &nbsp; &nbsp; &nbsp; &nbsp; price = string.gsub(tostring(price),&#39;&#91;%.&#93;+&#39;, &#39;,&#39;)<br /> &nbsp; &nbsp; &nbsp; &nbsp; return price<br /> &nbsp; &nbsp; &nbsp;end<br /> &nbsp; else -- После запятой не должно быть цифр<br /> &nbsp; &nbsp; &nbsp;-- Корректирует на соответствие шагу цены<br /> &nbsp; &nbsp; &nbsp;price = math_round(price/PriceStep)*PriceStep<br /> &nbsp; &nbsp; &nbsp;return tostring(math.floor(price))<br /> &nbsp; end<br />end<br /><br /><br /><br /> &nbsp; -- Выставляет заявку<br /> &nbsp; -- Получает ID для следующей транзакции<br /> &nbsp; trans_id = trans_id + 1<br /> &nbsp; -- Заполняет структуру для отправки транзакции<br /> &nbsp; local T = {}<br /> &nbsp; T&#91;&#39;CLIENT_CODE&#39;&#93;= Kod_klienta<br /> &nbsp; T&#91;&#39;TRANS_ID&#39;&#93; &nbsp; = tostring(trans_id) &nbsp; &nbsp; -- Номер транзакции<br /> &nbsp; T&#91;&#39;ACCOUNT&#39;&#93; &nbsp; &nbsp;= ACCOUNT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- Код счета<br /> &nbsp; T&#91;&#39;CLASSCODE&#39;&#93; &nbsp;= CLASS_CODE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- Код класса<br /> &nbsp; T&#91;&#39;SECCODE&#39;&#93; &nbsp; &nbsp;= SEC_CODE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- Код инструмента<br /> &nbsp; T&#91;&#39;ACTION&#39;&#93; &nbsp; &nbsp; = &#39;NEW_ORDER&#39; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- Тип транзакции (&#39;NEW_ORDER&#39; - новая заявка) &nbsp; &nbsp; &nbsp;<br /> &nbsp; T&#91;&#39;TYPE&#39;&#93; &nbsp; &nbsp; &nbsp; = &#39;L&#39; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- Тип (&#39;L&#39; - лимитированная, &#39;M&#39; - рыночная)<br /> &nbsp; T&#91;&#39;OPERATION&#39;&#93; &nbsp;= operation &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- Операция (&#39;B&#39; - buy, или &#39;S&#39; - sell)<br /> &nbsp; T&#91;&#39;PRICE&#39;&#93; &nbsp; &nbsp; &nbsp;= GetCorrectPrice(price) -- Цена<br /> &nbsp; T&#91;&#39;QUANTITY&#39;&#93; &nbsp; = tostring(qty) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- Количество<br /> &nbsp; <br />	function main()<br />	 &nbsp; -- Отправляет транзакцию<br />	 &nbsp; local Res = sendTransaction(T)<br />	 &nbsp; -- Если при отправке транзакции возникла ошибка<br />	 &nbsp; if Res ~= &#39;&#39; then<br />		 &nbsp;-- Выводит сообщение об ошибке<br />		 &nbsp;message(&#39;Ошибка транзакции открытия/закрытия: &#39;..Res)<br />	 &nbsp; end<br />	end <br />
			<i>01.11.2023 19:22:01, Сергей ВАТ.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message72496/topic8335/</link>
			<guid>http://forum.quik.ru/messages/forum10/message72496/topic8335/</guid>
			<pubDate>Wed, 01 Nov 2023 19:22:01 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
	</channel>
</rss>
