I have a strategy that enters and exists based on certain candle signals.
To close the position I'm using NetQtyFlag = "Y" parameter in the valuemap because in certain cases I may have multiple position open on the same side (see code below).
For some reason, the close request doesn't always work. The trade gets submitted and the async response is received with a "success" message, but the order's status reads as "C" (cancelled). This only happens SOMETIMES. Why would a "CM" order be cancelled? This is VERY frustrating since there is no reason as to what happened.
Any ideas?
(Additionally, it seems since Trading Station software update 01.15, many things have started acting inconsistently the backtester...)
- Code: Select all
function FXCMTrader:submitTradeCloseRequest()
local valuemap = core.valuemap();
valuemap.Command = "CreateOrder";
valuemap.OrderType = "CM";
valuemap.OfferID = self.offerId;
valuemap.AcctID = self.account;
valuemap.TradeID = self.tradeInfo[1].tradeId;
if (self.direction == 1) then
valuemap.BuySell = "S";
else
valuemap.BuySell = "B";
end
valuemap.NetQtyFlag = "Y"; -- <-- Close all open trades for this instrument.
local success, msg = terminal:execute(500, valuemap);
if not (success) then
trace(" Trade Close Submission Failure; Msg: " .. msg);
else
trace(" Trade Close Request Submitted; Msg: " .. msg);
end
end