Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NinjaTrader's OrderAction syntax causing problems. An update is needed.

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

    NinjaTrader's OrderAction syntax causing problems. An update is needed.

    I've created a CopyTrader add-on/strategy, but the internal OrderAction syntax is causing major issues, such as entering opposite trades on follower accounts when exiting on the Leader account. The issue is mainly on Long entries.

    The issue is caused by the OrderAction syntax used when exiting a long position. The order action received is 'Sell' rather than 'SellToCover'. If the Leader account enters and exits a trade fast before the Follower accounts have entered a trade, the followers are entered into a SHORT position which is a major problem.

    These are the OrderAction commands sent by NinjaTrader when an order is executed. As you can see, the LONG OrderAction syntax is problematic:

    LONG entry/exit:
    Entry-Execution received: Buy on Leader account.
    Exit-Execution received: Sell on Leader account.


    SHORT entry/exit:
    Entry-Execution received: Sell on Leader account.
    Exit-Execution received: BuyToCover on Leader account.


    The coding guide makes mention of a 'OrderAction.SellShort', but I am having trouble receiving this command. What is the correct way to properly distinguish entries from exits? Specifically - is there a way to distinguish a LONG exit from a SHORT entry order?
    Last edited by chromej; 06-30-2024, 10:26 AM.

    #2
    Hello chromej,

    The order actions that you see depend on the type of orders being submitted and what position they enter or target. Most commonly you would see
    Buy - Enter long position
    SellShort - Enter short position. you may also see sell depending on the tool or how a script is entering a short position.
    Buy to cover - close short position.
    Sell - close long position, this may also be used to enter a short position

    If you are making a trade copier you would also need context of the position information from the original account and follower account to know the intention of the order before submitting it For example if account A is long and account B is flat, if account A closes the position you would need to know account B is already flat and does not match account A then ignore that order. If the position was otherwise in sync you could submit the same type of order so it correctly enters/exits a position.

    Comment


      #3
      Thanks for addressing my issue.

      I have tried multiple ways of submitting orders, including:
      EnterLong(quantity, "CopyTraderBuy");
      EnterShort(quantity, "CopyTraderSellShort");

      SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Market, quantity, 0, 0, "", "CopyTraderBuy");
      SubmitOrderUnmanaged(0, OrderAction.SellShort, OrderType.Market, quantity, 0, 0, "", "CopyTraderSellShort");
      SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Market, quantity, 0, 0, "", "CopyTraderSell");
      SubmitOrderUnmanaged(0, OrderAction.BuyToCover, OrderType.Market, quantity, 0, 0, "", "CopyTraderBuyToCover");

      All of these return the same OrderAction, unfortunately. It would make things a whole easier if NinjaTrader would simply return 'SellToCover' on Exits.

      I noticed in the Control Center's Execution tab, It lists whether a trade is an "Entry" or "Exit". Is there a NinjaScript method that returns whether trades are "Entries" and "Exits"?

      Question - why is 'BuyToCover' to cover returned on a Short exit, but 'Sell' is returned on a Long exit? This seems like it may have a been a coding oversight that was never caught.

      ​Thanks.
      Last edited by chromej; 07-01-2024, 05:14 PM.

      Comment


        #4
        Hello chromej,

        You can view a trades (paired entry + exit) orders however that will only be available later after the exit order has been filled and is only available to the strategy that made the orders. For the purpose of copying an order you would need to use OnOrderUpdate or OnExecutionUpdate for event driven logic.

        While using OnExecutionUpdate you can use the overload that provides a position to determine what the position of the execution was.

        Regarding the order names, knowing the name of the order would still not help to address the situation you described because that is a timing issue. If the follower account was flat when your script tried to submit an order to close its position the follower has at that point already become two orders out of sync. It would still have entered the wrong position regardless of what the order name was. To avoid that you would either have to compare positions to block that order from being submitted so an incorrect position is not entered or you would need to have logic to wait for the follower account to enter the position so it is in sync with the leader account before submitting those orders at a later time.

        Keep in mind there is no expectation that two seperate accounts will have identical fills so you can easily see the two accounts become out of sync if your logic or market dynamics allows for that to happen.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        44 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        124 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        65 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X