Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error Using - SystemPerformance.AllTrades.Count - 1

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

    Error Using - SystemPerformance.AllTrades.Count - 1

    When running my strategy with live data I am getting an error after an order closes that the code is trying to access an index with an invalid range at the OnOrderUpdate.

    This is the code within OnOrderUpdate
    Code:
    if (order.Name == "StopExitLongFloor3b1" && orderState == OrderState.Filled || order.Name == "ExitProfitLongEntryFloor3b1" && orderState == OrderState.Filled
    || order.Name == "StopExitLongFloor3b1a" && orderState == OrderState.Filled || order.Name == "StopExitLongFloor3b1b" && orderState == OrderState.Filled
    )
    {
    Floor3bActive = false;
    LongFloor3bEntry = null;
    LongFloor3bEntryActive = false;
    stopOrderLongEntryFloor3b1a = null;
    stopOrderLongBreakOutFloor3b = null;
    stopOrderLongEntryFloor3b1 = null;
    entryLongFloor3b1 = null;
    Floor3bLossCount += SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitCurrency;
    }
    This is a MTF strategy.

    I read here that there was a problem with the AllTrades.Count when apply the strategy from the strategy tab. I am doing the same. Does this issue still exist?
    https://ninjatrader.com/support/foru...h-live-trading

    Is there a better way to pull last trades profit/loss?

    Thanks
    Last edited by mlprice12; 07-27-2021, 02:50 PM.

    #2
    Hello mlprice12,

    The SystemPerformance is updated after the position update.

    If this is moved to OnPositionUpdate() and you first confirm that SystemPerformance.AllTrades.Count is greater than 1, and then print SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitCurrency is there an indexing error?

    When adding a strategy directly to the Strategies tab of the Control Center instead of to a chart, set IncludeTradeHistoryInBacktest to true.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the response Chelsea,

      I have 4 separate entries so I need to distinguish the order name to make sure I can separate trade performance for each order name. ie lossCount1, lossCount2, lossCount3, and lossCount4.
      Would this still be possible in OnPositionUpdate? My understanding is I wouldn't be able to distinguish from which entry the position update is referencing.

      Now that I enabled the strategy from the chart the TradeCount is printing correctly.
      I also moved the code logic to OnExecutionUpdate. This seems to be working.

      Comment


        #4
        Hello mlprice12,

        Yes, each trade in the performance collection will have an Entry and Exit.

        if (SystemPerformance.AllTrades.Count > 0)
        Print(SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].Entry.Name);


        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        45 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        21 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        31 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        50 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        42 views
        0 likes
        Last Post CarlTrading  
        Working...
        X