<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title>Форум QUIK [тема: BULLS &amp; BEARS]</title>
		<link>http://forum.quik.ru</link>
		<description>Новое в теме BULLS &amp; BEARS форума  на сайте Форум QUIK [forum.quik.ru]</description>
		<language>ru</language>
		<docs>http://backend.userland.com/rss2</docs>
		<pubDate>Sat, 02 May 2026 14:27:25 +0300</pubDate>
		<item>
			<title>BULLS &amp; BEARS</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message17564/topic1966/">BULLS &amp; BEARS</a></b> <i>как получить линию разности быков и медведей с помощью индикаторов на Луа</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			<br />====quote====<br /><a class="blog-p-user-name" id="bp_2RJM78SJ" href="/user/2019/" bx-tooltip-user-id="2019">Сергей Качурин</a> написал:<br /> Sergey Gorokhov &nbsp;, спасибо! Всё заработало.<br /><br />что это за строчка такая, если не секрет?<br />=============<br /><br />Считайте что это ошибка в коде. Архив на ФТП уже поправили. <br />
			<i>03.08.2016 06:31:46, Sergey Gorokhov.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message17564/topic1966/</link>
			<guid>http://forum.quik.ru/messages/forum10/message17564/topic1966/</guid>
			<pubDate>Wed, 03 Aug 2016 06:31:46 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>BULLS &amp; BEARS</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message17561/topic1966/">BULLS &amp; BEARS</a></b> <i>как получить линию разности быков и медведей с помощью индикаторов на Луа</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			<a class="blog-p-user-name" id="bp_jSUvpHQ9" href="/user/17/" bx-tooltip-user-id="17">Sergey Gorokhov</a>, спасибо! Всё заработало.<br /><br />что это за строчка такая, если не секрет? <br />
			<i>02.08.2016 22:30:04, Сергей Качурин.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message17561/topic1966/</link>
			<guid>http://forum.quik.ru/messages/forum10/message17561/topic1966/</guid>
			<pubDate>Tue, 02 Aug 2016 22:30:04 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>BULLS &amp; BEARS</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message17548/topic1966/">BULLS &amp; BEARS</a></b> <i>как получить линию разности быков и медведей с помощью индикаторов на Луа</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			Уберите 111ю строку в файле SROC.lua<br />EMA_TMP[I-2]=nil<br /><br />должно помочь <br />
			<i>02.08.2016 10:40:22, Sergey Gorokhov.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message17548/topic1966/</link>
			<guid>http://forum.quik.ru/messages/forum10/message17548/topic1966/</guid>
			<pubDate>Tue, 02 Aug 2016 10:40:22 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>BULLS &amp; BEARS</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message17547/topic1966/">BULLS &amp; BEARS</a></b> <i>как получить линию разности быков и медведей с помощью индикаторов на Луа</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			А вообще это прикольный метод, отлаживать скрипт на форуме с помощью поддрежки :) <br />
			<i>02.08.2016 10:39:36, Imersio Arrigo.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message17547/topic1966/</link>
			<guid>http://forum.quik.ru/messages/forum10/message17547/topic1966/</guid>
			<pubDate>Tue, 02 Aug 2016 10:39:36 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>BULLS &amp; BEARS</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message17546/topic1966/">BULLS &amp; BEARS</a></b> <i>как получить линию разности быков и медведей с помощью индикаторов на Луа</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			<br />====quote====<br /><a class="blog-p-user-name" id="bp_5PWAnv6G" href="/user/2019/" bx-tooltip-user-id="2019">Сергей Качурин</a> написал:<br />и снова &nbsp;C:\FinamJunior\LuaIndicators\SROC.lua:110: <br />=============<br />Явно написано: строка 110,<br />че гадать-то &quot;между пятой и шестой...&quot; <br />
			<i>02.08.2016 10:39:03, Imersio Arrigo.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message17546/topic1966/</link>
			<guid>http://forum.quik.ru/messages/forum10/message17546/topic1966/</guid>
			<pubDate>Tue, 02 Aug 2016 10:39:03 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>BULLS &amp; BEARS</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message17544/topic1966/">BULLS &amp; BEARS</a></b> <i>как получить линию разности быков и медведей с помощью индикаторов на Луа</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			<a class="blog-p-user-name" id="bp_WMPq4KCs" href="/user/17/" bx-tooltip-user-id="17">Sergey Gorokhov</a>, <br /> вот так расчет пошел - for i=1,ds:Size() do<br /><br />результат в таблице:
====code====
<pre>&nbsp;&nbsp;&nbsp;Price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SROC
1&nbsp;&nbsp;&nbsp;91360&nbsp;&nbsp;&nbsp;
2&nbsp;&nbsp;&nbsp;91330&nbsp;&nbsp;&nbsp;
3&nbsp;&nbsp;&nbsp;91310&nbsp;&nbsp;&nbsp;
4&nbsp;&nbsp;&nbsp;91310&nbsp;&nbsp;&nbsp;
5&nbsp;&nbsp;&nbsp;91280&nbsp;&nbsp;&nbsp;
6&nbsp;&nbsp;&nbsp;91270&nbsp;&nbsp;&nbsp;
7&nbsp;&nbsp;&nbsp;91310&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 99,955126281672
</pre>
=============
и снова &nbsp;C:\FinamJunior\LuaIndicators\SROC.lua:110: attempt to perform arithmetic on field '?' (a nil value)<br /><br />код:<br />
====code====
<pre>for x = 2,4 do --periods
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;func = SROC()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t_id = AllocTable()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AddColumn(t_id,1,"Price",true,QTABLE_INT_TYPE,10)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AddColumn(t_id,2,"SROC",true,QTABLE_INT_TYPE,10)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CreateWindow(t_id)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SetWindowCaption(t_id,"SROC")
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;message("2", 1)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ds = CreateDataSource("SPBFUT", "RIU6", INTERVAL_M1) 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sleep(100)

