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

Historical vs Realtime Implementation Issue

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

    Historical vs Realtime Implementation Issue

    I have 5 instruments, each with the same time interval. In OnBarUpddate - for each of their respective BarsInProgress, I simply collect information from each of their indicators.

    I have a 6th data series that analyzes the information that was collected from the first 5 data series OnBarUpdate, and might Enter/Exit againt the 5 data series, depending on my logic.

    This works GREAT in historical backtesting because the OnBarUpdate method gets called sequentially for each series. Everything works as expected. However, in Realtime - I get undesired results because the order is not guaranteed.

    Not sure how to work around this. I need a way to centrally execute trades based on information collected from a basket of Data Series. I tried making the 6th data series to wait until all information from the 5 were collected, using Thread.wait( ) but one of the series was never called, probably because the 6th series was called before it.

    Any ideas? Thanks in advance!

    -Sam

    #2
    Hello szayedoud,

    Welcome to the NinjaTrader support forums.

    Syncing like this can be difficult depending on the overall goal. Before we get too far into this question what data do you need to use from each series?

    If you need to use the price information you may be best off to not collect the data and just use the price series:

    Code:
    if(BarsInProgress == 6) // processing series or condition you referred to
    {
        double value = Closes[1][0] + Closes[2][0]; // reference the last closed value for each series
    }
    The same general concept can be applied to some indicators, if the indicator in question uses Input in its logic you can pass a series to it and then just use the indicators directly in your calculation logic.



    Another approach may be to collect last values and then use them in your processing logic:


    Code:
        private double lastValue0; 
    private double lastValue1; 
            protected override void OnBarUpdate()
            {
                if(BarsInProgress == 0)
                {
                    lastValue0= Close[0]; // or indicator/other value you needed
                }
                if(BarsInProgress == 1)
                {
                    lastValue1= Close[0]; // or indicator/other value you needed
                }
                else if(BarsInProgress == 6)
                {
                    double calculated = lastValue0 - lastValue1; // or indicator/other value you needed
                }
    
            }
    This just uses whatever was last set for the BarsInProgress, in terms of sync this only make sure a value is present similar to your waiting idea however if one series is fast moving and the other has no movement you may see one series update and the other lag behind. You may also need logic to make sure the variable has a value and has been set.

    Regarding the Wait you were trying, just to detail this further you cannot make a script wait. NinjaScript is event driven so you would not want to hold up the script processing for any reasons. An alternative path needs to be used here instead of waiting such as accumulating values or passing an input series to the indicator.



    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Jesse - many thanks for your quick feedback!

      To answer your first question, I have various indicator information from each data series. My code is very similar to your second code example, and YES, I am getting a lag (previous 30 min bar) on some series, exactly how you put it. I need current information from all the series - to analyze whether to take action. I am using 30 min bars, so I can’t afford waiting another 30 minutes. How about this: make the analysis/execution happen on a smaller increment of time series after 30 min bar (like 30 seconds or 1 min after). Eg. - at 1 min and 31 min mark of the hour? I have my own Container class that has all the indicator information - the Strategy holds an array of 5 Container object holding all the indicator info. So it will be conveniently available for a different time series.

      If I could process the bars in the same way historical works, that would solve the problem and ensure I get the most current information. This page says “ If your development requires ticks to process in the same sequence historically as well as in real-time, you will need to enable Tick Replay (utilizes more PC resources).” https://ninjatrader.com/support/help...nstruments.htm I don’t quite understand how this would work. Could this apply to my case?

      Comment


        #4
        Hello szayedoud,

        You could move calculation down to a smaller timeframe to update the value more frequently that is a commonly used tactic.

        If your configuration is similar to the second item I provided then whenever the secondary series has movement and updates it would update your variable. In turn your calculation could happen on the next 1 minute to detect that or see a change in the value.

        You wont be able to process in the same way as historical when working in realtime because the realtime market is unknown and brand new. Historical data can be processed in the same order as it was seen by using tick replay. You can read more about tick replay in the following page: https://ninjatrader.com/support/help...sub=tickreplay

        I look forward to being of further assistance.

        JesseNinjaTrader Customer Service

        Comment


          #5
          Ok, thanks a lot for your help Jesse. I will try making the executions on a smaller time frame and see how that works out for me!

          Ahh ok - i think i get what the purpose of TickReplay is - it's for using it in historical testing, where as by default Historical data is limited to OHLCV values, and not tick data. It would be useful for Strategies that built bars using ticks for example - and OHLCV data doesn't supply that info. Right?

          Thanks again!

          Comment


            #6
            Hello szayedoud,

            TickReplay is used for more granular processing and its OnMarketData. This allows the OnMarketData override to be called historically which allows some scripts which would otherwise only work in realtime to work historically. This is not necessarily better for a strategy because it does not add any extra accuracy for fills but this would help for items which use OnMarketData such as something that builds from ask or bid data. This can help create more realistic results with some items because it allows for processing each tick.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              that explanation clarifies a lot! Thank you.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by FrancisMorro, Today, 03:24 AM
              0 responses
              1 view
              0 likes
              Last Post FrancisMorro  
              Started by Segwin, 05-07-2018, 02:15 PM
              10 responses
              1,770 views
              0 likes
              Last Post Leafcutter  
              Started by Rapine Heihei, 04-23-2024, 07:51 PM
              2 responses
              31 views
              0 likes
              Last Post Max238
              by Max238
               
              Started by Shansen, 08-30-2019, 10:18 PM
              24 responses
              944 views
              0 likes
              Last Post spwizard  
              Started by Max238, Today, 01:28 AM
              0 responses
              11 views
              0 likes
              Last Post Max238
              by Max238
               
              Working...
              X