Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to get last trade profit?

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

    how to get last trade profit?

    Its possible to get the last trade profit from OnExecutionUpdate when an execution was profit target or stoploss?

    im looking the input parameters Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time, but does not find something to get the value

    Thank you

    #2
    Hello arbeydario,

    wyou could do it under position update.




    region OnPositionUpdate
    protected override void OnPositionUpdate(Position position, double averagePrice, int quantity, MarketPosition marketPosition)
    {
    if (Position.MarketPosition == MarketPosition.Flat && SystemPerformance.AllTrades.Count > 0)
    {
    // when a position is closed, add the last trade's Profit to the currentPnL
    TradingCurrentDayPnL += SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitCurrency;

    // print to output window if the daily limit is hit
    if (TradingCurrentDayPnL <= -TradingLimitLossValue && TradingLimitLossEn)
    {
    Print("daily Loss limit hit, no new orders" + Time[0].ToString());
    }

    // print to output window if the daily limit is hit
    if (TradingCurrentDayPnL > TradingLimitProfitValue && TradingLimitProfitEn)
    {
    Print("daily Target limit hit, no new orders" + Time[0].ToString());
    }
    }
    }
    #endregion​



    And remember to reset on session start or build in a timer.

    if (Bars.IsFirstBarOfSession)
    {
    TradingCurrentDayPnL = 0;
    }​
    Donto
    NinjaTrader Ecosystem Vendor - otrading.dk

    Comment


      #3
      Hello,

      Thank you for your post.

      You could use the SystemPerformance.AllTrades TradeCollection to get the last trade and then use ProfitCurrency to get the profit of the last trade quoted in currency.

      See the help guide documentation below for more information and sample code.

      TradeCollection: https://ninjatrader.com/support/help...collection.htm
      Trade: https://ninjatrader.com/support/help...html?trade.htm

      Please let us know if you have any further questions. ​

      Comment


        #4
        Thank you donto and NinjaTrader_Gaby it works perfectly

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        110 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        59 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        37 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        41 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        78 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X