Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    Kate W.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by usazencort, Today, 01:16 AM
    0 responses
    1 view
    0 likes
    Last Post usazencort  
    Started by kaywai, 09-01-2023, 08:44 PM
    5 responses
    603 views
    0 likes
    Last Post NinjaTrader_Jason  
    Started by xiinteractive, 04-09-2024, 08:08 AM
    6 responses
    22 views
    0 likes
    Last Post xiinteractive  
    Started by Pattontje, Yesterday, 02:10 PM
    2 responses
    21 views
    0 likes
    Last Post Pattontje  
    Started by flybuzz, 04-21-2024, 04:07 PM
    17 responses
    230 views
    0 likes
    Last Post TradingLoss  
    Working...
    X