Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Optimization Fitnesses

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

    Optimization Fitnesses

    From within the above, it is possible to find out how many of the trades were exited via limit orders vs market ?

    #2
    Hello spottysallrite,

    Thank you for your note.

    You may get this information from a specific trade object using an index value for the TradeCollection being accessed. For example, building on the following example from the help guide that accesses the first and last trade in the strategy, we can also print out the order type for the exit of those trades:

    Code:
      // Accesses the first/last trade in the strategy (oldest trade is at index 0)
      // and prints out the order type for the exit order
      if (SystemPerformance.AllTrades.Count > 1)
      {
          Trade lastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];
          Trade firstTrade = SystemPerformance.AllTrades[0];
    
          Print("The last trade exit order type was " + lastTrade.Exit.Order.OrderType);
          Print("The first trade exit order type was " + firstTrade.Exit.Order.OrderType);
      }​
    The following links are relevant:
    When considering Optimization Fitness scripts, you could calculate the number of market exits for example using the following logic in OnCalculatePerformanceValue():
    Code:
            protected override void OnCalculatePerformanceValue(StrategyBase strategy)
            {
                int marketExits = 0;
                if (strategy.SystemPerformance.AllTrades.Count > 1)
                {
                    for (int x = 0; x < strategy.SystemPerformance.AllTrades.Count; x++)
                    {
                        if (strategy.SystemPerformance.AllTrades[x].Exit.Order.OrderType == OrderType.Market)
                            marketExits++;
                    }
                    Value = marketExits;
                }
            }​
    You could do something similar for limit orders or even make a ratio of limit order exits vs. market order exits depending on your needs.

    Please let us know if we may be of further assistance.

    Comment


      #3
      Nice ! Thx much !

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      46 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      22 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      33 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