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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    88 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    135 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    69 views
    0 likes
    Last Post PaulMohn  
    Working...
    X