I'd like to find the highest/lowest entry price in the open trades table and return that as value (storage1) of a function.
Therefore i wrote 2 functions findhighestprice () and find lowestprice():
- Code: Select all
function findhighestprice()
local storage1, enum2, row2={},{};
enum2 = core.host:findTable("trades"):find("TradeID", instance.bid:instrument()).Open;
row2 = enum2:next();
while row2 ~=nil do
if row2.OPEN>storage1 then
storage1=row2.OPEN;
end;
row2=enum2:next();
end
return storage1
end
function findlowesprice()
local enum2, row2={},{};
enum2 = core.host:findTable("trades"):find("TradeID", instance.bid:instrument()).Open;
row2 = enum2:next();
while row2 ~=nil do
if row2.OPEN<storage1 then
storage1=row2.OPEN;
end;
row2=enum2:next();
end
return storage1
end
I am getting the error: attempt to index a nil value for the line
- Code: Select all
enum2 = core.host:findTable("trades"):find("TradeID", instance.bid:instrument()).Open;
Q
- a) Is that an efficient way at all?
a) What's the problem with the error message?
tnx & best regards!