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

Retrieve list of executions

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

    Retrieve list of executions

    Hello,

    within TradePerformance it is possible to display Executions of filled orders within a pre-selected date range.

    Is there a sample code in C# to retrieve the list of executions within in NinjaScript?

    Gerik

    #2
    Hello Gerik,

    Thanks for your post.

    In New>Trade Performance, yes you can specify the begin and end dates of the report that is generated. Note that you can always right mouse click and select "export" to send the data into a speadsheet where you can sort and format as you wish: https://ninjatrader.com/support/help...data_grids.htm

    "Is there a sample code in C# to retrieve the list of executions within in NinjaScript?" You can do this within a strategy but it would be of the executions of the strategy. Please see the help guide here (examples in each section):


    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hello Paul,

      thank you for your answer. I want to retrieve the executions of the strategy also when the strategy has been restarted.

      Please add a feature request for that.

      Thank you
      Gerik

      Comment


        #4
        Hello Gerik ,

        Thanks for your reply.

        You already can retrieve both historical and real time trades. Please see: https://ninjatrader.com/support/help...erformance.htm

        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hello PaulH,

          thank you for your reply.

          With SystemPerformance.AllTrades.Count I receive 0 as a value although there has been already a round-turn of an instrument.

          Code:
          protected override void OnBarUpdate()
          {
          Print("The strategy has taken " + SystemPerformance.AllTrades.Count + " trades.");
          Print("The strategy has taken " + SystemPerformance.LongTrades.Count + " long trades.");
          Print("The strategy has taken " + SystemPerformance.RealTimeTrades.Count + " real-time trades.");
          Print("The strategy has taken " + SystemPerformance.ShortTrades.Count + " short trades.");
          }

          Result:
          The strategy has taken 0 trades.
          The strategy has taken 0 long trades.
          The strategy has taken 0 real-time trades.
          The strategy has taken 0 short trades.

          How can I access to the realtime and historical trades in case I recompile the strategy or restart the computer?

          Gerik

          Comment


            #6
            Hello Gerik,

            Thanks for your reply.

            I would suggest bracketing your code with:

            if (SystemPerformance.AllTrades.Count > 1)
            {
            // your code here
            }

            Note that when you restart or recompile and apply the strategy, it will perform historical trades where in the previous instance real time trades were made and those would then be shown as historical in the current instance. To clarify, Real Time would only be of the live data trades performed on the applied instance of the strategy.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Hello PaulH,

              thank you for your reply.

              Does SystemPerformance.AllTrades.Count only counts live trades? With my Sim101 account I get still 0 as a result.

              Gerik

              Comment


                #8
                Hello Gerik,

                Thanks for your reply.

                If you have historical trades they will show (In the new>Ninjascript output window) as soon as you apply the strategy.

                Do you see historical bars and trades when you look at the chart?

                I've created/attached a working example here, please create a chart of CL 02-20, 1 minute bars for example and run the strategy. Or you could run in the strategy analyzer as well.

                It will repeatedly enter long and exit based on profit target or stop loss, wait 10 bars and it will enter again. The code will print the values of the last trade. here is an example of the print:

                1/8/2020 1:22:00 PM Number of Trades: 133
                1/8/2020 1:22:00 PM Last trade entry:59.62
                1/8/2020 1:22:00 PM Last trade exit: 59.92
                1/8/2020 1:22:00 PM Last trade pnl: 300.000000000004
                1/8/2020 1:47:00 PM Number of Trades: 134
                1/8/2020 1:47:00 PM Last trade entry:59.97
                1/8/2020 1:47:00 PM Last trade exit: 60.27
                1/8/2020 1:47:00 PM Last trade pnl: 300.000000000004
                1/8/2020 2:17:00 PM Number of Trades: 135
                1/8/2020 2:17:00 PM Last trade entry:60.26
                1/8/2020 2:17:00 PM Last trade exit: 60.11
                1/8/2020 2:17:00 PM Last trade pnl: -149.999999999999
                1/8/2020 2:45:00 PM Number of Trades: 136
                1/8/2020 2:45:00 PM Last trade entry:60.1
                1/8/2020 2:45:00 PM Last trade exit: 59.95
                1/8/2020 2:45:00 PM Last trade pnl: -149.999999999999

                StrategyPerformanceDataExample.zip
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Hello PaulH,

                  thank you for your answer and the code. I need to retrieve the historical trades that are made in reality, not the hypothetic trades of the system. However, I receive also some values now, but when I remove the line EnterLong(); in your code, then SystemPerformance.AllTrade.Count turns back to 0, although I have already a long position in my Sim101 account. Therefore there must be at least one trade somehow.

                  Gerik

                  Comment


                    #10
                    Hello Gerik,

                    Thanks for your reply.

                    A strategy would only retrieve information concerning orders that the strategy placed. By removing the EnterLong() the strategy would not make any historical or real time trades so this would be expected that there would be no strategy performance data.

                    Orders made external to the strategy (by another strategy or manually) would be unknown to the strategy.

                    Perhaps I am misunderstanding what you are wanting to do. I've re-read your first post and has assumed this question, "Is there a sample code in C# to retrieve the list of executions within in NinjaScript?" was not related to the first question related to Trade performance. If that was indeed your inquiry then no we do not provide ninjascript methods to pull data from the database which would contain your trade history.

                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello PaulH,

                      thank you for your answer. Would be great if you could also add this to your development roadmap.

                      Anyhow, how can I avoid blind flying when using strategy automation? Is there any way to check the entry prices of a position?

                      Gerik

                      Comment


                        #12
                        Hello Gerik,

                        Thanks for your reply.

                        I will create a feature request to allow Ninjascript access to the same data as provided by the Trade Performance and will update this thread when I have further information.

                        If you are using single contracts you can query Position.AveragePrice: https://ninjatrader.com/support/help...erageprice.htm Otherwise you would need to query the order object to find its entry price. This example sgtrategy may help to see this (although it's focus is on stop and profit orders): https://ninjatrader.com/support/help..._and_profi.htm
                        Paul H.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello Gerik,

                          The feature request is identified as SFT-1540, "NinjaScript Database access".

                          As this was an already existing request, your vote was added to it along with this forum posting for reference.

                          Thanks for your interest to improve NinjaTrader.
                          Paul H.NinjaTrader Customer Service

                          Comment


                            #14
                            Hello Paul,

                            thank you for adding my vote to the feature request.

                            When will be the next board meeting to decide whether the feature request will be implemented?

                            Best regards
                            Gerik

                            Comment


                              #15
                              Hello Gerik,

                              Thanks for your reply.

                              A feature request does not mean that the feature will be implemented and is a means for program management to track user interest in the feature.

                              The current status of the feature request is open and you are welcome to inquire as to its status at any time.


                              Paul H.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Stanfillirenfro, Today, 07:23 AM
                              1 response
                              2 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by cmtjoancolmenero, Yesterday, 03:58 PM
                              2 responses
                              20 views
                              0 likes
                              Last Post cmtjoancolmenero  
                              Started by olisav57, Yesterday, 07:39 PM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by cocoescala, 10-12-2018, 11:02 PM
                              7 responses
                              943 views
                              0 likes
                              Last Post Jquiroz1975  
                              Started by oviejo, Today, 12:28 AM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X