I am consistently encountering bugs when developing code using host:execute("getSyncHistory", ...).
The problem is that the code works fine in the editor/debugger but in marketsope it exhibits buggy behavior or throws errors.
Can someone from the dev team please be responsive to this issue. Can you at least verify that you are getting the same behavior?
How is it even possible for code to execute fine in the debugger and throw errors in the platform? This makes it impossible to develop code and extremely frustrating.
I reported on this earlier on this thread and there has been no response from the dev team.
http://fxcodebase.com/code/viewtopic.php?f=25&t=40395&start=200#p108324Here is another example. Please confirm that you can run this in the debugger without throwing an error and then run it in marketscope and get an error.
- Code: Select all
function Init()
indicator:name("demo")
indicator:description("")
indicator:requiredSource(core.Bar)
indicator:type(core.Indicator)
end
local LTF, HTF
local first
local i
local barSize
local host
local mod
local dayoffset, weekoffset
local loading
local date, minutes
function Prepare()
LTF = instance.source
local name
name = profile:id() .. "(" .. instance.source:name() .. ")"
instance:name(name)
host = core.host
dayoffset = core.host:execute("getTradingDayOffset")
weekoffset = core.host:execute("getTradingWeekOffset")
barSize = "m5"
i = 2
first = LTF:first()
o = instance:addStream("o", core.Line, name, "output", core.rgb(0, 0, 255), first)
HTF = host:execute("getSyncHistory", LTF:instrument(), barSize, LTF:isBid(), i + 1, 100, 101)
mod = (barToMinutes(barSize) * i) / barToMinutes(LTF:barSize())
end
function Update(period, mode)
if loading or HTF:size() == 0 then
return false
end
if period < LTF:first() then
return false
end
p = getP(period)
if not p then
return;
end
end
-- the function is called when the async operation is finished
function AsyncOperationFinished(cookie)
if cookie == 100 then
loading = false;
--instance:updateFrom(0);
elseif cookie == 101 then
loading = true;
end
end
function getP(period)
local barBegin
date = core.dateToTable(LTF:date(period))
minutes = date.min + (date.hour * 60)
if minutes % mod == 0 then
-- get datetime of beggining of current LTF period
barBegin = core.getcandle(barSize, LTF:date(period), dayoffset, weekoffset)
-- get index of the HTF current period
P = core.findDate(HTF, barBegin, false)
end
-- candle is not found
if P < 0 then
return false
else
return P
end
end
-- converts the bar size string into minutes for bar sizes D1 or less
function barToMinutes(barsize)
local t, q, v
t = string.sub(barsize, 1, 1)
q = tonumber(string.sub(barsize, 2))
if t == "m" then v = q
elseif t == "H" and q == 1 then v = 60
elseif t == "H" and q == 2 then v = 120
elseif t == "H" and q == 3 then v = 180
elseif t == "H" and q == 4 then v = 240
elseif t == "H" and q == 6 then v = 360
elseif t == "H" and q == 8 then v = 480
elseif t == "D" then v = 1440
else assert(false, "barToMinutes: Bar size is out of bounds. Use D1 or less.") end
return v
end
This is the error I get when executed in market scope. I have done extensive tracing of this variable in the debugger and know that it is not a nil value when run in the debugger.
Thank you.
Regards.