Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to get Trade object

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

    How to get Trade object

    The help guides only tell how to get Trade's from the SystemPerformance class.

    Are there any other possibilities?

    For example I would like to get a Trade in the OnExecutionUpdate method from the given Execution or Order when the Exit has been filled.

    I guess I could just call this to get the last trade...
    Code:
    SystemPerformance.AllTrades[SystemPerformance.AllTrades.TradesCount-1];
    ...and check if the Exit Execution is the same object than the execution given from the OnExecutionUpdate.
    But what if they are not the same? Then I would need to search AllTrades for my execution and this feels laborious.
    Or am I wrong?

    #2
    Hello Bobin,

    Thank you for your post.

    Are you simply wanting to see if the last trade was profitable or not and submit further trades based on that? You can access the strategy's TradeCollection, get the last trade, and see if it was profitable or not. Here's an example from our help guide showing how to determine if the last trade was profitable or not - in this example the strategy will stop after three losing trades until the next session:

    https://ninjatrader.com/support/help...after_cons.htm

    Trades are formed by the platform by pairing executions together. You also could consider doing pairing executions together on your own within OnExecutionUpdate to make a Trade object.

    An active position does not get added to TradeCollection until the position is exited.

    Please let us know if we may be of further assistance to you.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    65 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    139 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    75 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