PDA

View Full Version : maybe bug with automated trading orderid


1reason
02-06-2010, 09:58 PM
I am a total newbe so its totally possible I am doing something wrong but here is the problem I am running into

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

NinjaTrader_Ray
02-07-2010, 07:53 AM
If you are getting multiple orders generated for the same signal, then then just means that your code really calls NTBuyLimit()... multiple times. You will have to debug your code and maybe add some code to prevent multiple calls to this method.

1reason
03-28-2010, 09:49 PM
Thank you for your reply.

I would agree with you and it appears that the second order is sent from TS to NT before NT lets TS that the first order is filled. If you look at my code it appears that it is supposed to do this check and it does in a chart but not radar.

Any help or suggestions?

Thank you

Robert


If you are getting multiple orders generated for the same signal, then then just means that your code really calls NTBuyLimit()... multiple times. You will have to debug your code and maybe add some code to prevent multiple calls to this method.

NinjaTrader_Bertrand
03-29-2010, 04:55 AM
Robert, are you referring to RadarScreen in TS? There's likely a different TS method needed when working in Radarscreen vs the chart you've been used to.