for i=1,ds:Size() do --candels
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;message("4", 1)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ma_out=func(i, {Period = x, Metod = "EMA", VType="Close", round="off"}, ds)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp=InsertRow(t_id,-1)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SetCell(t_id,tmp,1,tostring(ds:C(i)),ds:C(i))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SetCell(t_id,tmp,2,tostring(ma_out),ma_out)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;message("5", 1)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if i &#62; 4+x then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y = func(i-2, {Period = x, Metod = "EMA", VType="Close", round="off"}, ds) 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y1 = func(i-1, {Period = x, Metod = "EMA", VType="Close", round="off"}, ds) 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y2 = func(i, {Period = x, Metod = "EMA", VType="Close", round="off"}, ds)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;message("6", 1)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if count == 0
</pre>
=============
ошибка между message &quot;5&quot; и message &quot;6&quot; ... <br />
			<i>02.08.2016 10:29:51, Сергей Качурин.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message17544/topic1966/</link>
			<guid>http://forum.quik.ru/messages/forum10/message17544/topic1966/</guid>
			<pubDate>Tue, 02 Aug 2016 10:29:51 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>BULLS &amp; BEARS</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message17539/topic1966/">BULLS &amp; BEARS</a></b> <i>как получить линию разности быков и медведей с помощью индикаторов на Луа</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			И потом, в моем примере после CreateDataSource был sleep(100), а у Вас его нет.<br />Его нужно добавить, иначе цикл может начать работать до того как прокачаются свечки <br />
			<i>02.08.2016 04:09:22, Sergey Gorokhov.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message17539/topic1966/</link>
			<guid>http://forum.quik.ru/messages/forum10/message17539/topic1966/</guid>
			<pubDate>Tue, 02 Aug 2016 04:09:22 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>BULLS &amp; BEARS</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message17538/topic1966/">BULLS &amp; BEARS</a></b> <i>как получить линию разности быков и медведей с помощью индикаторов на Луа</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			Скорее всего ошибка в этой строке<br /><br />====quote====<br /><a class="blog-p-user-name" id="bp_urd3gBb5" href="/user/2019/" bx-tooltip-user-id="2019">Сергей Качурин</a> написал:<br />for i=1+x,ds:Size() do --candels<br />=============<br /><br />EMA рассчитывается на основе своих предыдущих значений.<br />То есть для того чтобы он считался на определенной свече нужно прогнать все предыдущие свечи.<br /><br />попробуйте указать так:<br />for i=1,ds:Size() do <br />
			<i>02.08.2016 04:06:52, Sergey Gorokhov.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message17538/topic1966/</link>
			<guid>http://forum.quik.ru/messages/forum10/message17538/topic1966/</guid>
			<pubDate>Tue, 02 Aug 2016 04:06:52 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>BULLS &amp; BEARS</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message17537/topic1966/">BULLS &amp; BEARS</a></b> <i>как получить линию разности быков и медведей с помощью индикаторов на Луа</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			Приведите полную версию кода. <br />
			<i>02.08.2016 03:59:45, Sergey Gorokhov.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message17537/topic1966/</link>
			<guid>http://forum.quik.ru/messages/forum10/message17537/topic1966/</guid>
			<pubDate>Tue, 02 Aug 2016 03:59:45 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>BULLS &amp; BEARS</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message17536/topic1966/">BULLS &amp; BEARS</a></b> <i>как получить линию разности быков и медведей с помощью индикаторов на Луа</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			<a class="blog-p-user-name" id="bp_cXaTFn0s" href="/user/17/" bx-tooltip-user-id="17">Sergey Gorokhov</a>, &nbsp;не подскажете в чем может быть засада?<br /><br /><br />C:\FinamJunior\LuaIndicators\SROC.lua:110: attempt to perform arithmetic on field '?' (a nil value) &nbsp;<br /><br />Если вместо SROC звать МА, то ошибка на 83 строке.<br />
====code====
<pre>for x = 2,4 do --periods
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;func = SROC()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t_id = AllocTable()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AddColumn(t_id,1,"Price",true,QTABLE_INT_TYPE,10)
&nbsp;&nbsp;&nbsp;AddColumn(t_id,2,"SROC",true,QTABLE_INT_TYPE,10)
&nbsp;&nbsp;&nbsp;CreateWindow(t_id)
&nbsp;&nbsp;&nbsp;SetWindowCaption(t_id,"SROC")
&nbsp;&nbsp;&nbsp;ds = CreateDataSource("SPBFUT", "RIU6", INTERVAL_M1) 

&nbsp;&nbsp; for i=1+x,ds:Size() do --candels
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;ma_out=func(i, {Period = x, Metod = "EMA", VType="Close", round="off"}, ds) --ОШИБКА
&nbsp;&nbsp;&nbsp;tmp=InsertRow(t_id,-1)
&nbsp;&nbsp;&nbsp;SetCell(t_id,tmp,1,tostring(ds:C(i)),ds:C(i))
&nbsp;&nbsp;&nbsp;SetCell(t_id,tmp,2,tostring(ma_out),ma_out)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

