I think I found a bug in the helper.lua file.
ExtSubscribe1(1, "EUR/USD", "t1", 1000, true, "bar") <<< this works ok
ExtSubscribe1(1, nil, "t1", 1000, true, "bar") <<< this doesn't work
Using "nil" for the instrument is supposed to use the default. This is how it works for non-tick sources, and also how it works for ExtSubscribe (for bar and tick sources). But, it seems for ExtSubscribe1, when "t1" is specified as the period, and nil specified as the instrument it does not work.
I think this is a mistake when this version of the function was "copied" from ExtSubscribe. ExtSubscribe has special handling for nil and "t1" which uses the instance.bid or instance.ask. This can not be used for ExtSubscribe1, but instead the tick is not handled properly.
Attempting to call ExtSubscribe1 with nil and "t1" returns nil.
I think the function needs to set sub.tick like it does for non-tick data, e.g. (See comments with ***)
- Code: Select all
-- subscribe for the price data
function ExtSubscribe1(id, instrument, period, count, bid, type)
local sub = {};
if instrument == nil then
sub.stream = core.host:execute("getHistory1", id, instance.bid:instrument(), period, count, 0, bid);
--sub.tick = false; -- *** this is original code ***
sub.tick = (period == "t1"); -- *** I think this should be used ***
sub.loaded = false;
sub.lastSerial = -1;
_gSubscription[id] = sub;
else
sub.stream = core.host:execute("getHistory1", id, instrument, period, count, 0, bid);
sub.tick = (period == "t1");
sub.loaded = false;
sub.lastSerial = -1;
_gSubscription[id] = sub;
end
if sub.tick then
return sub.stream;
else
if type == "open" then
return sub.stream.open;
elseif type == "high" then
return sub.stream.high;
elseif type == "low" then
return sub.stream.low;
elseif type == "close" then
return sub.stream.close;
elseif type == "bar" then
return sub.stream;
else
assert(false, type .. " is unknown");
end
end
end