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

Export Realtime Strategy Performance

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

    Export Realtime Strategy Performance

    I am building a remote monitoring tool for my strategies and I would like to pretty much get all the REALTIME information available in "Strategy Performance Window" when you right click on a chart but I get error
    'NinjaTrader.Cbi.SystemPerformance' does not contain a definition for 'RealTrades' and no extension method 'RealTrades' accepting a first argument of type 'NinjaTrader.Cbi.SystemPerformance' could be found (are you missing a using directive or an assembly reference?)
    trying to call get this information using the code below.

    PHP Code:
                currentPosition         Position.MarketPosition.ToString();    
                
    positionSize            Position.Quantity.ToString();
                
    averageBarsInTrade        = (SystemPerformance.RealTrades.TradesPerformance.AverageBarsInTrade).ToString();
                
    averageEntryEfficiency    = (SystemPerformance.RealTrades.TradesPerformance.AverageEntryEfficiency).ToString();
                
    averageExitEfficiency    = (SystemPerformance.RealTrades.TradesPerformance.AverageExitEfficiency).ToString();
                
    averageTimeInMarket        = (SystemPerformance.RealTrades.TradesPerformance.AverageTimeInMarket).ToString();
                
    averageTotalEfficiency    = (SystemPerformance.RealTrades.TradesPerformance.AverageTotalEfficiency).ToString();
                
    commission                = (SystemPerformance.RealTrades.TradesPerformance.TotalCommission).ToString();
                
    grossLoss                = (SystemPerformance.RealTrades.TradesPerformance.GrossLoss).ToString();
                
    grossProfit                = (SystemPerformance.RealTrades.TradesPerformance.GrossProfit).ToString();
                
    longestFlatPeriod        = (SystemPerformance.RealTrades.TradesPerformance.LongestFlatPeriod).ToString();
                
    maxConsecutiveLoser        = (SystemPerformance.RealTrades.TradesPerformance.MaxConsecutiveLoser).ToString();
                
    maxConsecutiveWinner    = (SystemPerformance.RealTrades.TradesPerformance.MaxConsecutiveWinner).ToString();
                
    netProfit                = (SystemPerformance.RealTrades.TradesPerformance.NetProfit).ToString();
                
    profitFactor            = (SystemPerformance.RealTrades.TradesPerformance.ProfitFactor).ToString();
                
    riskFreeReturn            = (SystemPerformance.RealTrades.TradesPerformance.SharpeRatio).ToString();
                
    totalQuantity            = (SystemPerformance.RealTrades.TradesPerformance.TotalQuantity).ToString();
                
    tradesCount                = (SystemPerformance.RealTrades.TradesPerformance.TradesCount).ToString();
                
    tradesPerDay            = (SystemPerformance.RealTrades.TradesPerformance.TradesPerDay).ToString(); 
    How would you call only the realtime information? I see in the reference guide, it only references the "AllTrades". Would the only way around it would be to add an
    PHP Code:
                if(State == State.Historical)
                    return; 
    so that it does not execute against historical data.

    Ideally, I only want to see the strategy performance for the current session. Would that be possible to filter out? Or would I have to terminate the strategy and reinitialize it every session?
    Attached Files
    Last edited by cutzpr; 06-27-2018, 08:05 PM.

    #2
    Hello cutzpr,

    Thank you for your note.

    If you use SystemPerformance.RealTimeTrades instead of SystemPerformance.RealTrades, does that resolve the error?
    See, https://ninjatrader.com/support/help...timetrades.htm

    The historical return statement would prevent the strategy from running historically, so yes no historical trades would be returned.

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Thank you, yes it resolved the error. What a brain fart. But I am still unclear about my second question. If I only wanted to see the states for the real time trades for the current session. How would I do that? If I have the strategy running for five straight days, how can I only get that last day's trade performance?

      Comment


        #4
        Hello cutzpr,

        To pull trade performance data for trades taken today, you could check that a trade occurred after today’s date minus 1.

        I put together a sample which will print trades which were taken later than this time yesterday. If you wanted to specify the exact time, such as a session start time rather than todays date minus a day, you could define a DateTime object.

        For example you could replace DateTime.Now.AddDays(-1) with xDateTime, and define xDateTime like the following,

        Code:
        DateTime xDateTime = new DateTime(2018,06,28,09,01,00);
        Please see the attached sample and I suggest running it on a 1 second chart with the output window open.

        Please let us know if you need further assistance.
        Attached Files
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Hi Alan,

          I've downloaded the code, and modified it so it attempts to print out all of the trades, regardless of the date of the trade...but I am only getting '0' for the number of trades in that "SystemPerformance.AllTrades" collection.

          I've also set "IncludeTradeHistoryInBacktest = true;" in SetDefaults


          So what do I need to do to get trade information printing to the OutputWindow?

          Correction: I've been able to get some output on certain trades...but it's spotty. What I don't understand is, I'm only getting current positions, I'm not getting all historical trades when I pull from the SystemPerformance.AllTrades collection. Shouldn't I be getting all of my history?...including open and closed positions?

          All this to say that my ultimate goal here is to access to all historical trades. Not strategy-managed trades, but manually entered trades...so how can I get programmatic access to trade history?
          Last edited by sbgtrading; 07-11-2018, 02:02 PM.

          Comment


            #6
            Hello sbgtrading,

            Thank you for your note.

            Without the full code we're unable to test on our end.

            If you'd like to upload the full code I can take a look and see if anything jumps out.

            I look forward to your reply.
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              Thanks Alan,

              No need to dig into that code, really. What would help me is if you can give me info on how I can get all of the trades that have been entered and exited for that day...both manual and strategy-executed trades.

              How can I get data on all such trades?

              Comment


                #8
                Hello sbgtrading,

                The SystemPerformance Object holds trades generated by the strategy and could not be used for all trades including manual trades. You could however loop through all executions for the account.

                See the following section for our helpguide which contains an example of a loop which prints executions on the given account.


                Going forward please do not go back and modify earlier posts with information after you’ve received a reply so that we can keep the integrity of forum. It seems that information would have been just fine in your second reply.

                Please let us know if you need further assistance.
                Alan P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by nandhumca, Yesterday, 03:41 PM
                1 response
                12 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by The_Sec, Yesterday, 03:37 PM
                1 response
                11 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by vecnopus, Today, 06:15 AM
                0 responses
                1 view
                0 likes
                Last Post vecnopus  
                Started by Aviram Y, Today, 05:29 AM
                0 responses
                5 views
                0 likes
                Last Post Aviram Y  
                Started by quantismo, 04-17-2024, 05:13 PM
                3 responses
                27 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Working...
                X