Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NTClosePosition() not working?

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

    NTClosePosition() not working?

    I've written a simple TradeStation strategy that uses the NTDLL interface to manage orders, and put it in the current Euro contract 1 minute bar. The strategy buys properly, but can not close the order. While it's possible for me to simply call NTSellMarket() instead of NTClosePosition(), I was hoping that NTClosePosition() was more reliable, closing everything, just in case I had more open positions in the account than my strategy knew about. Is there anything wrong with the script? Is there possibly a bug in NTClosePosition()? Do you recommend NTSellMarket() instead of NTClosePosition()?

    vars: IsLiveTrading(False);
    IsLiveTrading = LastBarOnChart and NTConnected(0) and (IsLiveTrading[1] or DateToJulian(Date) >= DateToJulian(CurrentDate) - 1);

    if IsLiveTrading and BarStatus(1) = 2 then begin
    vars: Order.Position(0), Order.OpenContracts(0), Order.EntryBar(0);
    Value1 = NTMarketPosition("Sim101");
    Order.Position = Sign(Value1);
    Order.OpenContracts = AbsValue(Value1);

    vars: Live.Pending.Id("");
    if Order.Position = 0 and Live.Pending.Id = "" then begin
    Live.Pending.Id = "";
    Value9 = NTBuyMarket(Live.Pending.Id, 10);
    print("Buy " + numtostr(Close, GTG.TickPrecision) + " on " + numtostr(CurrentBar, 0));
    Order.EntryBar = CurrentBar;
    end else begin
    print("Order is open on Current Bar " + numtostr(CurrentBar, 0));

    if Live.Pending.Id <> "" and NTFilled(Live.Pending.Id) = 10 then begin
    Live.Pending.Id = "";
    print("Order is Filled");
    end;

    if CurrentBar = Order.EntryBar + 2 then begin
    Value9 = NTClosePosition("Sim101");
    // NTSellMarket(NTNewOrderId, 10);
    print("NTClosePosition");
    end;
    end;
    end;

    #2
    Doug, any errors you see in the log tab as the AT receives the TS Close Position order?

    Does it work any different if you use the ATI default account as specified in NT (like below) ?

    if CurrentBar = Order.EntryBar + 2 then begin
    Value9 = NTClosePosition("");
    print("NTClosePosition");
    end;
    end;
    end;

    Comment


      #3
      Nothing in the log tab. It does work if I use the default account "".

      Comment


        #4
        Thanks for reporting back Doug, we'll look into it further.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        61 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        148 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        162 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        98 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        286 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X