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

Time[0] vs. Open[0] and IsFirstBarOfSession confusion

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

    Time[0] vs. Open[0] and IsFirstBarOfSession confusion

    I'm really confused about this situation.

    I have a 3k volume chart on the ES and add a Day period DataSeries to it.

    I then add this code to OnBarUpdate:

    Code:
    if (State == State.Historical){
    	if (Bars.IsFirstBarOfSession && BarsInProgress == 0){
    		Print("BarsInProgress 0 date is: " + ToDay(Time[0]) + " With an Open[0] of: " + Open[0]);
    	}
    	if (BarsInProgress == 1){
    		Print("BarsInProgress 1 date is: " + ToDay(Time[0]) + " With an Open[0] of: " + Open[0]);
    	}
    }
    and compare the printed output to a separate daily chart and find that both DataSeries have the same Open[0] but different dates for ToDay(Time[0]).

    AND! They don't match up with the Open on that separate daily chart .

    Look at the attached picture and compare the Open on 8/17/2017, which is 2466.75 in the DataBox, to what the Output prints:

    BarsInProgress 1 date is: 20170817 With an Open[0] of: 2466.75
    BarsInProgress 0 date is: 20170817 With an Open[0] of: 2426.75

    Both charts are set to use instrument settings for the trading hours / session and the Instrument is set to CME US Index Futures ETH.

    Can you please explain why the above happens?
    Are the daily bars not using the same session info as the other data series?

    EDIT:
    I went ahead and changed the session to regular trading hours (RTH) and the data still doesn't match as shown from this output:

    BarsInProgress 0 date is: 20170817 With an Open[0] of: 2460.5
    BarsInProgress 1 date is: 20170817 With an Open[0] of: 2466.75
    BarsInProgress 0 date is: 20170818 With an Open[0] of: 2426.5
    BarsInProgress 1 date is: 20170818 With an Open[0] of: 2426.75
    BarsInProgress 0 date is: 20170821 With an Open[0] of: 2424.25
    BarsInProgress 1 date is: 20170821 With an Open[0] of: 2428.75
    BarsInProgress 0 date is: 20170822 With an Open[0] of: 2433.25
    BarsInProgress 1 date is: 20170822 With an Open[0] of: 2428
    BarsInProgress 0 date is: 20170823 With an Open[0] of: 2440.5
    BarsInProgress 1 date is: 20170823 With an Open[0] of: 2453

    I'm trying to use the daily bars as the main generator of data regarding the daily open, high, low, close but I'm getting inconsistent results when trying to reconcile that data with the data from other volume-based data series.

    Shouldn't the first bar's open match the daily bar's open always? At least have the same date?
    Attached Files
    Last edited by hillborne; 08-31-2017, 05:17 AM. Reason: Found new info

    #2
    Hi hillborne

    What its your code in State.Configure and in function AddDataSeries(BarsPeriodType.Day, 1); ?

    Comment


      #3
      Hi Alvarheras,

      That is to add another data series that is based off of daily data.
      Here is the reference for it: http://ninjatrader.com/support/helpG...dataseries.htm

      That allows me to access and do calculations based on daily opens, highs, lows, closes.

      Comment


        #4
        Hii

        So you dont specific "BarsPeriodType periodType" ?

        Comment


          #5
          If you look at the link at the very bottom example, you can see that all you need to write is: AddDataSeries(BarsPeriodType.Day, 1);

          Comment


            #6
            Hello,

            If instead of a daily data series you add,

            AddDataSeries(BarsPeriodType.Minute, 1440);

            Do the prints match as you'd expect?

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

            Comment


              #7
              Hi Alan,

              Yes, here is the result:
              BarsInProgress 0 date is: 20170817 With an Open[0] of: 2460.5
              BarsInProgress 1 date is: 20170817 With an Open[0] of: 2460.5
              BarsInProgress 0 date is: 20170818 With an Open[0] of: 2426.5
              BarsInProgress 1 date is: 20170818 With an Open[0] of: 2426.5
              BarsInProgress 0 date is: 20170821 With an Open[0] of: 2424.25
              BarsInProgress 1 date is: 20170821 With an Open[0] of: 2424.25

              However, wouldn't this mean I have to process 1440 bars of information to find the OHLC for each day?

              What I'm doing is this:
              1. I have several volume-based data series running and as soon as the first bar of a new session completes for one of them, I record its Open.
              2. I add and subtract a value to that open (100 points) to get a HighRange and LowRange.
              3. I search for daily bars in the last 90 days that intersect with the High/LowRange.

              I've coded all of the above and it works except now I realize that it's being thrown off by doing calculations based on the assumption that a Daily bar's Open[0] equals the first bar of a session on a volume chart for the same date.

              The more processing done on the first bar of the session, the longer the strategy has to wait before entering a trade. That's why I want to work with a daily bar's 4 values.

              Working with the ETH session seems to compound the problem. Is the ToDay(Time[0]) of a daily bar always going to be 1 day behind?


              EDIT:
              I may have a solution but I don't know enough to understand if there's any downsides:

              Instead of working with mixed period types, I can have my 4 volume-based data series based on usable values (500, 2000, 5000, etc) and then add a 99,000,000 one that always captures the full ranges and times of the 4.

              I have to make sure to always break at end of day but is there any other downside?
              Last edited by hillborne; 08-31-2017, 08:18 PM. Reason: possible solution

              Comment


                #8
                Hello hillborne,

                I'm responding to you on behalf of my colleague Alan.

                Adding an additional data series of 1440 minutes would represent a whole day that is comprised of minute data, as far as processing this data in OnBarUpdate() goes, the bar still has the same number of OHLC values as the daily bar so processing the bar would be not different speed wise. I would not expect constructing this bar to have an impact on the OBU iteration.

                I've coded all of the above and it works except now I realize that it's being thrown off by doing calculations based on the assumption that a Daily bar's Open[0] equals the first bar of a session on a volume chart for the same date.
                If we are looking for the first bar of a session with the NinjaScript set to Calculate.OnBarClose, we will have to wait before the bar closes before we can get a value for that bar. When we reference Time[0], we are looking at the time that bar will close or has closed. Therefore, the daily series ToDay(Time[0]) would be the end of the session when the ToDay(Time[0]) of the volume series would be the close of the first bar of that series.

                Here is the output I get with a 3000 volume chart on the ES 09-17 and a daily series added. I am also printing ToDay(Time[1]) for the daily series so the time printed represents the day that the bar opened. I get the same results using a 1440 minute chart. If the Trading Hours templates are aligned for each data series, you should have matching opens.

                BarsInProgress 1 date is: 20170818 With an Open[0] of: 2428.75
                BarsInProgress 0 date is: 20170821 With an Open[0] of: 2428
                BarsInProgress 1 date is: 20170821 With an Open[0] of: 2428
                BarsInProgress 0 date is: 20170822 With an Open[0] of: 2453
                BarsInProgress 1 date is: 20170822 With an Open[0] of: 2453
                BarsInProgress 0 date is: 20170823 With an Open[0] of: 2440.25
                BarsInProgress 1 date is: 20170823 With an Open[0] of: 2440.25
                BarsInProgress 0 date is: 20170825 With an Open[0] of: 2442.25
                BarsInProgress 1 date is: 20170824 With an Open[0] of: 2442.5
                BarsInProgress 0 date is: 20170827 With an Open[0] of: 2442
                BarsInProgress 1 date is: 20170825 With an Open[0] of: 2442
                BarsInProgress 0 date is: 20170828 With an Open[0] of: 2434
                BarsInProgress 1 date is: 20170828 With an Open[0] of: 2434
                BarsInProgress 0 date is: 20170829 With an Open[0] of: 2446.5
                BarsInProgress 1 date is: 20170829 With an Open[0] of: 2446.5
                BarsInProgress 0 date is: 20170830 With an Open[0] of: 2455.25
                BarsInProgress 1 date is: 20170830 With an Open[0] of: 2455.25
                BarsInProgress 0 date is: 20170831 With an Open[0] of: 2470.25
                I would suggest to maintain a simple approach to reading the data in your strategy. If you are trying to get some information on a daily data series as it is developing, you may wish to utilize Calculate.OnEachTick and use IsFirstTickOfBar and a barsAgo reference to reference the previous bar to recreate Calculate.OnBarClose logic, and to use a barsAgo reference of 0 to get information on the iterating bar.

                This would allow you to display the close that just occurred as Close[1] and the Open of the current building bar as Open[0].

                IsFirstTickOfBar - https://ninjatrader.com/support/help...ttickofbar.htm

                Please let me know if I may be of further assistance.
                JimNinjaTrader Customer Service

                Comment


                  #9
                  Hi Jim,

                  Thank you for answering my questions. I appreciate it. I have a final few questions below.

                  I forgot to mention that I'm exporting the bar data to separate files based on the day/session. This allows me to do some graphs and analysis outside of NinjaTrader. I wanted one data series based on a 'day' because it would only have a single line of data for the OHLC instead of having to load and iterate through thousands of lines of minute data for each day.

                  I also might be working on non-RTH sessions and I read a post saying that NT's daily bars are built only from RTH data. Is this true? Can you have daily bars built on the ETH instead?

                  Finally, what do you think of my suggestion to use a 99,000,000 volume bar that breaks at EOD alongside my other volume based period values? I understand I couldn't access today's open on that data series because it hasn't completed but its close (from yesterday) would be much closer in value to today's open because they would be on the same session. This would reduce the gap in price between a daily bar's close (If it can only be based on RTH) and a volume bar's first bar of session when using ETH.

                  Thanks again!
                  Last edited by hillborne; 09-02-2017, 09:19 PM. Reason: Changed question

                  Comment


                    #10
                    Hello hillborne,

                    Thanks for writing back.

                    I also might be working on non-RTH sessions and I read a post saying that NT's daily bars are built only from RTH data. Is this true? Can you have daily bars built on the ETH instead?
                    NinjaTrader 8 builds daily bars based on ETH data. This was changed from NinjaTrader 7. Using a 1440 minute data series and a Trading Hours template will allow you to view the data in RTH hours.

                    Finally, what do you think of my suggestion to use a 99,000,000 volume bar that breaks at EOD alongside my other volume based period values? I understand I couldn't access today's open on that data series because it hasn't completed but its close (from yesterday) would be much closer in value to today's open because they would be on the same session. This would reduce the gap in price between a daily bar's close (If it can only be based on RTH) and a volume bar's first bar of session when using ETH.
                    I don't know the full implications of what you are trying to accomplish with your script, but it sounds like the main issue you are facing involves getting the Open on a daily data series before the daily bar closes. This could be accomplished using the IsFirstTickOfBar logic described in my last post to check the developing Daily Data Series with Calculate.OnEachTick and still maintaining similar overhead to Calculate.OnBarClose.

                    I would recommend this route as it would be a more reliable to get the Daily Open without too many design changes.

                    If you have any additional questions, please don't hesitate to ask.
                    JimNinjaTrader Customer Service

                    Comment


                      #11
                      Hi Jim,

                      Ah, that's great that the day bars are based off of ETH now.

                      I set everything to ETH but something seems off because I'm missing 8 hours of data each day when exporting.

                      For instance, when exporting from a 175 volume series, the first 3 lines and last 3 are:
                      (Date, Time, OHLC, Direction)
                      20170831,23,2457.5,2457.75,2457.5,2457.5,0
                      20170831,443,2457.5,2457.75,2457.25,2457.5,0
                      20170831,1456,2457.5,2457.75,2457.25,2457.5,0
                      ...
                      20170831,155922,2470.25,2470.5,2470.25,2470.5,1
                      20170831,155945,2470.5,2470.5,2470.25,2470.5,0
                      20170831,155959,2470.5,2470.5,2470.25,2470.5,0

                      Looking at the session template, the data seems to be obeying the end time of 4:00pm but not the start time of 5:00pm. It waits until 12:00am before exporting data again.

                      Is this because the session template has EOD check marked?

                      If yes, and I un-check it, exporting will happen through those 8 hours, right?

                      It seems like there's no overload for adding a volume-based data series with a different trading hours name. Is there one? I want to do:

                      AddDataSeries(BarsPeriodType.Volume, 175, "CME US Index Futures ETH", false)

                      Thanks!
                      Last edited by hillborne; 09-06-2017, 10:31 PM. Reason: additional question

                      Comment


                        #12
                        Hello hillborne,

                        Thanks for your reply.

                        This data you are referring to does not look like the same format of data that we use for exporting historical data. I am also confused on what you mean by exporting a 175 Volume series. If you are referring to writing the incoming data that processes in OnBarUpdate() to a file, then the data would follow the Trading Hours template applied to the data series and the output would change if you have Break at EOD enabled.

                        There is already an overload to apply a specific Trading Hours template to an additional data series. You could do something as follows:

                        Code:
                        AddDataSeries("ES 09-17", new BarsPeriod{ BarsPeriodType = BarsPeriodType.Volume, Value = 175 }, "CME US Index Futures ETH", false);
                        https://ninjatrader.com/support/help...dataseries.htm

                        I look forward to being of further help.
                        JimNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by lorem, Today, 09:18 AM
                        0 responses
                        2 views
                        0 likes
                        Last Post lorem
                        by lorem
                         
                        Started by hazylizard, Today, 08:38 AM
                        4 responses
                        11 views
                        0 likes
                        Last Post hazylizard  
                        Started by geddyisodin, Today, 05:20 AM
                        2 responses
                        20 views
                        0 likes
                        Last Post geddyisodin  
                        Started by Max238, Today, 01:28 AM
                        5 responses
                        47 views
                        0 likes
                        Last Post Max238
                        by Max238
                         
                        Started by giulyko00, Yesterday, 12:03 PM
                        3 responses
                        13 views
                        0 likes
                        Last Post NinjaTrader_BrandonH  
                        Working...
                        X