Сергей, пока не уловил как надо. Строчка, которую Вы написали, полностью совпадает с моей кроме кавычек. Наверное что то не вижу.
Вот более полный код:
--Параметры:
p_classcode="TQBR"
p_seccode={"POLY","YNDX","AVAZ","GAZP","NLMK","RTKM","HYDR"}
chart={"RSI1","RSI2","RSI3","RSI4","RSI5","RSI6","RSI7"}
p_account="L01-00000F00"
p_clientcode="56445"
p_count=77
p_spread=0.7
p_buy_level_RSI=70
p_sell_level_RSI=30
--Служебные переменные
is_run = true
count = 0
in_trade = true
order_num = ""
direction = ""
last_price = 0
function main()
while is_run do
sleep(2000)
robot()
end
end
function to_log(a_msg)
p_file:write(os.date().." "..a_msg.."\n")
end
for i,v in pairs(p_seccode) do
function robot()
for i,v in pairs(chart) do
local RSI=getNumCandles(chart[i])
local N=getNumCandles("Price")
t,n,i=getCandlesByIndex("Price", 0, N-1, 1)
RSI_t,RSI_n,RSI_i=getCandlesByIndex("RSI", 0, RSI-3, 2)
if (in_trade) then
--сигнал на покупку (RSI пересекает уровень продажи снизу вверх)
if RSI_t[0].close<p_buy_level_RSI and RSI_t[1].close>p_buy_level_RSI then - - ВОТ ЗДЕСЬ ВЫБИВАЕТ ОШИБКУ
Trade("B",p_count-count,t[0].close+p_spread)
end
end
if not(in_trade) then
--сигнал на продажу (RSI пересекает уровень продажи сверху вниз)
if RSI_t[0].close>p_buy_level_RSI and RSI_t[1].close<p_buy_level_RSI then
Trade("S",count+p_count,t[0].close-p_spread)
end
end
if (in_trade) then
--сигнал на покупку (RSI пересекает уровень продажи сверху вниз)
if RSI_t[0].close>p_sell_level_RSI and RSI_t[1].close<p_sell_level_RSI then
Trade("S",p_count-count,t[0].close+p_spread)
end
end
if not (in_trade) then
--сигнал на продажу (RSI пересекает уровень продажи снизу вверх)
if RSI_t[0].close<p_sell_level_RSI and RSI_t[1].close>p_sell_level_RSI then
Trade("B",count+p_count,t[0].close-p_spread)
end
end
end
end
end