</pre>
============= <br />
			<i>01.08.2016 23:38:46, Сергей Качурин.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message17536/topic1966/</link>
			<guid>http://forum.quik.ru/messages/forum10/message17536/topic1966/</guid>
			<pubDate>Mon, 01 Aug 2016 23:38:46 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>BULLS &amp; BEARS</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message17462/topic1966/">BULLS &amp; BEARS</a></b> <i>как получить линию разности быков и медведей с помощью индикаторов на Луа</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			<br />====quote====<br /><a class="blog-p-user-name" id="bp_CuzFLhvO" href="/user/2019/" bx-tooltip-user-id="2019">Сергей Качурин</a> написал:<br /> как тогда обратиться к значениям каждой конкретной свечи<br />=============<br /><br />первый параметр функции вернет значение для конкретной свечки<br /> &nbsp; ma_out=func(1, {Period = x, Metod = "EMA", VType="Close", round="off"}, ds) --первая свечка<br /> &nbsp; ma_out=func(2, {Period = x, Metod = "EMA", VType="Close", round="off"}, ds) --вторая<br />и т.д. <br />
			<i>27.07.2016 05:52:17, Sergey Gorokhov.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message17462/topic1966/</link>
			<guid>http://forum.quik.ru/messages/forum10/message17462/topic1966/</guid>
			<pubDate>Wed, 27 Jul 2016 05:52:17 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>BULLS &amp; BEARS</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message17454/topic1966/">BULLS &amp; BEARS</a></b> <i>как получить линию разности быков и медведей с помощью индикаторов на Луа</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			<a class="blog-p-user-name" id="bp_1VbAgB1Q" href="/user/17/" bx-tooltip-user-id="17">Sergey Gorokhov</a>, а как тогда обратиться к значениям каждой конкретной свечи из диапазона i=1+x,ds:Size() ? <br /><br />чтобы получить вот эти значения:<br />
====code====
<pre>if i &#62; 4+x and ma_out&#91;i-1&#93; &#62; ma_out&#91;i-2&#93; and ma_out&#91;i&#93; &#60; ma_out&#91;i-1&#93;</pre>
=============
<br />Создать таблицу (где?) в которую сохранять № свечи и значение, а потом обращаться к этой таблице?<br /><br />Вы, наверное, уже видите, что задача перебрать несколько периодов индикатора и на каждом периоде проверить выполнение условий на всем диапазоне i=1+x,ds:Size() .. <br />
			<i>26.07.2016 17:23:12, Сергей Качурин.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message17454/topic1966/</link>
			<guid>http://forum.quik.ru/messages/forum10/message17454/topic1966/</guid>
			<pubDate>Tue, 26 Jul 2016 17:23:12 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>BULLS &amp; BEARS</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message17453/topic1966/">BULLS &amp; BEARS</a></b> <i>как получить линию разности быков и медведей с помощью индикаторов на Луа</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			<br />====quote====<br /><a class="blog-p-user-name" id="bp_dHLap9YR" href="/user/2019/" bx-tooltip-user-id="2019">Сергей Качурин</a> написал:<br />Sergey Gorokhov, a можно к созданному индикатору присвоить идентификатор через Lua (сразу при добавлении), чтобы потом обращаться к его значениям через getNumCandles и getCandlesByIndex?<br /><br />=============<br /><br />К сожалению в текущей реализации в Lua индикаторы нельзя добавить идентификатор средствами Lua.<br /><br /><br />====quote====<br /><a class="blog-p-user-name" id="bp_1fRrq38b" href="/user/2019/" bx-tooltip-user-id="2019">Сергей Качурин</a> написал:<br />или вот такое обращение будет корректным: ma_out[i], ma_out[i-1]... ?<br />=============<br /><br />нет, так как функция возвращает значение рассчитанное для конкретной свечи, а не таблицу. <br />
			<i>26.07.2016 14:43:36, Sergey Gorokhov.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message17453/topic1966/</link>
			<guid>http://forum.quik.ru/messages/forum10/message17453/topic1966/</guid>
			<pubDate>Tue, 26 Jul 2016 14:43:36 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>BULLS &amp; BEARS</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message17452/topic1966/">BULLS &amp; BEARS</a></b> <i>как получить линию разности быков и медведей с помощью индикаторов на Луа</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			<a class="blog-p-user-name" id="bp_GCXzoFdu" href="/user/17/" bx-tooltip-user-id="17">Sergey Gorokhov</a>, a можно к созданному индикатору присвоить идентификатор через Lua (сразу при добавлении), чтобы потом обращаться к его значениям через getNumCandles и getCandlesByIndex?<br /><br />или вот такое обращение будет корректным: ma_out&#91;i&#93;, ma_out&#91;i-1&#93;... ?
====code====
<pre>for i=1+x,ds:Size() do
&nbsp;&nbsp;&nbsp;ma_out=func(i, {Period = x, Metod = "EMA", VType="Close", round="off"}, ds)
&nbsp;&nbsp;&nbsp;tmp=InsertRow(t_id,-1)
&nbsp;&nbsp;&nbsp;SetCell(t_id,tmp,1,tostring(ds:C(i)),ds:C(i))
&nbsp;&nbsp;&nbsp;SetCell(t_id,tmp,2,tostring(ma_out),ma_out)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;if i &#62; 4+x and ma_out&#91;i-1&#93; &#62; ma_out&#91;i-2&#93; and ma_out&#91;i&#93; &#60; ma_out&#91;i-1&#93;
end 
</pre>
============= <br />
			<i>26.07.2016 14:34:34, Сергей Качурин.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message17452/topic1966/</link>
			<guid>http://forum.quik.ru/messages/forum10/message17452/topic1966/</guid>
			<pubDate>Tue, 26 Jul 2016 14:34:34 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>BULLS &amp; BEARS</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message17439/topic1966/">BULLS &amp; BEARS</a></b> <i>как получить линию разности быков и медведей с помощью индикаторов на Луа</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			Здравствуйте,<br />Проверять нужно не сами функции а результат этих функций.<br /><br />
