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

SystemPerformance.AllTrades.Count

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

    SystemPerformance.AllTrades.Count

    Code:
    			trade_count=SystemPerformance.AllTrades.Count;
    			
    Print(string.Format("{0};{1};{2};{3}", Time[0],SystemPerformance.AllTrades.TradesPerformance.Percent.CumProfit,Account.Name,trade_count));
    trade_count prints for backtesting, market replay and now i'm doing simulation testing for a live account and it's not printing. why?

    output window:

    Code:
    8/30/2018 1:00:00 AM;0.00825031579486279;****ABC******;0
    8/30/2018 1:00:00 AM;-0.029063823625113;****ABC******;0
    8/30/2018 1:00:00 AM;-0.0290638148653174;****ABC******;0
    I've even tried this:

    Code:
    Print(string.Format("{0};{1};{2};{3}", Time[0],SystemPerformance.AllTrades.TradesPerformance.Percent.CumProfit,Account.Name,SystemPerformance.AllTrades.Count));
    my entry is basic:

    Code:
    			if (Close[0] > Close[1] && (Position.MarketPosition==MarketPosition.Short || Position.MarketPosition==MarketPosition.Flat)) 
    			{				
    			EnterLong(Convert.ToInt32(100000), @"Long1");
    			}
    
    			if (Close[0] < Close[1] && (Position.MarketPosition==MarketPosition.Long || Position.MarketPosition==MarketPosition.Flat)) 
    			{
    			EnterShort(Convert.ToInt32(100000), @"Short1");
    			}
    -ps. system's opened and closed over 10 trades without any interruption
    Last edited by staycool3_a; 08-29-2018, 11:09 PM.

    #2
    Hello calhawk01,

    Thank you for your note.

    If you test with the attached strategy applied to a 5 second chart, after a few trades are you seeing prints to the output window?

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

    Comment


      #3
      Originally posted by NinjaTrader_AlanP View Post
      Hello calhawk01,

      Thank you for your note.

      If you test with the attached strategy applied to a 5 second chart, after a few trades are you seeing prints to the output window?

      I look forward to your reply.
      hi Alan.

      It's made many trades but the output window does not reflect the correct trade count.

      Code:
      execution='AUDUSD/0001f4e8.5b87d922.01.01' instrument='AUDUSD' account='ABC' exchange=Default price=0.72672 quantity=1 marketPosition=Long orderId='550014890' time='2018-08-30 12:51:16' sod=False statementDate='2018-08-30'
      The strategy has taken 0 trades.
      The strategy has taken 0 trades.
      The strategy has taken 0 trades.
      The strategy has taken 0 trades.
      The strategy has taken 0 trades.
      The strategy has taken 0 trades.
      execution='AUDUSD/0001f4e8.5b87d94e.01.01' instrument='AUDUSD' account='ABC' exchange=Default price=0.72677 quantity=1 marketPosition=Long orderId='550014894' time='2018-08-30 12:51:52' sod=False statementDate='2018-08-30'
      The strategy has taken 0 trades.
      The strategy has taken 0 trades.
      The strategy has taken 0 trades.
      The strategy has taken 0 trades.
      The strategy has taken 0 trades.
      The strategy has taken 0 trades.
      execution='AUDUSD/0001f4e8.5b87d972.01.01' instrument='AUDUSD' account='ABC' exchange=Default price=0.72679 quantity=1 marketPosition=Long orderId='550014898' time='2018-08-30 12:52:20' sod=False statementDate='2018-08-30'
      The strategy has taken 0 trades.
      The strategy has taken 0 trades.
      The strategy has taken 0 trades.
      The strategy has taken 0 trades.
      The strategy has taken 0 trades.
      The strategy has taken 0 trades.
      execution='AUDUSD/0001f4e8.5b87d985.01.01' instrument='AUDUSD' account='ABC' exchange=Default price=0.72679 quantity=1 marketPosition=Long orderId='550014902' time='2018-08-30 12:52:50' sod=False statementDate='2018-08-30'
      The strategy has taken 0 trades.
      The strategy has taken 0 trades.
      The strategy has taken 0 trades.
      The strategy has taken 0 trades.
      The strategy has taken 0 trades.
      The strategy has taken 0 trades.
      execution='AUDUSD/0001f4e8.5b87d9b7.01.01' instrument='AUDUSD' account='ABC' exchange=Default price=0.72675 quantity=1 marketPosition=Long orderId='550014906' time='2018-08-30 12:53:26' sod=False statementDate='2018-08-30'
      The strategy has taken 0 trades.
      The strategy has taken 0 trades.
      The strategy has taken 0 trades.
      The strategy has taken 0 trades.
      The strategy has taken 0 trades.
      Attached Files
      Last edited by staycool3_a; 08-30-2018, 11:13 AM.

      Comment


        #4
        Hello staycool3_a,

        A trade is a buy with a sell for a net flat position. If you submit 10 limit buy orders and all are filled, a "trade" does not occur until one or all of these are closed out.

        With the strategy I provided you continue to see to the output window, 0's for trade count?

        What version of NT8 are you using under help>about?

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

        Comment


          #5
          Originally posted by NinjaTrader_AlanP View Post
          Hello staycool3_a,

          A trade is a buy with a sell for a net flat position. If you submit 10 limit buy orders and all are filled, a "trade" does not occur until one or all of these are closed out.

          With the strategy I provided you continue to see to the output window, 0's for trade count?

          I look forward to your reply.
          I understand and I agree. A trade count will be 1 if the strategy opened and then closed a position. That is not what is happening here. As you can see from the order window (screenshot) that the strategy you sent me opened over X trades and then closed those X trades. Hence, trade count should be > 0.

          The strategy you provided to me -> was imported to NT8 -> i made no changes to the strategy -> and then I added the strategy and enabled it on the strategy tab using 5 second data... as instructed.

          The output window is showing zero trades even though the strategy has opened and closed many trades without any interruption.

          My version is: 8.0.14.2 64-bit

          ******************
          UPDATE: I just upgraded NT to : 8.0.15.1 64-bit
          Re ran the strategy that you sent me with. The strategy opened several trades and then closed the trades and became net flat various times. The issue is still occur. Trade count is zero.

          OUTPUT:

          Code:
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          execution='AUDUSD/0001f4e8.5b8800f2.01.01' instrument='AUDUSD' account='ABC' exchange=Default price=0.72656 quantity=100,000 marketPosition=Long orderId='550018376' time='2018-08-30 16:27:41' sod=False statementDate='2018-08-30'
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          execution='AUDUSD/0001f4e8.5b880101.01.01' instrument='AUDUSD' account='ABC' exchange=Default price=0.72654 quantity=100,000 marketPosition=Long orderId='550018380' time='2018-08-30 16:28:17' sod=False statementDate='2018-08-30'
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          execution='AUDUSD/0001f4e8.5b880122.01.01' instrument='AUDUSD' account='ABC' exchange=Default price=0.72654 quantity=100,000 marketPosition=Long orderId='550018384' time='2018-08-30 16:28:53' sod=False statementDate='2018-08-30'
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          execution='AUDUSD/0001f4e8.5b88015c.01.01' instrument='AUDUSD' account='ABC' exchange=Default price=0.72668 quantity=100,000 marketPosition=Long orderId='550018388' time='2018-08-30 16:29:40' sod=False statementDate='2018-08-30'
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          execution='AUDUSD/0001f4e8.5b880174.01.01' instrument='AUDUSD' account='ABC' exchange=Default price=0.72657 quantity=100,000 marketPosition=Long orderId='550018392' time='2018-08-30 16:30:20' sod=False statementDate='2018-08-30'
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          execution='AUDUSD/0001f4e8.5b880199.01.01' instrument='AUDUSD' account='ABC' exchange=Default price=0.72653 quantity=100,000 marketPosition=Long orderId='550018396' time='2018-08-30 16:31:02' sod=False statementDate='2018-08-30'
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          The strategy has taken 0 trades.
          execution='AUDUSD/0001f4e8.5b8801c8.01.01' instrument='AUDUSD' account='ABC' exchange=Default price=0.72654 quantity=100,000 marketPosition=Long orderId='ABC' time='2018-08-30 16:31:30' sod=False statementDate='2018-08-30'
          Attached are the screenshots for the order window, version of my strategy and output...
          Attached Files
          Last edited by staycool3_a; 08-30-2018, 02:35 PM.

          Comment


            #6
            Hello staycool3_a,

            If you connect to the simulated data feed and run the strategy on Sim101 account, are you seeing trade prints?

            If you switch the instrument from FX to ES 09-18 and run the strategy, are you seeing prints?

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

            Comment


              #7
              Originally posted by NinjaTrader_AlanP View Post
              Hello staycool3_a,

              If you connect to the simulated data feed and run the strategy on Sim101 account, are you seeing trade prints?

              If you switch the instrument from FX to ES 09-18 and run the strategy, are you seeing prints?

              I look forward to your reply.
              ******************************
              SIMULATION DATA FEED
              ******************************

              testing the strategy on simulated data feed and ran it with sim101. The trades are being counted correctly:

              Code:
              execution='bd401dfb73e24e6694fd5366ab181bed' instrument='AUDUSD' account='Sim101' exchange=Default price=0.72668 quantity=100,000 marketPosition=Long orderId='098e3d099232465a83dd736a48ff7b64' time='2018-08-30 19:20:25' sod=False statementDate='2018-08-30'
              The strategy has taken 1 trades.
              The strategy has taken 1 trades.
              The strategy has taken 1 trades.
              The strategy has taken 1 trades.
              The strategy has taken 1 trades.
              The strategy has taken 2 trades.
              execution='38191da71dc044e29a2acf5cb6e6a15b' instrument='AUDUSD' account='Sim101' exchange=Default price=0.72666 quantity=100,000 marketPosition=Long orderId='a03649a339174a8d9053681c9c7e28ae' time='2018-08-30 19:20:55' sod=False statementDate='2018-08-30'
              The strategy has taken 2 trades.
              The strategy has taken 2 trades.
              ********************************
              MARKET REPLAY: I also tested it on market replay. It works fine on market replay and calculates the trades correctly.
              *******************************

              ************************************************** ****
              LIVE DATA FEED AND NT 'SIM101' ACCOUNT; i also tested it with live IB data feed but in sim101 account. trades are being counted and printed correctly
              ************************************************** ****

              ************************************************** ****
              LIVE DATA FEED AND IB ACCOUNT; trades are being executed correctly but trades are not being counted at all. after many open and closed trades; trade count stays at 0.......................


              ///////////////////////////////////////////////////////////////////
              like i said on my original post. it works on backtest/simulation/market replay but apparently stops working as soon as you to live account.......super frustrating that something as simple as trade count is breaking. is this working on your end? can you show me a screenshot...

              ps. i am using IB Gateway API to connect with IB. however, i do not think IB API has anything to do with NT's ability to count trades that it's executing.............arn't these suppose to be virtual positions on NT's platform?
              Last edited by staycool3_a; 08-30-2018, 05:40 PM.

              Comment


                #8
                Hello staycool3_a,

                Thank you for the reply.

                I am able to get the test strategy to count the trades through our test IB account. Please see the attached screenshot.

                This is a paper account, so the possibility that SystemPerformance is not working for live IB accounts is still there.

                Please test the strategy that NinjaTrader_AlanP posted in your paper trading instance of IB Gateway. If you do see the SystemPerformance working there, then we will look into the behavior of the strategy further.

                I look forward to your reply.
                Attached Files
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_ChrisL View Post
                  Hello staycool3_a,

                  Thank you for the reply.

                  I am able to get the test strategy to count the trades through our test IB account. Please see the attached screenshot.

                  This is a paper account, so the possibility that SystemPerformance is not working for live IB accounts is still there.

                  Please test the strategy that NinjaTrader_AlanP posted in your paper trading instance of IB Gateway. If you do see the SystemPerformance working there, then we will look into the behavior of the strategy further.

                  I look forward to your reply.
                  can you confirm that you're seeing the correct trade count when you are adding and enabling the strategy with chart AND if you add and enable the chart via strategy tab? Yesterday I did notice that when I add the sim01 account via chart, the count is correct, when i add it via strategy tab, it's 50/50 (works sometimes and then sometimes it does not..).

                  Comment


                    #10
                    Hello staycool3_a,

                    Thanks for the reply.

                    I have confirmed that running an instance of the strategy on both the chart and from the Control Center will produce correct results from the SystemPerformace class.

                    Please let me know if you do not see the same results.
                    Chris L.NinjaTrader Customer Service

                    Comment


                      #11
                      Chris, I did what you asked.

                      Here are the findings;

                      **********************************
                      IB GATEWAY CONNECTION
                      **********************************
                      a) enable strategy via chart; trade.count works correctly
                      b) enable strategy via strategy tab; trade count does not work. it stays at zero no matter how many trades have been opened and closed

                      *above behavior is consistent with regardless of account type. even the sim101 account has the same behavior.

                      **********************************
                      IB TWS platform
                      **********************************
                      a) enable strategy via chart; trade count works correctly
                      b) enable strategy via strategy tab; trade count does not work. it stays at zero no matter how many trades have been opened and closed

                      **********************************
                      SIMULATED DATA FEED
                      **********************************

                      a) enable strategy via chart; trade count works correctly
                      b) enable strategy via strategy tab; trade count does not work. it stays at zero no how many trades have been opened and closed

                      *********************************
                      ADDITIONAL CHECK
                      *********************************
                      SystemPerformance.AllTrades.TradesPerformance.Perc ent.CumProfit
                      I checked the above for all of the connections above; this seems to work via chart and strategy tab regardless of connection and account type.

                      CONCLUSION: Looks like trade.count does not work when added via strategy tab. I did check one other statistic.

                      Can you please confirm this behavior on your end as well? Please let me know what I can do to resolve this issue as being able to keep a track of my trades is extremely important. Additionally, can you check other trade statistics/performance variables to see if they work?

                      Comment


                        #12
                        Hello,

                        This post is to confirm that SystemPerformance.AllTrades.Count is not working for strategies that are applied through the Strategies tab of the Control Center. It will work if the strategy is applied through a chart. This issue has been reported and will be fixed in a future update.
                        Chris L.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by staycool3_a View Post

                          CONCLUSION: Looks like trade.count does not work when added via strategy tab. I did check one other statistic.
                          Nice detective work.

                          Comment


                            #14
                            Hello All,

                            This can be solved by setting IncludeTradeHistoryInBacktest = true; This happens when a strategy is applied through the strategies tab, it will not store historical backtest information like on a chart. The historical backtest is still performed to calculate the strategies position.

                            Please let me know if I can assist further.
                            Chris L.NinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by NinjaTrader_ChrisL View Post
                              Hello All,

                              This can be solved by setting IncludeTradeHistoryInBacktest = true; This happens when a strategy is applied through the strategies tab, it will not store historical backtest information like on a chart. The historical backtest is still performed to calculate the strategies position.

                              Please let me know if I can assist further.
                              Thanks. I tested this setting in replay and it seems to count the trades correctly. Do you know if this would continue to count trades in real-time trading? I'd rather stick to chart for live trading unless you can confirm this. Seems counter intuitive to turn on IncludeTradeHistoryInBacktest during live trading b/c I don't know what else may change in my strategy by having this option ON.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by DJ888, Yesterday, 06:09 PM
                              2 responses
                              9 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by jeronymite, 04-12-2024, 04:26 PM
                              3 responses
                              40 views
                              0 likes
                              Last Post jeronymite  
                              Started by bill2023, Today, 08:51 AM
                              2 responses
                              16 views
                              0 likes
                              Last Post bill2023  
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              167 responses
                              2,260 views
                              0 likes
                              Last Post jeronymite  
                              Started by warreng86, 11-10-2020, 02:04 PM
                              7 responses
                              1,362 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Working...
                              X