Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Performance Instance

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

    Performance Instance

    I am trying to check the loss amount once my stoploss is hit, but each time I check the value of the last trade in my OnOrderUpdate() it shows as a positive value and just so happens to be the value of the last winning trade. Here is what I am doing.

    Code:
    [FONT=Calibri][SIZE=3]OnOrderUpdate(IOrder order)[/SIZE][/FONT]
    [FONT=Calibri][SIZE=3]{[/SIZE][/FONT]
    [SIZE=3][FONT=Calibri]           // after verifying this is the order I think it is…[/FONT][/SIZE]
    [COLOR=blue][FONT=Courier New]   if[/FONT][/COLOR][COLOR=black][FONT=Courier New](order.OrderState == OrderState.Filled)[/FONT][/COLOR]
    [COLOR=black][FONT=Courier New]   {[/FONT][/COLOR]
    [COLOR=black][FONT=Courier New]       Trade lastTrade  = Performance.AllTrades[[/FONT][/COLOR][COLOR=purple][FONT=Courier New]0[/FONT][/COLOR][COLOR=black][FONT=Courier New]]; [/FONT][/COLOR]
    [COLOR=black][FONT=Courier New]       tradePL += lastTrade.ProfitCurrency * lastTrade.Quantity;  [/FONT][/COLOR]
    [COLOR=black][FONT=Courier New]   }[/FONT][/COLOR]
    [COLOR=black][FONT=Courier New]}[/FONT][/COLOR]
    This is always a positive number, and like I mentioned, it’s the value of the trade prior to the one I am working with. Also, the docs indicate a Performance.LosingTrades collection, but it looks like there is no such collection.

    When the OnOrderUpdate() message fires, I would assume the collection would already know about the trade that just caused the OnOrderUpdate() message. Is this correct?
    I am just trying to keep a running total of my winners and lossers - both realtime and historic. I've simplified the code above for clarity - much more is happening after the P/L for the trade is calculated.

    Thanks,

    -Scott

    #2
    I think I see my problem now. I need to use

    Performance.AllTrades.LosingTrades[
    0] to get the last losser.

    Thanks,

    -Scott

    Comment


      #3
      Glad you figured it out.
      Josh P.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      601 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      347 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      559 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      558 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X