====code====
<pre>
if func1(Index, Settings) ~= nil and func2(Index, Settings) ~= nil then
</pre>
=============
<br /><br />а еще лучше задать переменные и дальше работать с ними<br />
====code====
<pre>
x = func1(Index, Settings) 
y = func2(Index, Settings)

if x ~= nil and y ~= nil then
&nbsp;&nbsp; return (x+y)/2
end
</pre>
============= <br />
			<i>26.07.2016 06:08:44, Sergey Gorokhov.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message17439/topic1966/</link>
			<guid>http://forum.quik.ru/messages/forum10/message17439/topic1966/</guid>
			<pubDate>Tue, 26 Jul 2016 06:08:44 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>BULLS &amp; BEARS</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message17433/topic1966/">BULLS &amp; BEARS</a></b> <i>как получить линию разности быков и медведей с помощью индикаторов на Луа</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			<a class="blog-p-user-name" id="bp_EjJMkZxk" href="/user/17/" bx-tooltip-user-id="17">Sergey Gorokhov</a>, <br /> а не подскажете как убрать вот эту ошибку: C:\FinamJunior\LuaIndicators\_Line.lua:27: attempt to perform arithmetic on a nil value. Выскакивает по количеству периодов расчета<br /><br />такой вариант не помог<br />
====code====
<pre>if func1 ~= nil and func2 ~= nil then
&nbsp;&nbsp;&nbsp;return (func1(Index, Settings)+func2(Index, Settings))/2
end
</pre>
============= <br />
			<i>25.07.2016 21:08:37, Сергей Качурин.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message17433/topic1966/</link>
			<guid>http://forum.quik.ru/messages/forum10/message17433/topic1966/</guid>
			<pubDate>Mon, 25 Jul 2016 21:08:37 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>BULLS &amp; BEARS</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message17422/topic1966/">BULLS &amp; BEARS</a></b> <i>как получить линию разности быков и медведей с помощью индикаторов на Луа</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			<a class="blog-p-user-name" id="bp_4ShJ5Z56" href="/user/17/" bx-tooltip-user-id="17">Sergey Gorokhov</a>, спасибо , всё работает! <br />
			<i>25.07.2016 10:23:26, Сергей Качурин.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message17422/topic1966/</link>
			<guid>http://forum.quik.ru/messages/forum10/message17422/topic1966/</guid>
			<pubDate>Mon, 25 Jul 2016 10:23:26 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>BULLS &amp; BEARS</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message17406/topic1966/">BULLS &amp; BEARS</a></b> <i>как получить линию разности быков и медведей с помощью индикаторов на Луа</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			Причина в том что в коде много ошибок, причем не синтаксических а логических<br />вот Вы выводите сообщение<br />
