Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT8 - last trade info

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

    NT8 - last trade info

    lastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count -1];
    is referencing -2 trade not the last trade

    #2
    Where are you accessing this code?

    Are you in OnPositionUpdate? Or OnBarUpdate?

    Comment


      #3
      Originally posted by sledge View Post
      Where are you accessing this code?

      Are you in OnPositionUpdate? Or OnBarUpdate?
      OnBarUpdate

      Comment


        #4
        Hello astef,

        Thanks for your post.

        I will look into this and update when I have further information.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hello astef,

          I've tested some code an have not observed what you are reporting.

          Here is the code I tested with, please apply to your situation as a test.

          Code:
          		Print ("Number of trades: " +SystemPerformance.AllTrades.Count);
          		
          		for (int i = 0; i < SystemPerformance.AllTrades.Count; i++)
          		{
          			Trade firstTrade = SystemPerformance.AllTrades[i];
          			Print ("Trade: "+ i+"  Value: "+ firstTrade.ProfitCurrency);
          		}
          		
          		Trade last1Trade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count -1];
          		
          		Print ("last1: "+last1Trade.ProfitCurrency);
          		
          		Trade last2Trade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count -2];
          		
          		Print ("last2: "+last2Trade.ProfitCurrency);
          Here is a sample of the output:

          Trade: 184 Value: 550
          Trade: 185 Value: 30.0000000000068
          Trade: 186 Value: -69.9999999999932
          Trade: 187 Value: -160.000000000002
          Trade: 188 Value: -210.000000000002
          last1: -210.000000000002
          last2: -160.000000000002
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Hi
            Thank you very much.
            The reference to

            Trade last1Trade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count -1];

            works well in OnOrderUpdate but for me does not wok in OnBarUpdate
            in

            OnBarupdate:
            {...
            if (Criteria)
            EnterLong()

            lastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count -1]; - was not referencing last trade but a second last

            Note - I am running with Tickr Replay on historical data


            as the trade can be properly referenced in OnOrderUpdate, this is not an issue for me any more

            Comment


              #7
              Hello astef,

              Thanks for your reply.

              I am unable to replicate the issue.

              I have tried with historical data with Tick Replay in the strategy analyzer. I have tried with historical data without tick replay.

              In each case the [-1] points to the last trade and [-2] the trade before, etc.

              If you can create a small working sample that demonstrates the issue, along with the steps to recreate, I would be glad to review.
              Paul H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by jaybedreamin, Today, 05:56 PM
              0 responses
              3 views
              0 likes
              Last Post jaybedreamin  
              Started by DJ888, 04-16-2024, 06:09 PM
              6 responses
              18 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by Jon17, Today, 04:33 PM
              0 responses
              1 view
              0 likes
              Last Post Jon17
              by Jon17
               
              Started by Javierw.ok, Today, 04:12 PM
              0 responses
              6 views
              0 likes
              Last Post Javierw.ok  
              Started by timmbbo, Today, 08:59 AM
              2 responses
              10 views
              0 likes
              Last Post bltdavid  
              Working...
              X