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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        67 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        36 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        59 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        62 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        53 views
        0 likes
        Last Post CarlTrading  
        Working...
        X