====code====
<pre>message (tostring(Out1), 1)</pre>
=============
<br />однако сама переменная Out1 у Вас нигде не задана.<br />далее<br />
====code====
<pre>&nbsp;&nbsp; if Out1~=nil and Out2~=nil
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;func = Out1- Out2
&nbsp;&nbsp; end</pre>
=============
<br />Этот текст вообще не понятен. Что такое func? Где задаются значения для Out1 и Out2?<br /><br />далее<br />
====code====
<pre>return func1(Index, Settings) and func2(Index, Settings)
</pre>
=============
<br />Здесь вообще не понятно чего Вы пытались добиться выводя boolean тип данных, когда надо выводить число.<br />Зачем вообще надо было трогать переменные внутри функции?<br /><br />Функция выводит результат, вот и работайте с результатом, а не с тем что внутри функции.<br />То что внутри вообще трогать не надо.<br /><br /><table class="forum-spoiler"><thead onclick="if (this.nextSibling.style.display=='none') { this.nextSibling.style.display=''; BX.addClass(this, 'forum-spoiler-head-open'); } else { this.nextSibling.style.display='none'; BX.removeClass(this, 'forum-spoiler-head-open'); } BX.onCustomEvent('BX.Forum.Spoiler:toggle', [{node: this}]); event.stopPropagation();"><tr><th><div>Скрытый текст</div></th></tr></thead><tbody class="forum-spoiler" style="display:none;"><tr><td>
====code====
<pre>Settings = {
Name = "*BULLS-BEARS", 
round = "off",
Period = 13, 
Metod = "EMA", --SMA, EMA, VMA, SMMA, VMA 
VType = "Close", --Open, High, Low, Close, Volume, Median, Typical, Weighted, Difference 
line = {{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name = "BULLS-BEARS", 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Type = TYPE_HISTOGRAM, 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Color = RGB(255, 0, 0)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name = "line 0",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Type = TYPE_LINE, 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Color = RGB(0, 255, 0)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
function Init() 
&nbsp;&nbsp;&nbsp;func1 = BULLS()
&nbsp;&nbsp;&nbsp;func2 = BEARS()
&nbsp;&nbsp;&nbsp;return #Settings.line
end

function OnCalculate(Index) 
&nbsp;&nbsp;&nbsp;return func1(Index, Settings)-func2(Index, Settings)
end

function BULLS() --Bulls Power ("BULLS")
&nbsp;&nbsp;&nbsp;local Bulls_MA=MA()
return function (I, Fsettings, ds)
local Out = nil
local Fsettings=(Fsettings or {})
local P = (Fsettings.Period or 13)
local M = (Fsettings.Metod or "EMA")
local VT = (Fsettings.VType or "Close")
local R = (Fsettings.round or "off")
local b_ma = Bulls_MA(I, {Period=P, Metod = M, VType=VT, round=R}, ds)
if I&#62;=P and b_ma then
&nbsp;&nbsp;&nbsp;Out = Value(I, "High", ds)-b_ma
else Out = b_ma end
&nbsp;&nbsp;&nbsp;return rounding(Out, R),0
end
end

function BEARS() --Bears Power ("BEARS")
&nbsp;&nbsp;&nbsp;local Bears_MA=MA()
return function (I, Fsettings, ds)
local Out = nil
local Fsettings=(Fsettings or {})
local P = (Fsettings.Period or 13)
local M = (Fsettings.Metod or "EMA")
local VT = (Fsettings.VType or "Close")
local R = (Fsettings.round or "off")
local b_ma = 0

b_ma=Bears_MA(I, {Period=P, Metod = M, VType=VT, round=R}, ds)
if I&#62;=P and b_ma then
&nbsp;&nbsp;&nbsp;Out = Value(I, "Low", ds)-b_ma
else Out = b_ma end
&nbsp;&nbsp;&nbsp;return rounding(Out, R),0
end
end

function MA() --Moving Average ("MA")
local t_SMA = F_SMA()
local t_EMA = F_EMA()
local t_VMA = F_VMA()
local t_SMMA = F_SMMA()
local t_WMA = F_WMA()
return function(I, Fsettings, ds)
&nbsp;&nbsp;&nbsp;local Out = nil
&nbsp;&nbsp;&nbsp;local Fsettings=(Fsettings or {})
&nbsp;&nbsp;&nbsp;local P = (Fsettings.Period or 9)
&nbsp;&nbsp;&nbsp;local M = (Fsettings.Metod or "EMA")
&nbsp;&nbsp;&nbsp;local VT = (Fsettings.VType or "Close")
&nbsp;&nbsp;&nbsp;local R = (Fsettings.round or "off")
&nbsp;&nbsp;&nbsp;if M == "SMA" then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = t_SMA(I, P, VT, ds, R)
&nbsp;&nbsp;&nbsp;elseif M == "EMA" then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = t_EMA(I, P, VT, ds, R)
&nbsp;&nbsp;&nbsp;elseif M == "VMA" then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = t_VMA(I, P, VT, ds, R)
&nbsp;&nbsp;&nbsp;elseif M == "SMMA" then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = t_SMMA(I, P, VT, ds, R)
&nbsp;&nbsp;&nbsp;elseif M == "WMA" then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = t_WMA(I, P, VT, ds, R)
&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = nil
&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;return rounding(Out, R)
end
end
------------------------------------------------------------------
--Moving Average SMA, EMA, VMA, SMMA, VMA
------------------------------------------------------------------
--&#91;&#91;Simple Moving Average (SMA)
SMA = sum(Pi) / n
&#93;&#93;
function F_SMA()
return function (I, Period, VType, ds, round) 
local Out = nil
&nbsp;&nbsp;&nbsp;if I &#62;= Period then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local sum = 0
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for i = I-Period+1, I do
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum = sum +Value(i, VType, ds)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = sum/Period
&nbsp;&nbsp;&nbsp;end 
&nbsp;&nbsp;&nbsp;return rounding(Out,round)
end
end

--&#91;&#91;Exponential Moving Average (EMA)
EMAi = (EMAi-1*(n-1)+2*Pi) / (n+1)
&#93;&#93;
function F_EMA() 
local EMA_TMP={}
return function(I, Period, VType, ds, round)
local Out = nil
&nbsp;&nbsp;&nbsp;if I == 1 then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EMA_TMP&#91;I&#93;=rounding(Value(I, VType, ds),round)
&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EMA_TMP&#91;I&#93;=rounding((EMA_TMP&#91;I-1&#93;*(Period-1)+2*Value(I, VType, ds)) / (Period+1),round)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EMA_TMP&#91;I-2&#93;=nil
&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;if I &#62;= Period then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = EMA_TMP&#91;I&#93;
&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;return rounding(Out,round)
end
end

--&#91;&#91;
William Moving Average (WMA)
( Previous WILLMA * ( Period - 1 ) + Data ) / Period
&#93;&#93;
function F_WMA()
&nbsp;&nbsp;&nbsp;local WMA_TMP={}
return function(I, Period, VType, ds, round)
local Out = nil
&nbsp;&nbsp; if I == 1 then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WMA_TMP&#91;I&#93;=rounding(Value(I, VType, ds),round)
&nbsp;&nbsp; else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WMA_TMP&#91;I&#93;=rounding((WMA_TMP&#91;I-1&#93;*(Period-1)+Value(I, VType, ds)) / Period,round)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WMA_TMP&#91;I-2&#93;=nil
&nbsp;&nbsp; end
&nbsp;&nbsp; if I &#62;= Period then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = WMA_TMP&#91;I&#93;
&nbsp;&nbsp; end
&nbsp;&nbsp; return rounding(Out,round)
end
end

--&#91;&#91;Volume Adjusted Moving Average (VMA)
VMA = sum(Pi*Vi) / sum(Vi)
&#93;&#93;
function F_VMA()
return function (I, Period, VType, ds, round)
local Out = nil
&nbsp;&nbsp;&nbsp;if I &#62;= Period then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local sum = 0
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local sumV = 0
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for i = I-Period+1, I do
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum = sum +Value(i, VType, ds)*Value(i, "Volume", ds)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sumV = sumV +Value(i, "Volume", ds)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = sum/sumV
&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;return rounding(Out,round)
end
end

--&#91;&#91;Smoothed Moving Average (SMMA)
SMMAi = (sum(Pi) - SMMAi-1 + Pi) / n
&#93;&#93;
function F_SMMA()
local SMMA_TMP={}
return function(I, Period, VType, ds, round)
local Out = nil
&nbsp;&nbsp;&nbsp;if I &#62;= Period then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local sum = 0
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for i = I-Period+1, I do
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum = sum +Value(i, VType, ds)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if I == Period then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SMMA_TMP&#91;I&#93;=rounding((sum-Value(I, VType, ds)+Value(I, VType, ds)) / Period, round)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SMMA_TMP&#91;I&#93;=rounding((sum-SMMA_TMP&#91;I-1&#93;+Value(I, VType, ds)) / Period, round)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SMMA_TMP&#91;I-2&#93;=nil
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = SMMA_TMP&#91;I&#93;
&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;return rounding(Out,round)
end
end


function rounding(num, round) 
if round and string.upper(round)== "ON" then round=0 end
if num and tonumber(round) then
&nbsp;&nbsp;&nbsp;local mult = 10^round
&nbsp;&nbsp;&nbsp;if num &#62;= 0 then return math.floor(num * mult + 0.5) / mult
&nbsp;&nbsp;&nbsp;else return math.ceil(num * mult - 0.5) / mult end
else return num end
end

function Value(I,VType,ds) 
local Out = nil
VType=(VType and string.upper(string.sub(VType,1,1))) or "A"
&nbsp;&nbsp;&nbsp;if VType == "O" then&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--Open
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = (O and O(I)) or (ds and ds:O(I))
&nbsp;&nbsp;&nbsp;elseif VType == "H" then &nbsp;&nbsp;&nbsp;--High
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = (H and H(I)) or (ds and ds:H(I))
&nbsp;&nbsp;&nbsp;elseif VType == "L" then&nbsp;&nbsp;&nbsp;--Low
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = (L and L(I)) or (ds and ds:L(I))
&nbsp;&nbsp;&nbsp;elseif VType == "C" then&nbsp;&nbsp;&nbsp;--Close
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = (C and C(I)) or (ds and ds:C(I))
&nbsp;&nbsp;&nbsp;elseif VType == "V" then&nbsp;&nbsp;&nbsp;--Volume
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = (V and V(I)) or (ds and ds:V(I)) 
&nbsp;&nbsp;&nbsp;elseif VType == "M" then&nbsp;&nbsp;&nbsp;--Median
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = ((Value(I,"H",ds) + Value(I,"L",ds)) / 2)
&nbsp;&nbsp;&nbsp;elseif VType == "T" then&nbsp;&nbsp;&nbsp;--Typical
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = ((Value(I,"M",ds) * 2 + Value(I,"C",ds))/3)
&nbsp;&nbsp;&nbsp;elseif VType == "W" then&nbsp;&nbsp;&nbsp;--Weighted
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = ((Value(I,"T",ds) * 3 + Value(I,"O",ds))/4) 
&nbsp;&nbsp;&nbsp;elseif VType == "D" then&nbsp;&nbsp;&nbsp;--Difference
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = (Value(I,"H",ds) - Value(I,"L",ds))
&nbsp;&nbsp;&nbsp;elseif VType == "A" then&nbsp;&nbsp;&nbsp;--Any
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ds then Out = ds&#91;I&#93; end
&nbsp;&nbsp;&nbsp;end
return Out
end</pre>
=============
</td></tr></tbody></table> <br />
			<i>23.07.2016 13:09:50, Sergey Gorokhov.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message17406/topic1966/</link>
			<guid>http://forum.quik.ru/messages/forum10/message17406/topic1966/</guid>
			<pubDate>Sat, 23 Jul 2016 13:09:50 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>BULLS &amp; BEARS</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message17402/topic1966/">BULLS &amp; BEARS</a></b> <i>как получить линию разности быков и медведей с помощью индикаторов на Луа</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			Как начинающему, советую начать с изучения языка луа на простых примерах.<br />потом написать эти индикаторы самостоятельно по формулам инета.<br />В результате размер кода будет раз в 10 меньше (получится примерно 5 строчек кода)<br /> и исполняться будет быстрее и у Вас будет понимание того, что делаете.<br />--------------------------------------<br />Примечание:<br />Если не обращать внимание на громкие и пустые фразы вокруг этих индикаторов, <br />то реально &nbsp;индикаторы по сути &nbsp;самые примитивные фильтры первого порядка. <br />Реально показывают лишь слабые знания математики и богатое воображение у их автора. <br />
			<i>23.07.2016 07:10:47, Николай  Камынин.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message17402/topic1966/</link>
			<guid>http://forum.quik.ru/messages/forum10/message17402/topic1966/</guid>
			<pubDate>Sat, 23 Jul 2016 07:10:47 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
		<item>
			<title>BULLS &amp; BEARS</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum10/message17398/topic1966/">BULLS &amp; BEARS</a></b> <i>как получить линию разности быков и медведей с помощью индикаторов на Луа</i> в форуме <a href="http://forum.quik.ru/forum10/">Программирование на языке Lua</a>. <br />
			Здравствуйте.<br /><br />Пытаюсь слегка изменить выложенные разработчиком индикаторы: получить Линию разности Быков и Медведей..<br />Соединил их вместе:<br /><br />Думал, BULLS() возвращает значение (но если tostring, то печатает &quot;function: F028E025&quot; - примерно, tonumber - nil).<br /><br />Предположил, что значение сидит в Out (func = Out1- Out2), но выходит nil, а дальше ошибка, что ожидается число..Вроде логично, ведь период 13 и первые 12 значений скорее всего пустые. <br />Убрал под if Out1~=nil and Out2~=nil .. и вот тут началось самое интересное - индикатор просто пропал из списка доступных индикаторов!<br />Возможно, это встроенная защита от ошибок ..<br />Джуниор 7.0.0.289<br /><br />Подскажите, пожалуйста, начинающему в чём ошибка.<br /><br />
====code====
<pre>Settings = {
Name = "*line_1", 
round = "off",
Period = 13, 
Metod = "EMA", --SMA, EMA, VMA, SMMA, VMA 
VType = "Close", --Open, High, Low, Close, Volume, Median, Typical, Weighted, Difference 
line = {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name = "LINE", 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Type = TYPE_LINE, 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Color = RGB(255, 0, 0)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
}
&nbsp;&nbsp;&nbsp;
function Init() 
&nbsp;&nbsp;&nbsp;func1 = BULLS()
&nbsp;&nbsp;&nbsp;func2 = BEARS()
&nbsp;&nbsp;&nbsp;message (tostring(Out1), 1)
&nbsp;&nbsp;&nbsp;if Out1~=nil and Out2~=nil
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;func = Out1- Out2
&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;return #Settings.line
end

function OnCalculate(Index) 
&nbsp;&nbsp;&nbsp;return func1(Index, Settings) and func2(Index, Settings)
end

function BULLS() --Bulls Power ("BULLS")
&nbsp;&nbsp;&nbsp;local Bulls_MA=MA()
return function (I, Fsettings, ds)
local Out1 = nil
local Fsettings=(Fsettings or {})
local P = (Fsettings.Period or 13)
local M = (Fsettings.Metod or "EMA")
local VT = (Fsettings.VType or "Close")
local R = (Fsettings.round or "off")
local b_ma = Bulls_MA(I, {Period=P, Metod = M, VType=VT, round=R}, ds)
if I&#62;=P and b_ma then
&nbsp;&nbsp;&nbsp;Out1 = Value(I, "High", ds)-b_ma
else Out1 = b_ma end
&nbsp;&nbsp;&nbsp;return rounding(Out1, R),0
end
end

function BEARS() --Bears Power ("BEARS")
&nbsp;&nbsp;&nbsp;local Bears_MA=MA()
return function (I, Fsettings, ds)
local Out2 = nil
local Fsettings=(Fsettings or {})
local P = (Fsettings.Period or 13)
local M = (Fsettings.Metod or "EMA")
local VT = (Fsettings.VType or "Close")
local R = (Fsettings.round or "off")
local b_ma = 0

b_ma=Bears_MA(I, {Period=P, Metod = M, VType=VT, round=R}, ds)
if I&#62;=P and b_ma then
&nbsp;&nbsp;&nbsp;Out2 = Value(I, "Low", ds)-b_ma
else Out2 = b_ma end
&nbsp;&nbsp;&nbsp;return rounding(Out2, R),0
end
end

function MA() --Moving Average ("MA")
local t_SMA = F_SMA()
local t_EMA = F_EMA()
local t_VMA = F_VMA()
local t_SMMA = F_SMMA()
local t_WMA = F_WMA()
return function(I, Fsettings, ds)
&nbsp;&nbsp;&nbsp;local Out = nil
&nbsp;&nbsp;&nbsp;local Fsettings=(Fsettings or {})
&nbsp;&nbsp;&nbsp;local P = (Fsettings.Period or 9)
&nbsp;&nbsp;&nbsp;local M = (Fsettings.Metod or "EMA")
&nbsp;&nbsp;&nbsp;local VT = (Fsettings.VType or "Close")
&nbsp;&nbsp;&nbsp;local R = (Fsettings.round or "off")
&nbsp;&nbsp;&nbsp;if M == "SMA" then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = t_SMA(I, P, VT, ds, R)
&nbsp;&nbsp;&nbsp;elseif M == "EMA" then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = t_EMA(I, P, VT, ds, R)
&nbsp;&nbsp;&nbsp;elseif M == "VMA" then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = t_VMA(I, P, VT, ds, R)
&nbsp;&nbsp;&nbsp;elseif M == "SMMA" then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = t_SMMA(I, P, VT, ds, R)
&nbsp;&nbsp;&nbsp;elseif M == "WMA" then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = t_WMA(I, P, VT, ds, R)
&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = nil
&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;return rounding(Out, R)
end
end
------------------------------------------------------------------
--Moving Average SMA, EMA, VMA, SMMA, VMA
------------------------------------------------------------------
--&#91;&#91;Simple Moving Average (SMA)
SMA = sum(Pi) / n
&#93;&#93;
function F_SMA()
return function (I, Period, VType, ds, round) 
local Out = nil
&nbsp;&nbsp;&nbsp;if I &#62;= Period then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local sum = 0
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for i = I-Period+1, I do
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum = sum +Value(i, VType, ds)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = sum/Period
&nbsp;&nbsp;&nbsp;end 
&nbsp;&nbsp;&nbsp;return rounding(Out,round)
end
end

--&#91;&#91;Exponential Moving Average (EMA)
EMAi = (EMAi-1*(n-1)+2*Pi) / (n+1)
&#93;&#93;
function F_EMA() 
local EMA_TMP={}
return function(I, Period, VType, ds, round)
local Out = nil
&nbsp;&nbsp;&nbsp;if I == 1 then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EMA_TMP&#91;I&#93;=rounding(Value(I, VType, ds),round)
&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EMA_TMP&#91;I&#93;=rounding((EMA_TMP&#91;I-1&#93;*(Period-1)+2*Value(I, VType, ds)) / (Period+1),round)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EMA_TMP&#91;I-2&#93;=nil
&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;if I &#62;= Period then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = EMA_TMP&#91;I&#93;
&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;return rounding(Out,round)
end
end

--&#91;&#91;
William Moving Average (WMA)
( Previous WILLMA * ( Period - 1 ) + Data ) / Period
&#93;&#93;
function F_WMA()
&nbsp;&nbsp;&nbsp;local WMA_TMP={}
return function(I, Period, VType, ds, round)
local Out = nil
&nbsp;&nbsp; if I == 1 then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WMA_TMP&#91;I&#93;=rounding(Value(I, VType, ds),round)
&nbsp;&nbsp; else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WMA_TMP&#91;I&#93;=rounding((WMA_TMP&#91;I-1&#93;*(Period-1)+Value(I, VType, ds)) / Period,round)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WMA_TMP&#91;I-2&#93;=nil
&nbsp;&nbsp; end
&nbsp;&nbsp; if I &#62;= Period then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = WMA_TMP&#91;I&#93;
&nbsp;&nbsp; end
&nbsp;&nbsp; return rounding(Out,round)
end
end

--&#91;&#91;Volume Adjusted Moving Average (VMA)
VMA = sum(Pi*Vi) / sum(Vi)
&#93;&#93;
function F_VMA()
return function (I, Period, VType, ds, round)
local Out = nil
&nbsp;&nbsp;&nbsp;if I &#62;= Period then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local sum = 0
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local sumV = 0
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for i = I-Period+1, I do
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum = sum +Value(i, VType, ds)*Value(i, "Volume", ds)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sumV = sumV +Value(i, "Volume", ds)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = sum/sumV
&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;return rounding(Out,round)
end
end

--&#91;&#91;Smoothed Moving Average (SMMA)
SMMAi = (sum(Pi) - SMMAi-1 + Pi) / n
&#93;&#93;
function F_SMMA()
local SMMA_TMP={}
return function(I, Period, VType, ds, round)
local Out = nil
&nbsp;&nbsp;&nbsp;if I &#62;= Period then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local sum = 0
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for i = I-Period+1, I do
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum = sum +Value(i, VType, ds)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if I == Period then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SMMA_TMP&#91;I&#93;=rounding((sum-Value(I, VType, ds)+Value(I, VType, ds)) / Period, round)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SMMA_TMP&#91;I&#93;=rounding((sum-SMMA_TMP&#91;I-1&#93;+Value(I, VType, ds)) / Period, round)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SMMA_TMP&#91;I-2&#93;=nil
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = SMMA_TMP&#91;I&#93;
&nbsp;&nbsp;&nbsp;end
&nbsp;&nbsp;&nbsp;return rounding(Out,round)
end
end


function rounding(num, round) 
if round and string.upper(round)== "ON" then round=0 end
if num and tonumber(round) then
&nbsp;&nbsp;&nbsp;local mult = 10^round
&nbsp;&nbsp;&nbsp;if num &#62;= 0 then return math.floor(num * mult + 0.5) / mult
&nbsp;&nbsp;&nbsp;else return math.ceil(num * mult - 0.5) / mult end
else return num end
end

function Value(I,VType,ds) 
local Out = nil
VType=(VType and string.upper(string.sub(VType,1,1))) or "A"
&nbsp;&nbsp;&nbsp;if VType == "O" then&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--Open
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = (O and O(I)) or (ds and ds:O(I))
&nbsp;&nbsp;&nbsp;elseif VType == "H" then &nbsp;&nbsp;&nbsp;--High
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = (H and H(I)) or (ds and ds:H(I))
&nbsp;&nbsp;&nbsp;elseif VType == "L" then&nbsp;&nbsp;&nbsp;--Low
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = (L and L(I)) or (ds and ds:L(I))
&nbsp;&nbsp;&nbsp;elseif VType == "C" then&nbsp;&nbsp;&nbsp;--Close
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = (C and C(I)) or (ds and ds:C(I))
&nbsp;&nbsp;&nbsp;elseif VType == "V" then&nbsp;&nbsp;&nbsp;--Volume
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = (V and V(I)) or (ds and ds:V(I)) 
&nbsp;&nbsp;&nbsp;elseif VType == "M" then&nbsp;&nbsp;&nbsp;--Median
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = ((Value(I,"H",ds) + Value(I,"L",ds)) / 2)
&nbsp;&nbsp;&nbsp;elseif VType == "T" then&nbsp;&nbsp;&nbsp;--Typical
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = ((Value(I,"M",ds) * 2 + Value(I,"C",ds))/3)
&nbsp;&nbsp;&nbsp;elseif VType == "W" then&nbsp;&nbsp;&nbsp;--Weighted
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = ((Value(I,"T",ds) * 3 + Value(I,"O",ds))/4) 
&nbsp;&nbsp;&nbsp;elseif VType == "D" then&nbsp;&nbsp;&nbsp;--Difference
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Out = (Value(I,"H",ds) - Value(I,"L",ds))
&nbsp;&nbsp;&nbsp;elseif VType == "A" then&nbsp;&nbsp;&nbsp;--Any
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ds then Out = ds&#91;I&#93; else Out = nil end
&nbsp;&nbsp;&nbsp;end
return Out
end
</pre>
============= <br />
			<i>22.07.2016 22:11:50, Сергей Качурин.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum10/message17398/topic1966/</link>
			<guid>http://forum.quik.ru/messages/forum10/message17398/topic1966/</guid>
			<pubDate>Fri, 22 Jul 2016 22:11:50 +0300</pubDate>
			<category>Программирование на языке Lua</category>
		</item>
	</channel>
</rss>
