Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Having trouble getting "last traded entry price"

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

    Having trouble getting "last traded entry price"

    Hi NT,

    I am trying to get the right code line for the entry price of the previous trade, and the trade before that, etc. I am looking for something like the below, can you please help? Thank you!

    SystemPerformance.AllTrades[SystemPerformance.AllTrades.Price - 1]

    #2
    Hello Austiner87,

    You can find an example of getting the last trade here: https://ninjatrader.com/support/help...collection.htm

    To get other instances you would subtract 1 or more from the overall trade count as the index you are using.

    You can see the properties each Trade has here: https://ninjatrader.com/support/help.../nt8/trade.htm

    To get its entry price you need to use its Entry execution property to get the order object, the properties for executions can be found here: https://ninjatrader.com/support/help.../execution.htm

    And for orders here: https://ninjatrader.com/support/help.../nt8/order.htm

    Code:
    lastTrade.Entry.Order.AverageFillPrice

    Comment


      #3
      I think I am getting closer, I entered the <lastTrade> variable in your suggested code line with code <SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1]> and then used the rest of the suggested code line <.Entry.Order.AverageFillPrice>. I've highlighted these sections in the code block below. I am simply trying to create a limit order exit when a red bar appears and it is above the fill price of the last trade + 2 points. I am getting the error when I turn the strategy on: "You are accessing an index with a value that is invalid because it is out of range".

      Just need a bit of guidance to complete, I think I just need some correction to the highlighted section in the first snapshot, please
      Attached Files

      Comment


        #4
        Hello Austiner87,

        That condition will only be able to be used once you have at least one trade. You will need to surround that condition with this:

        Code:
        if (SystemPerformance.AllTrades.Count > 1)
        {​
        
        }
        In addition to that you need to make a second exit condition that does not use the trade performance so you can get a first trade. The easiest way is to make an else :

        Code:
        if (SystemPerformance.AllTrades.Count > 1)
        {​
           // the conditions you have in the image
        } else {
           // the conditions you have in the image except for the SystemPerformance part
        }
        ​Regarding adding 2 points, what you have now adds just 2, if the price was 100 it would be 102. You can very easily use Ticks in calculations, you could figure out how many ticks are within the number of points you wanted to use and then use this instead: yourValue + (2 * TickSize) which would be the value plus 2 ticks worth of price.

        Comment


          #5
          I promise i am trying a lot of things to resolve this, but when I do the IF and ELSE statements above, I get an error that about an unexpected " character
          Attached Files

          Comment


            #6
            Hello Austiner87,

            If you copied and pasted that from the forum that may have included padding characters, try doing the following:
            1. Select line 126
            2. Backspace all the way until the end of the if condition closing parenthesis on line 124
            3. Press enter to go to the next line and type {

            Does that resolve the error?

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            59 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            134 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            74 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            45 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            50 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X