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 rocketman7, Today, 01:00 AM
              0 responses
              1 view
              0 likes
              Last Post rocketman7  
              Started by wzgy0920, 04-20-2024, 06:09 PM
              2 responses
              27 views
              0 likes
              Last Post wzgy0920  
              Started by wzgy0920, 02-22-2024, 01:11 AM
              5 responses
              32 views
              0 likes
              Last Post wzgy0920  
              Started by wzgy0920, 04-23-2024, 09:53 PM
              2 responses
              74 views
              0 likes
              Last Post wzgy0920  
              Started by Kensonprib, 04-28-2021, 10:11 AM
              5 responses
              193 views
              0 likes
              Last Post Hasadafa  
              Working...
              X