Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Orders cancelled but Position Open

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

    Orders cancelled but Position Open

    Running strategies and brokered through Rithmic/APEX. When I reach a profit target on some occasions the position is closed by Rithmic but I still see an open position with unrealized profit/loss showing on the NT8 Strategies grid in control panel. Looking at the trade, it appears that the entry name for this open position/trade is an exit command.such as Trail Stop. This position was created immediately after the close of the previous trade. Any thoughts on what might be causing this? Some Ideas:
    1. Rithmic closes a trade properly but does not communicate to Ninja the close and the Trade carries on
    2. Rithmic issues a close command and checks to see if executed. If it does not see a closed position in time either Rithmic or Ninja reissues another close command so that the first close exits the trade and the second one enters a trade with no control
    3. The second trade position is in the opposite direction of the original first trade. (ie on a long the entry is a trail stop sell for a short positon)
    4. A trade setting (ie OCO) is not set properly
    The second entry/position has caused some significant losses at it is not called for and not based on any strategy or favorable set of indicators. Has anyone else experienced these unwanted positions/orders?

    Help appreciated. Thanks

    #2
    Hello PhoenixApex,

    Thanks for your post and welcome to the Forums!

    Please answer all of the questions below so I may accurately assist.
    • What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 8.0.?.? or 8.1.?.?)​
    • Are the strategies in question created by you or were they created by a third-party developer?
    • If the strategies were created by you, are you using Exit methods such as ExitLongStopLimit() and Set methods such as SetTrailStop() in the same script?
    • Do you receive an error on screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?
    • Are you able to reproduce the behavior using the Playback connection?
      • Playback: https://ninjatrader.com/support/help...connection.htm
      • If so, please send me a reduced copy of the script and the exact steps and settings you used to reproduce the behavior so I can try to reproduce it on my end.
        • Note that a reduced copy refers to a copy of the script that contains the minimum amount of code needed to reproduce the issue. All other code is commented out or removed.
        • To create a copy of your script to modify, open a New > NinjaScript Editor, select your script, right-click in the Editor, select 'Save as', name the script, and click OK.
    I look forward to assisting further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Brandon

      Thanks for getting back to me. I will try to answer your questions as best I can and will provide some additional info once I can as noted:
      1. I am using Version 8.0.27.0 64-bit
      2. I created the strategies myself
      3. I am using the following 3 exit methods
        1. TrailStop submitted with Order (includes Profit Target and TrailStop in OCO submission) as in command SetTrailStop("", CalculationMode.Ticks, TS, false); I do not have a ExitLongStopLimit() command in the script
        2. Command exit on reaching a user input BTT (which is Bars To Trade as in (BarsSinceEntryExecution(0, @"LE HRX", 0) >= BTT) which would execute the command ExitLong(Convert.ToInt32(DefaultQuantity), @"BTTL HRX", @"LE HRX");
        3. Command exit on reaching a Price Reversal(PR) as in (Close[0] <= Close[1]) which would execute the commandExitLong(Convert.ToInt32(DefaultQuantity), @"PRL HRX", @"LE HRX");
        4. Of course I have similar exit methods for Short entries as in 2 & 3 above
      4. I have not noted the screen errors but the log info for a trade at 11:28:32 on May 24th is uploaded
      5. Click image for larger version  Name:	Error1.png Views:	0 Size:	127.7 KB ID:	1254691
      6. This is the trade performance for the sequence of trades. Note that the entries at 11:28:32 as a Trail Stop exit and PRL HRX Entry. Click image for larger version  Name:	Error2.png Views:	0 Size:	88.9 KB ID:	1254689
      7. The SAME strategy was being run on three different APEX accounts but Account 6 and 11 are running 2 contract trades while Account 12 was running 3 contracts. The problem was on Account 11 as shown
      8. I will run a Playback of the day with the Strategy that created the problem but I suspect that it will not produce the same result as
        • I am not going through the IB (Rithmic APEX)
        • The error is random for the strategy. I have had numerous trades with the same strategy with no problem while I have had about 12 trades in the last month that have show Exit Named (as in reply 3 above) entries
        • If I can replicated the problem I will send you a redacted version of the source code.
      Thanks in advance for your help.
      Attached Files
      Last edited by PhoenixApex; 06-05-2023, 05:40 PM.

      Comment


        #4
        Hello PhoenixApex,

        Thanks for your notes.

        I see you are using an old version of NinjaTrader. Please update to NinjaTrader 8 version 8.0.28.0 by using the download lin on the NinjaTrader article below.



        That said, your logic still may be calling Enter/Exit on the same bar. You can test with the Exit behavior removed to confirm if the Exit behavior is causing the issue.

        I would then suggest adding a bool to the strategy so you can better control the logic.

        For example, once the bool is created in Inputs and Variables, create a new condition set in Conditions and Actions that does not have any conditions. This should be Condition Set 1. In this Condition Set, create an action that sets the bool to true. This will be done on each bar that the strategy processes, before the rest of the logic is processed.

        In your entry/reversal condition sets, set the bool to false. In your Exit condition sets, check if the bool is true before allowing the Exit to take place. This will ensure that these methods are not called on the same bar.

        More information about this error could be found on this forum thread: https://forum.ninjatrader.com/forum/...omplete​
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Thanks I will review and set the Bool.

          As for the Enter/Exit all calculations for the strategy are Calculate = Calculate.OnBarClose; so for those where the exit and entry are at the same time, I guess the Exit and immediate Entry could be on the bar after the bar that just closed.

          I had a repeat of the issue today where I had an exit on a BTTL close for 3 contracts but an entry on a Trail stop open on 1 contract (2 of the 3 closes cleared properly?) . In this case the close occurred at 10:11:32 but the open was significantly later at 10:12:13. In the trade, I realize things were amiss and closed. Fortunately for a profit.

          Click image for larger version

Name:	Error3.png
Views:	143
Size:	63.2 KB
ID:	1254776

          Comment


            #6
            I have had the problem with trades of only 1 contract but in this case the same strategy was running on 4 other accounts with a total of 14 contracts on 5 different accounts. Could the issue be in a lag/efficiency of processing the trades by APEX (IB) and sending information to Ninja on trade status?

            Comment


              #7
              Hello PhoenixApex,

              Thanks for your notes.

              To clarify, are you calling Entry methods and Exit methods in the same bar update? Such as calling ExitShort() and EnterLong() in the same condition in the script.

              You should make sure that you are not calling Entry and Exit methods at the same time anywhere in the script. This means that you cannot call ExitShort() and EnterLong() in the same condition, for example.

              The Entry methods and Exit methods must be separated in the script so that they are not called on the same bar update.

              See this forum thread for more information about this error: https://forum.ninjatrader.com/forum/ninjatrader-8/strategy-development/1140849-cancellation-rejected-by-the-order-management-system-order-is-complete
              Brandon H.NinjaTrader Customer Service

              Comment


                #8
                Brandon,

                They are definitely not called within the script. Entries are called when certain conditions are met. Exits are called when the conditions require the exit. The two are removed from each other. The problem is that I have an entry that is not called by the script, is labeled with an exit name and is definitely placed by something outside the script as I do not have any condition that would produce the entry.

                In the example I sent you there is an entry named Trail Stop. I do not have an entry condition that would produce such an entry. Only an exit. I really don't think this is a script issue but rather an order processing problem between Apex and Ninja.

                Comment


                  #9
                  Hello PhoenixApex,

                  Thanks for your notes.

                  Please write in to support[at]ninjatrader[dot]com with an exported copy of your strategy, the Order ID of the order you are referring to, and attach your Log and Trace files to your email so I may look into this further.

                  In the subject of the email include "ATTN: BrandonH" and in the body of the email include a link to this forum thread.

                  To export a NinjaScript, go to Tools > Export > NinjaScript Addon.

                  Follow the steps below to manually attach your log and trace files to your email.
                  • Open your NinjaTrader folder under, "Documents" (sometimes called, "My Documents")
                  • Right click on the 'log' and 'trace' folders and select Send To> Compressed (zipped) Folder.
                  • Send the 2 compressed folders as attachments to this email.
                  • Once complete, you can delete these compressed folders.
                  I look forward to assisting further.​
                  Brandon H.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks. I checked my log and only have one instance of this error (yesterday). I had a reentry called Trail Stop on a finished trade (3 contracts). The entry (1 contract) was strange in that it was 40 sec after the finished trade. The other errors where at the end of May and beginning of month. I will monitor and will send the info when I get the next good instance of this error.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Belfortbucks, Today, 09:29 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post Belfortbucks  
                    Started by zstheorist, Today, 07:52 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post zstheorist  
                    Started by pmachiraju, 11-01-2023, 04:46 AM
                    8 responses
                    151 views
                    0 likes
                    Last Post rehmans
                    by rehmans
                     
                    Started by mattbsea, Today, 05:44 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post mattbsea  
                    Started by RideMe, 04-07-2024, 04:54 PM
                    6 responses
                    33 views
                    0 likes
                    Last Post RideMe
                    by RideMe
                     
                    Working...
                    X