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

OnBarUpdate() and Multi-Timeframe behavior not as expected

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

    OnBarUpdate() and Multi-Timeframe behavior not as expected

    Hello, I have a 30-minute chart (with 1500 BARS of data loaded) running a custom indicator (below).

    The custom indicator loads a 1-minute time frame dataseries.

    I am needing to process data on every 1-minute bar in the OnBarUpdate() method. However, it seems that it only processes the added data series for a few days back and not all the data loaded within the chart.

    I've tried setting the "MaximumBarsLookBack", changing the "Calculate" to be each tick, etc without change.

    I am loading multiple weeks of data into the chart, but only a few days of 1-min data are processed.

    How do I allow OnBarUpdate() to be called for each 1-min bar (the entire time span of the chart) of the secondary dataseries? Do I need to add something to AddDataSeries()? Change a default setting of the chart/indicator?

    Thank you!

    PHP Code:
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Data;

    namespace 
    NinjaTrader.NinjaScript.Indicators
    {
        public class 
    ExampleMultiTimeFrameOnBarUpdate Indicator
        
    {
            protected 
    override void OnStateChange()
            {
                if (
    State == State.SetDefaults)
                {
                    
    Description = @"Perform a calculation on each 1-min bar, regardless of primary dataseries.";
                    
    Name "Test - Multi-timeframe OnBarUpdate()";
                    
    Calculate Calculate.OnEachTick;
                    
    IsOverlay true;                
                    
    DrawOnPricePanel    true;                
                    
    ScaleJustification NinjaTrader.Gui.Chart.ScaleJustification.Right;                
                    
    IsSuspendedWhileInactive true;
                    
    MaximumBarsLookBack MaximumBarsLookBack.Infinite;
                }
                else if (
    State == State.Configure)
                {
                    
    AddDataSeries(BarsPeriodType.Minute1);
                }
            }

            protected 
    override void OnBarUpdate()
            {
                
    //if (BarsInProgress == 1)
                    
    Print("BiP " BarsInProgress "       " Times[BarsInProgress][0]);
            }
            
            protected 
    override void OnRender(ChartControl chartControlChartScale chartScale)
            {
                
    base.OnRender(chartControlchartScale);
            }
        }

    Last edited by neoikon; 08-14-2017, 09:17 AM.

    #2
    Hello neoikon,

    I am not able to reproduce on my end, I'm pulling 1 minute data all the way to early June, see attached screen shots.

    Who is your data provider and what contract are you testing on?

    I look forward to your reply.
    Attached Files
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Thank you for the reply.

      I am using Kinetick data (the feed given to vendors, not EoD) on NQ ##-## (or NQ 09-17), 30-min chart, with 1500 BARS loaded. Trading hours is "<Use Instrument Settings>". No other indicators on the chart.

      I also tried creating a new workspace (closing all other workspaces) with this one chart and one indicator running. Same result.

      I've tried "reloading all historical data", restarting NT, resetting the Database, and repairing the database. All same result.

      This is the output I get:

      BiP 0 6/28/2017 2:30:00 PM
      BiP 0 6/28/2017 3:00:00 PM
      BiP 0 6/28/2017 3:30:00 PM
      BiP 0 6/28/2017 4:00:00 PM
      BiP 0 6/28/2017 5:30:00 PM
      BiP 0 6/28/2017 6:00:00 PM
      BiP 0 6/28/2017 6:30:00 PM
      BiP 0 6/28/2017 7:00:00 PM
      BiP 0 6/28/2017 7:30:00 PM
      BiP 0 6/28/2017 8:00:00 PM
      BiP 0 6/28/2017 8:30:00 PM
      BiP 0 6/28/2017 9:00:00 PM
      BiP 0 6/28/2017 9:30:00 PM
      BiP 0 6/28/2017 10:00:00 PM
      BiP 0 6/28/2017 10:30:00 PM
      BiP 0 6/28/2017 11:00:00 PM
      BiP 0 6/28/2017 11:30:00 PM
      BiP 0 6/29/2017 12:00:00 AM

      ... Etc, every 30-min until 8/11, then it starts behaving as expected, then BiP is 0 every 30min and BiP is 1 every minute

      BiP 0 8/11/2017 8:00:00 AM
      BiP 0 8/11/2017 8:30:00 AM
      BiP 0 8/11/2017 9:00:00 AM
      BiP 0 8/11/2017 9:30:00 AM
      BiP 1 8/11/2017 9:49:00 AM
      BiP 1 8/11/2017 9:50:00 AM
      BiP 1 8/11/2017 9:51:00 AM
      BiP 1 8/11/2017 9:52:00 AM
      BiP 1 8/11/2017 9:53:00 AM
      BiP 1 8/11/2017 9:54:00 AM
      BiP 1 8/11/2017 9:55:00 AM
      BiP 1 8/11/2017 9:56:00 AM
      BiP 1 8/11/2017 9:57:00 AM
      BiP 1 8/11/2017 9:58:00 AM
      BiP 1 8/11/2017 9:59:00 AM
      BiP 0 8/11/2017 10:00:00 AM
      BiP 1 8/11/2017 10:00:00 AM
      BiP 1 8/11/2017 10:01:00 AM
      BiP 1 8/11/2017 10:02:00 AM
      BiP 1 8/11/2017 10:03:00 AM
      BiP 1 8/11/2017 10:04:00 AM

      ... Etc...

      If I change my chart from a 30-min chart to a 1-minute chart, I can easily load 30+ days of data. But, when I switch back to 30-min, the indicator gives the same, incorrect output.

      I'm running NT 8.08 64-bit

      Is there something else I should try?
      Last edited by neoikon; 08-14-2017, 01:16 PM.

      Comment


        #4
        Hello neoikon,

        Rather than using 1500 Bars, could you change the data series to Days.

        Does that yield a different result?
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Set to Daily (1D):

          BiP 0 8/25/2014 4:00:00 PM
          BiP 0 8/26/2014 4:00:00 PM
          BiP 0 8/27/2014 4:00:00 PM
          BiP 0 8/28/2014 4:00:00 PM
          BiP 0 8/29/2014 4:00:00 PM
          BiP 0 9/2/2014 4:00:00 PM
          BiP 0 9/3/2014 4:00:00 PM
          BiP 0 9/4/2014 4:00:00 PM
          BiP 0 9/5/2014 4:00:00 PM
          BiP 0 9/8/2014 4:00:00 PM
          BiP 0 9/9/2014 4:00:00 PM
          BiP 0 9/10/2014 4:00:00 PM
          BiP 0 9/11/2014 4:00:00 PM
          BiP 0 9/12/2014 4:00:00 PM
          BiP 0 9/15/2014 4:00:00 PM
          BiP 0 9/16/2014 4:00:00 PM
          BiP 0 9/17/2014 4:00:00 PM

          ... until...

          BiP 0 8/10/2017 4:00:00 PM
          BiP 0 8/11/2017 4:00:00 PM
          BiP 1 8/14/2017 2:35:00 AM
          BiP 1 8/14/2017 2:36:00 AM
          BiP 1 8/14/2017 2:37:00 AM
          BiP 1 8/14/2017 2:38:00 AM
          BiP 1 8/14/2017 2:39:00 AM

          ... (750 times)

          Until it gets to real-time, then it gives.

          BiP 0 8/14/2017 4:00:00 PM
          BiP 1 8/14/2017 3:05:00 PM
          BiP 0 8/14/2017 4:00:00 PM
          BiP 1 8/14/2017 3:05:00 PM
          BiP 0 8/14/2017 4:00:00 PM
          BiP 1 8/14/2017 3:05:00 PM
          BiP 0 8/14/2017 4:00:00 PM
          BiP 1 8/14/2017 3:05:00 PM
          BiP 0 8/14/2017 4:00:00 PM

          One interesting thing to note is that it switches to BiP= 1 for 750 times before real-time hits. Meaning, it is only loading 750 bars of the second dataseries.

          As a test, I changed the 2nd dataseries to 5-min (from the original 1-min), and again, it processed exactly 750 bars before real-time bars.



          EDIT: I checked my "Daily" settings and it only had 750 bars loaded. I changed this to 1500 bars and the BiP behavior changed to 1500 bars as well!

          SO, if the main chart's dataseries has X number of bars loaded, then the 2nd data series will also only load X number of bars. Which leads to unexpected results, since 1500 30-min bars is different than 1500 1-min bars as far as the "beginning of the chart" is concerned. My fear is that there is no way to change this behavior.
          Last edited by neoikon; 08-14-2017, 02:52 PM.

          Comment


            #6
            Hello neoikon,

            Rather than using 1500 Bars, could you change the data series to Days.

            Does that yield a different result?
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              I was expecting a different result by changing it do Days, but it's the same result, unfortunately.

              Comment


                #8
                Hello neoikon,

                Thank you for writing in.

                Could you please send an email to platformsupport[at]ninjatrader[dot]com with Attn: Alan P in the Subject line. Also within the email please include a link to this thread, and attach the log and trace files for the day in subject which you can find in My Documents>NinjaTrader8>Log and My Documents>NinjaTrader8/Trace folders.

                I look forward to your email.
                Alan P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by trilliantrader, Today, 08:16 AM
                2 responses
                6 views
                0 likes
                Last Post trilliantrader  
                Started by samish18, Today, 08:31 AM
                1 response
                1 view
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by Creamers, 09-08-2023, 10:26 AM
                6 responses
                157 views
                0 likes
                Last Post JonyGurt  
                Started by funk10101, Today, 08:14 AM
                1 response
                2 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by bill2023, Yesterday, 08:51 AM
                3 responses
                22 views
                0 likes
                Last Post bltdavid  
                Working...
                X