I am getting duplicate orders filled and the order ID in the log does not match what is showing in Tradestation as the order ID.
I am running this code in radarscreen as I want to have the ability to have the criteria I wrote for radar determine entry and at what price for several stocks right at the open. (my code doesn't work in a chart and life is easier if I can get the automation to work in a radar screen)
here is my code:
DefineDLLFunc: "NtDirect.dll", int, "SetUp", lpstr, int;
SetUp("192.168.0.174", 36973);
if CurrentBar = 1 then begin
SetUp("192.168.0.174", 36973);
end;
{inputs: FastLength(9), SlowLength(18) ;}
variables: FastAvg(0), SlowAvg(0), Success(0),varNTFilled(0), varNTNewOrderId(0);
if LastBarOnChart and NTConnected(1) then begin
if NTMarketPosition("") = 0 and
NTOrderStatus(NTNewOrderId) = "" then begin
{ place an order, if there is no position yet }
if high > low[1]-25 then begin
Success = NTBuyLimit(NTNewOrderId, 200,last); {orderID, qty, price}
plot1(last, "entry");
plot2(NTNewOrderId, "NTNewOrderId");
varNTFilled = NTFilled(NTNewOrderId);
plot3(varNTFilled, "NTFilled");
plot4(Success, "Success");
end;
end else begin
{ print some information on the current position and order }
Print("Position size: " + NumToStr(NTMarketPosition(""), 0));
Print("AvgEntryPrice: " + NumToStr(NTAvgEntryPrice(""), 2));
Print("OrderStatus: " + NTOrderStatus("MyOrderId"));
Print("Filled #: " + NumToStr(NTFilled("MyOrderId"), 0));
Print("AvgFillPrice: " + NumToStr(NTAvgFillPrice("MyOrderId"), 2));
Print("BuyingPower: " + NumToStr(NTBuyingPower(""), 2));
Print("CashValue: " + NumToStr(NTCashValue(""), 2));
Print("RealizedPnL: " + NumToStr(NTRealizedPnL(""), 2));
end;
end;
I have tried the same code in both a chart and radar screen and get duplicate/multiple orders as if it was running through a loop several times. TS and NT are not on the same machine. I am using the SIM account in NT to test (then to the IB sim acct and then hopefully to live IB)
The code has NTNewOrderId in the buylimit but the order ID that is displayed in both the radar screen and the chart is not EVER found in the NT log.
Thank you in advance
Comment