<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title>Форум QUIK [тема: getCandlesByIndex  в индикаторе]</title>
		<link>http://forum.quik.ru</link>
		<description>Новое в теме getCandlesByIndex  в индикаторе форума  на сайте Форум QUIK [forum.quik.ru]</description>
		<language>ru</language>
		<docs>http://backend.userland.com/rss2</docs>
		<pubDate>Fri, 01 May 2026 11:59:18 +0300</pubDate>
		<item>
			<title>getCandlesByIndex  в индикаторе</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message51805/topic4571/">getCandlesByIndex  в индикаторе</a></b> <i>Как используется функция getCandlesByIndex в  индикаторе?</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			<br />====quote====<br /><a class="blog-p-user-name" id="bp_ptE1BH5X" href="/user/13008/" bx-tooltip-user-id="13008">Дмитрий</a> написал:<br /> function &nbsp; OnCalculate (index)<br /> &nbsp; &nbsp;plusdi,n,q &nbsp;= &nbsp; getCandlesByIndex &nbsp;( "SBAdx" , 1 , 0 , getNumCandles ( "SBAdx" )) &nbsp; -- get +DI table <br /> &nbsp; &nbsp;minusdi,n,q &nbsp;= &nbsp; getCandlesByIndex &nbsp;( "SBAdx" , 2 , 0 , getNumCandles ( "SBAdx" )) &nbsp;-- get -DI table <br /> &nbsp; &nbsp; return &nbsp;handler()<br /> end <br /><br />function handler(index)<br /> &nbsp; &nbsp;if plusdi[index].close ~= nil and minusdi[index].close ~= nil then  [/CODE] <br />=============<br /><br />1) Правильно ли, что &nbsp;из plusdi[] и minusdi[] значения берутся по индексу index?<br />Ведь в OnCalculate индексы приходят начиная с 1, а в возвращаемых значениях массивов из getCandlesByIndex &nbsp;индексы начитаются с 0...<br /><br />Наверное правильно будет plusdi[index-1].close и minusdi[index-1].close ?<br /><br />2) Про оптимизации.<br />Здесь получается, что мы в каждом OnCalculate получаем все свечи с другого графика через getCandlesByIndex(), после чего берём только какое-то одно значение...<br />думаю будет эффективнее написать так:<br /><br /> &nbsp; &nbsp;plusdi &nbsp;= &nbsp; getCandlesByIndex &nbsp;( "SBAdx" , 1 , index-1 , 1) &nbsp; -- get +DI table <br /> &nbsp; &nbsp;minusdi &nbsp;= &nbsp; getCandlesByIndex &nbsp;( "SBAdx" , 2 , index-1 , 1) &nbsp;-- get -DI table <br />...<br />и, соответственно, данные брать как<br />plusdi[0].close и minusdi[0].close <br />
			<i>15.01.2021 23:50:01, swerg.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message51805/topic4571/</link>
			<guid>http://forum.quik.ru/messages/forum10/message51805/topic4571/</guid>
			<pubDate>Fri, 15 Jan 2021 23:50:01 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>getCandlesByIndex  в индикаторе</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message38344/topic4571/">getCandlesByIndex  в индикаторе</a></b> <i>Как используется функция getCandlesByIndex в  индикаторе?</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			Хотя можно даже короче, т.к. только параметр index не является глобальным:<br />
====code====
<pre>function OnCalculate(index)
&nbsp;&nbsp;&nbsp;&nbsp;plusdi,n,q = getCandlesByIndex ("SBAdx",1,0,getNumCandles("SBAdx"))&nbsp;&nbsp;-- get +DI table
&nbsp;&nbsp;&nbsp;&nbsp;minusdi,n,q = getCandlesByIndex ("SBAdx",2,0,getNumCandles("SBAdx")) -- get -DI table
&nbsp;&nbsp;&nbsp;&nbsp;return handler(index)
end

function handler(index)
&nbsp;&nbsp;&nbsp;&nbsp;if plusdi&#91;index&#93;.close ~= nil and minusdi&#91;index&#93;.close ~= nil then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if plusdi&#91;index&#93;.close &#62; 30 then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my_indicator = 1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elseif minusdi&#91;index&#93;.close &#62; 30 then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my_indicator = -1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else my_indicator = 0
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;&nbsp;else my_indicator = 0
&nbsp;&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;&nbsp;return my_indicator
end</pre>
=============
<br />И проверьте, возвращает ли функция getCandlesByIndex() данные, тут может быть проблема в том, что тэг 'SBAdx' не задан в свойствах индикатора ADX. <br />
			<i>10.06.2019 08:09:51, Nikolay Pavlov.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message38344/topic4571/</link>
			<guid>http://forum.quik.ru/messages/forum10/message38344/topic4571/</guid>
			<pubDate>Mon, 10 Jun 2019 08:09:51 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>getCandlesByIndex  в индикаторе</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message38342/topic4571/">getCandlesByIndex  в индикаторе</a></b> <i>Как используется функция getCandlesByIndex в  индикаторе?</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			Добрый день.<br />У Вас в функции handler() используются переменная index, таблицы plusdiи minusdi, но я не вижу, чтобы вы эти данные передавали в функцию handler() (эти переменные не глобальные, соответственно они не будут видны в функции handler), сделайте вот так:<br />
