Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    JimNinjaTrader Customer Service

    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
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Waxavi, Today, 02:10 AM
        0 responses
        3 views
        0 likes
        Last Post Waxavi
        by Waxavi
         
        Started by TradeForge, Today, 02:09 AM
        0 responses
        9 views
        0 likes
        Last Post TradeForge  
        Started by Waxavi, Today, 02:00 AM
        0 responses
        2 views
        0 likes
        Last Post Waxavi
        by Waxavi
         
        Started by elirion, Today, 01:36 AM
        0 responses
        4 views
        0 likes
        Last Post elirion
        by elirion
         
        Started by gentlebenthebear, Today, 01:30 AM
        0 responses
        4 views
        0 likes
        Last Post gentlebenthebear  
        Working...
        X