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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        630 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        364 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        566 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        568 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X