====code====
<pre>function OnCalculate(index)
&nbsp;&nbsp;&nbsp;&nbsp;plusdi,n,q = getCandlesByIndex ("SBAdx",1,0,getNumCandles("SBAdx"))&nbsp;&nbsp;-- get +DI table
&nbsp;&nbsp;&nbsp;&nbsp;minusdi,n,q = getCandlesByIndex ("SBAdx",2,0,getNumCandles("SBAdx")) -- get -DI table
&nbsp;&nbsp;&nbsp;&nbsp;return handler(index, plusdi, minusdi)
end

function handler(index, plusdi, minusdi)
&nbsp;&nbsp;&nbsp;&nbsp;if plusdi&#91;index&#93;.close ~= nil and minusdi&#91;index&#93;.close ~= nil then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if plusdi&#91;index&#93;.close &#62; 30 then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my_indicator = 1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elseif minusdi&#91;index&#93;.close &#62; 30 then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my_indicator = -1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else my_indicator = 0
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;&nbsp;else my_indicator = 0
&nbsp;&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;&nbsp;return my_indicator
end</pre>
============= <br />
			<i>10.06.2019 05:05:39, Nikolay Pavlov.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message38342/topic4571/</link>
			<guid>http://forum.quik.ru/messages/forum10/message38342/topic4571/</guid>
			<pubDate>Mon, 10 Jun 2019 05:05:39 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>getCandlesByIndex  в индикаторе</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message38339/topic4571/">getCandlesByIndex  в индикаторе</a></b> <i>Как используется функция getCandlesByIndex в  индикаторе?</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			<br />====quote====<br /><a class="blog-p-user-name" id="bp_8204l2nR" href="/user/13008/" bx-tooltip-user-id="13008">Дмитрий</a> написал:<br />Пытаюсь написать простой индикатор на основе ADX. QUIK зависает &nbsp;при вызове этого индикатора. сыплет ошибками &quot;attempt to index field &quot;?&quot; (a nil value)<br /><br />=============<br /> <br />
			<i>09.06.2019 22:23:36, Дмитрий.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message38339/topic4571/</link>
			<guid>http://forum.quik.ru/messages/forum10/message38339/topic4571/</guid>
			<pubDate>Sun, 09 Jun 2019 22:23:36 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>getCandlesByIndex  в индикаторе</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message38338/topic4571/">getCandlesByIndex  в индикаторе</a></b> <i>Как используется функция getCandlesByIndex в  индикаторе?</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			Пытаюсь написать простой индикатор на основе ADX. QUIK зависает &nbsp;при вызове этого индикатора. сыплет ошибками &quot;attempt to index field &quot;?&quot;
====code====
<pre>Settings=
{
&nbsp;&nbsp;&nbsp;&nbsp;Name = "***AAA"
}
function Init()
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;return 1
end
function OnCalculate(index)
&nbsp;&nbsp;&nbsp;&nbsp;plusdi,n,q = getCandlesByIndex ("SBAdx",1,0,getNumCandles("SBAdx"))&nbsp;&nbsp;-- get +DI table
&nbsp;&nbsp;&nbsp;&nbsp;minusdi,n,q = getCandlesByIndex ("SBAdx",2,0,getNumCandles("SBAdx")) -- get -DI table
&nbsp;&nbsp;&nbsp;&nbsp;return handler()
end

function handler()
&nbsp;&nbsp;&nbsp;&nbsp;if plusdi&#91;index&#93;.close ~= nil and minusdi&#91;index&#93;.close ~= nil then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if plusdi&#91;index&#93;.close &#62; 30 then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my_indicator = 1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elseif minusdi&#91;index&#93;.close &#62; 30 then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my_indicator = -1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else my_indicator = 0
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;&nbsp;else my_indicator = 0
&nbsp;&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;&nbsp;return my_indicator
end


</pre>
============= <br />
			<i>09.06.2019 22:20:32, Дмитрий.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message38338/topic4571/</link>
			<guid>http://forum.quik.ru/messages/forum10/message38338/topic4571/</guid>
			<pubDate>Sun, 09 Jun 2019 22:20:32 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
	</channel>
</rss>
