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 CaptainJack, 05-29-2026, 05:09 AM
        0 responses
        388 views
        0 likes
        Last Post CaptainJack  
        Started by CaptainJack, 05-29-2026, 12:02 AM
        0 responses
        260 views
        0 likes
        Last Post CaptainJack  
        Started by charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        218 views
        1 like
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        302 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        268 views
        0 likes
        Last Post CarlTrading  
        Working...
        X