i would like to discuse one problem, which i figured out and i didnt find thread, where to place my question. So I'm sorry about this. But I really need to fix following problem:
- Code: Select all
function CloseTrade(side)
local enum, row, valuemap;
enum = core.host:findTable("trades"):enumerator();
row = enum:next();
while row ~= nil do
if row.BS == side then
valuemap = core.valuemap();
if CANCLOSE then
-- non-FIFO account, create a close market order
valuemap.OrderType = "CM";
valuemap.Quantity = row.Lot;
valuemap.TradeID = row.TradeID;
else
-- FIFO account, create an opposite market order
valuemap.OrderType = "OM";
valuemap.Quantity = AMOUNT;
end
valuemap.OfferID = OFFER;
valuemap.AcctID = ACCOUNT;
valuemap.CustomID = CID;
if row.BS == "B" then
valuemap.BuySell = "S";
else
valuemap.BuySell = "B";
end
success, msg = terminal:execute(200, valuemap);
assert(success, msg);
end
row = enum:next();
end
end
thi function should end opened position according to parameter side (sell or buy pos.), but problem is that its not pass all elements. It forget to check last row(trade) and it still open. My question is, if its just me or another guys have same problem?
how to fix this?
I tried recursive calling of this function (looks little bit differently), but the problem is still there even I thought that position will be reseted and its not.
when Im debugging that code. I can see there 2 opened position (both Sell), but closed is just one. During second cycle is row nil and then its of course end of the function.....
As I said, I tried recursive calling of it -> same results. Also I tried somehow to reset enum via function enum:reset() its not help either.
For me It looks like a bug in source code....any advice? Is there any function which has to be presented in strategy or anything else?