Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

maybe bug with automated trading orderid

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    maybe bug with automated trading orderid

    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

    #2
    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.
    RayNinjaTrader Customer Service

    Comment


      #3
      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


      Originally posted by NinjaTrader_Ray View Post
      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.

      Comment


        #4
        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.
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by kevinenergy, 02-17-2023, 12:42 PM
        118 responses
        2,778 views
        1 like
        Last Post kevinenergy  
        Started by briansaul, Today, 05:31 AM
        0 responses
        9 views
        0 likes
        Last Post briansaul  
        Started by traderqz, Yesterday, 12:06 AM
        11 responses
        28 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by PaulMohn, Today, 03:49 AM
        0 responses
        9 views
        0 likes
        Last Post PaulMohn  
        Started by inanazsocial, Today, 01:15 AM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Jason  
        Working...
        X