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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      62 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      33 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      44 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      58 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      47 views
      0 likes
      Last Post CarlTrading  
      Working...
      X