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

Execution attributes... isEntry vs isEntryStrategy etc...

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

    Execution attributes... isEntry vs isEntryStrategy etc...

    I've been working for a good while on a little something to (hopefully) settle the debate that raged some months back about shortcomings in the Trade Performance Trades report... Thought I had it all but finished... then found a scenario in which my Trades report was wrong... and it is due I think to mingling of vanilla/manual executions (isEntry/isExit) with those generated by a strategy (isEntryStrategy/isExitStrategy).

    So... diving right in...

    Creating a list of trades is easy if all executions are manual... or all are strategy-generated.. but I am having trouble reconciling the unusual cases... like when my account has 1 Short position...then I execute a single Buy (qty 1)... and NT reports I am now 1 Long. Yep... More of this later, as I've found another nasty reporting glitch... but I digress...

    The point of this post is to see if I can accurately replicate NT's reporting logic (where it is right ;-) And do better where it isn't.

    I currently examine each execution in sequence, and "do stuff", including maintaining a stack or queue of entry executions, then, when I get an exit... I have a TRADE and can do more stuff.
    My current implementation combines strategy and non-strategy entries in the one queue/stack... my question is this:

    Do I need to maintain SEPARATE queues/stacks for the two flavours? Essentially running manual vs strategy executions/trades in parallel, rather than essentially merging them?

    Cheers,
    T.

    #2
    Hello tgn55,

    Thank you for your post.

    NinjaTrader pairs trades first in/first out regardless of whether the trade was entered by a strategy or by manual means - they're not in two separate "stacks". So Strategy B's exit could close Strategy A's entry, or a manual order could close Strategy A's entry - this would be strictly sequenced by timestamp.

    Separate queues would not be necessary to reproduce this.

    Please let us know if we may be of further assistance to you.



    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thanks Kate. I sort of figured that out after I posted, but good to have official confirmation.

      Things get a tad tricky when trades are flagged as both an entry and an exit...my code did appear to manage that just fine, as I said - I thought I was done, until another test revealed a scenario where it all went pear-shaped. See details at end of the post...

      The legitimate scenario where this happens is say you are 1S... and place an execution to buy 3... ending up with final position 2L. In this instance, there is an implied exit, plus an entry long (Well, that's my interpretation...) so, it makes sense. The case shown below does not....in my view.

      Your comment above has got me thinking about another situation that my code has not yet addressed (mostly because I have not yet referred to the "Strategy/Template" field... on the to-do list;-)

      In the case that you have two strategies running on the same instrument...in the same account (Personally I don't do this... as it seems fraught with risk...) I presume a strategy A exit should NEVER be paired with a strategy B entry ... right?

      Clearly this arrangement has the potential to mess up synchronisation... (same as entering a manual execution when a strategy is already running), so maybe the quick answer is "Just don't do it - and don't worry about coding for it"

      What triggered this issue for me is this: So I know that normally, strategy-generated executions are flagged as BOTH , ie an entry is flagged as isEntry and also isEntryStrategy, ditto for exits.
      What messed up my Addon code is this:

      Click image for larger version

Name:	Entry-Exit 1.sdf.png
Views:	462
Size:	78.2 KB
ID:	1128114

      And here is the corresponding Execution list:
      Click image for larger version

Name:	Entry-Exit 2.png
Views:	420
Size:	71.3 KB
ID:	1128115

      After a while, things got back "in synch" again (not shown).
      Any comment on this?

      Regards,
      T.

      Comment


        #4
        Hello tgn55,

        Thank you for your reply.

        In the case that you are running two strategies simultaneously on the same instrument and account combination, it would be entirely possible for strategy A's exit to be paired with Strategy B's entrance and vice versa. This would make the strategies not synchronized to your account position, and is a major reason why we don't advise running multiple strategies on the same account and instrument combination.

        The screenshots provided do look like there's something a bit off. We'd need to take a look at your log and trace files as well as the database to see what may have occurred there.

        Rather than have you post those publicly, since they may contain personally identifiable information, please send me your database, log, and trace files so that I may look into what occurred.

        You can do this by going to the Control Center-> Help-> Email Support

        Expand 'Other files' and enable 'Database file'.

        Please reference the following ticket number in the body of the email: 2837206 ATTN Kate W.

        Thanks in advance; I look forward to assisting you further.


        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Hello tgn55,

          Thank you for your patience.

          This appears to be a database issue that may be resolved by updating to the latest version of NinjaTrader (we just released a new version yesterday) and running a database repair.

          First, to update NinjaTrader, please follow the steps below:
          • First, copy your license key from NinjaTrader under Help> License Key then exit NinjaTrader
          • Click on the link: https://ninjatrader.com/PlatformDirect
          • Enter your license key and press Submit
          • Select 'NinjaTrader 8'
          • Select 'Download'
          • Critical: Before running the installer, ensure NinjaTrader is closed.
          Once complete, restart NinjaTrader, disconnect from any open connections, and go to Tools > Database Management > Repair Database. Click the arrow next to this to expand the section and click Repair. Once the repair completes, restart NinjaTrader and regenerate a new Trade Performance report. After repairing the database I was able to see the position change as expected for the trades you pointed out.

          I'll also be replying to your email with this information as well.

          Please let us know if we may be of further assistance to you.
          Kate W.NinjaTrader Customer Service

          Comment


            #6
            Thanks Kate.

            It has resolved SOME of the odd trades in my sdf... but not all (fairly old trades still look fishy), so I'm a bit intrigued as to what the cleanup parameters were... but this is a bit academic.

            Of greater concern is that even with this applied, NT is still creating some incorrect (recent) trades... like this: the highlighted row has an entry recorded as an exit:
            Click image for larger version

Name:	2020-11-24 23_37_57-Trade Performance - Report.png
Views:	223
Size:	47.1 KB
ID:	1129159
            Now, yes in this case I manually entered some executions whilst strategy AAS0531 was running, as I am torture-testing my code... but, my process generates this: (NOTE: this is NOT NT's Trade Performance report... it is my own creation...just to avoid any confusion ;-)

            Click image for larger version

Name:	2020-11-24 23_43_17-TTR2Q Window.png
Views:	222
Size:	28.1 KB
ID:	1129160
            As you can see... I never report an entry (SE) as an exit like NT does ... but then again... it's still not quite kosher, as it really should be "LE" not "SE". So, a bit more debugging for me yet.

            Bottom line is, I still think NT's database and reporting system is not entirely correct... but that's OK... if I can fix 1 or 2 remaining minor issues in my code... I will have (I hope) a marketable addon !!
            (Making negative values red is proving quite the coding challenge ;-( but that's another topic!

            Cheers,
            T.
            Attached Files

            Comment


              #7
              Hello tgn55,

              Thank you for your reply.

              We can confirm that trade performance reporting has limitations since NinjaTrader does not actually track trades and attempts to pair executions together to form trades. It does so in first in/first out order.

              If there is a specific case that you would like us to look into with trade pairing, please provide specific steps we can take to reproduce those trades. Keep in mind, if the mismatched trades are a limitation of the current design, changes would not be made in the near term.

              Please let us know if we may be of further assistance to you.
              Kate W.NinjaTrader Customer Service

              Comment


                #8
                Thanks Kate.

                No need for further input, I think... I am close to having my addon ready for release, it all started in a thread that inevitably resulted in Jim (?) referring to the dreaded execution pairing...
                I will say more about this when I done debugging...

                Cheers,
                T.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by DJ888, Yesterday, 10:57 PM
                0 responses
                6 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by MacDad, 02-25-2024, 11:48 PM
                7 responses
                158 views
                0 likes
                Last Post loganjarosz123  
                Started by Belfortbucks, Yesterday, 09:29 PM
                0 responses
                7 views
                0 likes
                Last Post Belfortbucks  
                Started by zstheorist, Yesterday, 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
                 
                Working...
                X