Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Winning Trades Count differs in live trading vs backtesting

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

    Winning Trades Count differs in live trading vs backtesting

    My NT8 strategy has a parameter named "MaxWinners" to stop after X number of winning trades per trading session/day.

    Also, the strategy uses "NumContracts" to set the default number of contracts to trade.

    Here is an example:

    Code:
    if (Bars.IsFirstBarOfSession)
    {
    PriorWinningTrades = SystemPerformance.AllTrades.WinningTrades.Count;
    }
    
    CurrentWins = SystemPerformance.AllTrades.WinningTrades.Count - PriorWinningTrades;
    
    // Stop trading if MaxWinners reached
                if (CurrentWins >= MaxWinners)
                {
                    Print(Time[0] + " Trading Stopped... Max Winners Reached: " + CurrentWins);
                    return;
                }​
    
    // Entry logic
                if (Close[0] < Close[1])
                        {
                            EnterShortLimit(NumContracts, Close[0], @"Short");
                        }​



    In backtesting and optimization, everything works as intended and can be verified in the NinjaScript Output window. For example, when NumContracts is set to "4" and MaxWinners is set to "2" and the strategy executes two separate winning trades of 4 contracts each, the strategy will not place any more trades, and outputs:

    "4/12/2023 2:29:10 PM Trading Stopped... Max Winners Reached: 2"

    However, in LIVE trading using the same parameters, one winning trade made with 4 contracts sets "CurrentWins" to 4, instead of 1 like in backtesting. Live excution interprets one 4 contract winning trade as 4 separate winning trades instead of a single winning trade, which is my intention. This messes up my strategy in live trading since it will stop trading after one winning trade since CurrentWins=4 is greater than MaxWinners=2. Here is the output in LIVE trading after one single winning trade of 4 contracts:

    "7/17/2023 11:35:30 AM Trading Stopped... Max Winners Reached: 4"

    What can I do to have "CurrentWins" behave the same in live trading and backtesting?


    EDIT: I have run this through Market Replay and discovered that sometimes a single trade of 4 contracts will result in a different number of trades, such as 2 contracts + 2 contracts, 3 contacts + 1 contract, etc.
    Last edited by fredb987; 04-17-2023, 01:41 PM.

    #2
    Hi fredb987, thanks for posting. Have you tried implementing intrabar granularity for better fill estimation in the backtest? We have a guide on what intrabar granularity is and how to use it in your script and an example here:

    https://ninjatrader.com/support/foru...-backtest-live


    Kind regards,

    -ChrisL​

    Comment


      #3
      Thanks for the reply, Chris. I can try what you're suggesting, but I'm not sure it will help. I've decided to go a different route that will achieve the same results using CumProfit instead.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      54 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      72 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X