Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Prevent Real-time Order While Backtesting

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

    Prevent Real-time Order While Backtesting

    As the post title says, I'm doing backtesting work on historical data. I'm connected to the Sim101 account, but every time I run the backtest I get the disembodied voice saying "Order Filled."

    Obviously this is intended behavior as we transition to real-time, but I just want to know how I can temporarily turn off real-time submission of orders while I'm backtesting.

    I tried a few things like requiring State == State.Historical before calling EnterLong, but that doesn't seem to make any difference.

    Thanks,

    #2
    Hello BarzTrading,

    Thanks for your post.

    Backtesting when added to a chart (historical data processing) will always be processed when the strategy is enabled, and when the strategy finishes processing that data it transitions to realtime data. These behaviors happen sequentially as the strategy state transitions from Historical to Realtime and this processing does not happen at the same time. Because of which, there would not be a way to "turn off real-time submission of orders while backtesting." Any order submissions that you hear would be realtime submissions from the strategy after historical processing has finished.

    If you are just interested in viewing backtest results before you have the strategy take realtime behaviors, I may recommend using the Strategy Analyzer as this will only perform the historical backtest.

    Please let me know if you have any additional questions.

    Comment


      #3
      I resolved this for my situation by setting the strategy to "Wait until Flat" and then preventing any entries on the final historical bar.

      I can change these settings when I'm ready to go live.

      Code:
             
              protected bool IsDataSeriesFinalHistoricalBarUpdate(int currentBarIndex, int dataSeriesIndex)
              {
                  if (_Script.State != State.Historical) { return false; }
                  if (dataSeriesIndex < 0 || dataSeriesIndex > _Script.BarsArray.Length - 1) { return false; }
      
                  if (_Script.Calculate == Calculate.OnBarClose)
                  {
                      return currentBarIndex == _Script.BarsArray[dataSeriesIndex].Count - 2;
                  }
                  else
                  {
                      return currentBarIndex == _Script.BarsArray[dataSeriesIndex].Count - 1;
                  }
              }

      Comment


        #4
        Hello BarzTrading,

        Just to note, using Wait Until Flat would mean that any position opened from processing historical data will need to be closed before the strategy is allowed to submit live orders. Preventing entries on the last historical bar may prevent entries being created on this bar where you would remain flat, but Wait Until Flat will still wait until the last position created from historical data gets closed regardless if that position gets created on that last historical bar or earlier.

        If it applies, you may also wish to consider disabling Realtime data processing to achieve your goal with:

        if (State == State.Realtime) return;


        More information on Start Behaviors can be found here - https://ninjatrader.com/support/help..._positions.htm

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        62 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        134 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        75 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        50 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X