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

Strategy in Market Replay mode slows to real time only when position opened

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

    Strategy in Market Replay mode slows to real time only when position opened

    I am having an issue with a custom strategy that I am testing that when tested in market replay model slows down to real time as soon as a position is opened. I can set it a 500x speed and it will play back at this speed properly but as soon as the strategy opens a position, the playback speed slows down to near real time.

    Any idea as to why this might be happening?
    Jdmtrader
    NinjaTrader Ecosystem Vendor - JDM Indicators

    #2
    Hello Jdmtrader,

    Thank you for your post.

    So I may accurately assist you, please answer all of the following questions:
    • What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 8.?.?.?)
    • What instrument symbol (and expiry if applicable) have you selected? For example, ES 03-22, AAPL, EURUSD, etc.
    • What interval is selected? For example, 5 minute, 1 day, 2000 volume, 4 Renko, etc.
    • Do you receive an error on the screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?
    • Does this only happen when testing a NinjaScript strategy or are you able to reproduce when opening a position manually during playback?
    • Does the playback controller still show 500x speed or does it show a slower speed multiplier?
    I look forward to your reply.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      I am using NinjaTrader 8 version 8.0.28.0

      ES 09-23, 5 MIN. I dont receive any error. The trade is opened properly, its just that market replay slows down to near real time. No errors in log.

      It only happens when a strategy opens a position. If I open a position manually, it does not cause this to happen. It still shows 500x, even though the playback speed is showing seconds moving at real time or near real time.
      Jdmtrader
      NinjaTrader Ecosystem Vendor - JDM Indicators

      Comment


        #4
        Hello Jdmtrader,

        Thank you for your reply.

        It sounds like this may be related to a performance impact. Please try the following to test this in a blank workspace and only open a chart for the instrument you are running the strategy on:
        • Shut down NinjaTrader
        • Navigate to the Documents\NinjaTrader 8\db\replay folder
          • Temporarily move all files/folders except for the instrument and date(s) you are testing in playback to a new folder on the desktop
        • Launch NinjaTrader
        • Go to Control Center > Workspaces > New
          • Name the new workspace
        • Go to Control Center > Workspaces and close any workspaces that are still open other than the new workspace you just created
        • Connect to the playback connection
        • Select Control Center > New > Chart and set up a chart for the instrument you are testing on
        • Run the strategy and take note of the replay speed when a position is opened
        To get back to your previous setup, you may open your previous workspace(s) and even delete the newly created one if desired from the Workspaces menu. You may also shut down NinjaTrader and move the replay files from the desktop back into your Documents\NinjaTrader 8\db\replay folder.

        If you are still able to reproduce the apparent slowdown in playback, please provide the strategy being used as well as the steps to reproduce the behavior so I may test on my end.

        I appreciate your patience and look forward to hearing the results.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          I have resolved the issue related to the performance impact.

          However, I am having an issue related to an indicator that must run on onbarclose that is added into a strategy. I need the logic in OnBarUpdate in the strategy to run oneachtick, but the indicator added in the strategy using AddChartIndicator(IndicatorX) within State == State.DataLoaded to only update onbarclose.

          Correct me if I am wrong, but if the Calculate setting is OnBarClose (Calculate.OnBarClose), I won't be able to get tick-level granularity inside the OnBarUpdate() method. This is because with Calculate.OnBarClose, OnBarUpdate() is only called once per bar - at the close of the bar. Is it possible to have the strategy default to onbarclose but allow logic within the onbarupdate to calculate oneachtick?

          The intent of this is because the indicator being added in the strategy can't have anything updated that it draws until each bar closes, otherwise, the drawn object may be presented prematurely and incorrectly because its calculating oneachtick vs onbarupdate.

          My solution is to update my indicator so within the onbarupdate, I force it by adding after onBarUpdate

          if (!IsFirstTickOfBar) return;


          This would ensure the indicator's calculations are effectively performed once per bar (i.e., on bar close), even though the strategy's calculation mode is set to Calculate.OnEachTick. While the calculation mode of the indicator set in its defaults can't stop the strategy from calling the indicator's OnBarUpdate() method on each tick, checking IsFirstTickOfBar can stop the indicator from doing any meaningful calculations until the bar closes.

          My workaround would make the indicator behave as if it's operating on bar close, even though it technically gets called on each tick when it's added to a strategy that calculates on each tick.

          Is this the correct way to do it?

          Last edited by Jdmtrader; 07-05-2023, 07:20 PM.
          Jdmtrader
          NinjaTrader Ecosystem Vendor - JDM Indicators

          Comment


            #6
            Hello Jdmtrader,

            Thank you for your reply.

            Glad to hear you got the performance impact resolved. When it comes to a host script calculating on each tick and a hosted script, such as your indicator in this case, calculating on bar close, you are correct. You could use IsFirstTickOfBar in your logic to ensure that the indicator calculations are only processed once per bar. You could do it either as if (!IsFirstTickOfBar) return; followed by your indicator logic, or you could create a block of code within the condition if (IsFirstTickOfBar) and include your indicator logic within the actions of that condition. We have a reference sample that demonstrates how to separate logic to calculate on bar close or on each tick that may be found in the help guide here:


            Please feel free to reach out with any additional questions or concerns.
            Emily C.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Segwin, 05-07-2018, 02:15 PM
            14 responses
            1,789 views
            0 likes
            Last Post aligator  
            Started by Jimmyk, 01-26-2018, 05:19 AM
            6 responses
            837 views
            0 likes
            Last Post emuns
            by emuns
             
            Started by jxs_xrj, 01-12-2020, 09:49 AM
            6 responses
            3,293 views
            1 like
            Last Post jgualdronc  
            Started by Touch-Ups, Today, 10:36 AM
            0 responses
            13 views
            0 likes
            Last Post Touch-Ups  
            Started by geddyisodin, 04-25-2024, 05:20 AM
            11 responses
            63 views
            0 likes
            Last Post halgo_boulder  
            Working...
            X