Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unmanaged order system and SystemPerfromance.AllTrades.Count

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

    Unmanaged order system and SystemPerfromance.AllTrades.Count

    Hi,

    I've been working on a strategy that is proving to be extremely successful using an unmanaged order system. In order to determine which of the "triggers" that I have set that need to be satisfied to enter a trade are the best, I decided it would be a good idea to collect data. I understand NT8 allows you to export data internally, however, I'd like to have it export the trade data as soon as it successfully exits a trade (in other words, it satisfies the trade object requirement of an entry and exit) through the streamwriter. Through testing it seems that the unmanaged orders aren't counting towards a "trade" when using "SystemPerformance.AllTrades.Count" (it just continuously outputs "OnPositionUpdate: The strategy has taken 0 trades."). My question is do unmanaged orders have to have its own SystemPerformance coded into the base or should SystemPerformance.AllTrades.Count work with unamanged orders and perhaps there is something wrong with my code?

    Thank you,

    John

    #2
    Welcome to the forums!

    Originally posted by Ja3nyc View Post
    Do unmanaged orders have to have its own SystemPerformance coded into the base?
    No.

    Originally posted by Ja3nyc View Post
    Should SystemPerformance.AllTrades.Count work with unamanged orders?
    Yes.

    Originally posted by Ja3nyc View Post
    Is something wrong with my code?
    Probably.

    If by 'success' with your strategy, you mean
    your backtesting is showing profits, have you
    enabled IncludeTradeHistoryInBacktest?

    Last edited by bltdavid; 06-13-2022, 07:17 AM.

    Comment


      #3
      Hi David,

      Thank you for the welcome!

      So my current strategy utilizes multi-timeframe triggers, which from my testing is far too complex for NT backtesting to figure out, so it doesn’t take trades. However, when I run the strategy in current prices (what I term “forward” testing), it takes trades beautifully and catches 100 point trades on ES. From my thorough research on the forums, it seems there was an issue in the past with strategies and system performance, where it wouldn’t count trades in systemperformance when turning on a strategy through the strategy tab, but would when doing it through the chart. This occurred because of the “IncludeTradeHistoryInBacktest” value wasn’t enabled in the strategy through the strategy tab, but enabled when doing it on the chart. What I’m trying to figure out is how to log every single trade data (where a trade is a complete entry and exit), such as PnL, entry price, exit price, Marketposition, true and false values for each trigger condition, etc. to determine which trigger to eliminate because it isn’t as profitable as the others. I’m trying to figure out how to do this in real-time, not back testing, with streamwriter. Would the value, “IncludeTradeHistoryInBacktest” for real-time?

      Comment


        #4
        Hi John, thanks for posting.

        Our colleague made a good post here on why a backtest might have different results compared to a real time strategy here. This includes information on adding intrabar granularity if your strategy is calculating intrabar signals:
        Citizens of the NinjaTrader Community, A common question we hear from clients is 'why are results from backtest different from real-time or from market replay?'. Live orders are filled on an exchange with a trading partner on an agreed upon price based on market dynamics. Backtest orders are not using these market dynamics.


        The strategy analyzer/backtest system can handle multi time frame scripts. One way you can write your own trade data to a file is to generate a CSV file. I attached an example of how to do this.

        Kind regards,
        -ChrisL
        Attached Files

        Comment


          #5
          Hi ChrisL,

          Thank you so much for the refrerences, but the issue I'm having is as follows:
          Code:
          protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string comment)
          {
          base.OnOrderUpdate(order, limitPrice, stopPrice, quantity, filled, averageFillPrice, orderState, time, error, comment);
          bool atLeastOneTrade = SystemPerformance.RealTimeTrades.Count > 0;
          if(WriteEx && atLeastOneTrade)
          {
          Trade lastTrade = SystemPerformance.RealTimeTrades[SystemPerformance.RealTimeTrades.Count - 1];
          sw = File.AppendText(path);
          sw.WriteLine(String.Format("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}",
          lastTrade.TradeNumber, lastTrade.Entry.Instrument, lastTrade.Entry.Time, lastTrade.Exit.Time, lastTrade.Entry.Price, lastTrade.Exit.Price, lastTrade.ProfitCurrency, lastTrade.Quantity, lastTrade.Entry.MarketPosition, lastTrade.MaePoints, lastTrade.MfePoints));
          sw.Close();
          }
          }
          I use the unmanaged order submission in my strategy, but whenever I do:

          Code:
          Print(SystemPerformance.RealTimeTrades.Count);
          It always returns a value of zero even after the strategy takes a trade. My assumption is that the limit orders used for stop loss and take profit are not being considered as a completed trade. I could be wrong on that one.

          How would I be able to resolve this?

          Thank you,

          John

          Comment


            #6
            So I fixed the issue:

            It was this:

            Code:
            IncludeTradeHistoryInBacktest                = true;
            inside the (State==State.Configure).

            I also moved the large code block from OnOrderUpdate to OnExecutionUpdate.

            Thank you all for your help, very much appreciated!

            Best,

            John

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            70 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            143 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            76 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            47 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            51 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X