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

Historic flag incorrect

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

    Historic flag incorrect

    I have the following at the very start of my BarUpdate method:

    Code:
    protected override void OnBarUpdate()
            {
    			int startIndex = Historical ? 0 : 1;
    Further down in the same method I have the following:

    Code:
    	if (BarsInProgress == 0) {
    		if (CurrentBars[0] < 5) { return; }		 
    		Print(Times[1][0] + ": Start index: " + startIndex);
    This is the output I'm getting in LIVE tape:

    .......
    .......
    5/30/2013 9:24:15 AM: Start index: 0
    5/30/2013 9:24:15 AM: Start index: 0
    5/30/2013 9:24:15 AM: Start index: 0
    5/30/2013 9:24:15 AM: Start index: 0
    5/30/2013 9:24:15 AM: Start index: 0
    5/30/2013 9:24:15 AM: Start index: 0
    5/30/2013 9:24:15 AM: Start index: 0
    5/30/2013 9:24:15 AM: Start index: 0
    In live trading the output should be 1 - why is it printing 0 as it should for historic candles?

    FYI - BarsRequired is set to 0 and I'm loading 14 days of 60-min data.
    Last edited by molecool; 05-30-2013, 07:38 AM.

    #2
    Hello molecool,

    What period types are you applying this on?

    Also after the bar closes does your variable start to output 1?

    Happy to be of further assistance.
    Last edited by NinjaTrader_JC; 05-30-2013, 08:37 AM.
    JCNinjaTrader Customer Service

    Comment


      #3
      Originally posted by molecool View Post
      I have the following at the very start of my BarUpdate method:

      Code:
      protected override void OnBarUpdate()
              {
                  int startIndex = Historical ? 0 : 1;
      Further down in the same method I have the following:

      Code:
          if (BarsInProgress == 0) {
              if (CurrentBars[0] < 5) { return; }         
              Print(Times[1][0] + ": Start index: " + startIndex);
      This is the output I'm getting in LIVE tape:



      In live trading the output should be 1 - why is it printing 0 as it should for historic candles?

      FYI - BarsRequired is set to 0 and I'm loading 14 days of 60-min data.
      What is the secondary timeframe; what is the primary timeframe?

      Comment


        #4
        Primary timeframe is 60-minutes the secondary is single ticks.

        Comment


          #5
          Originally posted by molecool View Post
          Primary timeframe is 60-minutes the secondary is single ticks.
          Try moving the Historical test into the BarsInProgress filter.

          I am theorizing that as it is outside the filter, it is being affected by all ticks, so the ultra-fast secondary timeframe is turning Historical on, which given a 1-tick barSeries, means pretty much on every tick: at any rate, most definitely, after the last 60-min bar, whenever it is.

          Comment


            #6
            Originally posted by koganam View Post
            Try moving the Historical test into the BarsInProgress filter.

            I am theorizing that as it is outside the filter, it is being affected by all ticks, so the ultra-fast secondary timeframe is turning Historical on, which given a 1-tick barSeries, means pretty much on every tick: at any rate, most definitely, after the last 60-min bar, whenever it is.

            My *problem* is that I need to know the historical context of the 0 series in the 1 series:

            Code:
            if (BarsInProgress == 0) {
               startIndex = Historical ? 0 : 1;
            }
            
            if (BarsInProgress == 1) { 
            
             // what is the historical context of the 0 series?
            Print(Times[1][0] + ": Start index: " + startIndex);
            //
            So it seems to plot 0 even during live tape. That's a big problem for my strategy as I'm defining candle patterns on the 0 series but am managing entries, targets, stops in the 1 series (i.e. ticks).

            Comment


              #7
              Hello molecool,

              How you are setting the "startIndex" variable that would be expected since the Primary or BarsInProgress (BIP) 0 is going to be the larger time frame and how the bars are going to be accessed.

              The Primary will be called first which Historical is going to be true since you only change the variable if BIP = 0, but outputting the statement in the smaller time frame.

              Once, the a new Primary bar has been formed then it will set your variable to 1. You may want to change your logic to set the variable in the smaller time frame or set Calculate on bar close to false, so that BIP 0 can be called with incoming ticks of data to set the variable to 1.

              Here is an example of the Output log on a 1 minute time frame to demonstrate what I mean.

              Code:
              BIP: 0 Historical: 0 Time: 5/30/2013 11:41:00 AM
              BIP: 1 Historical: 0 Time: 5/30/2013 11:41:56 AM
              5/30/2013 11:41:56 AM: Start index: 0
              BIP: 1 Historical: 0 Time: 5/30/2013 11:41:57 AM
              5/30/2013 11:41:57 AM: Start index: 0
              BIP: 0 Historical: 1 Time: 5/30/2013 11:42:00 AM
              BIP: 1 Historical: 1 Time: 5/30/2013 11:41:59 AM
              5/30/2013 11:41:59 AM: Start index: 1
              BIP: 1 Historical: 1 Time: 5/30/2013 11:42:00 AM
              Last edited by NinjaTrader_JC; 05-30-2013, 11:50 AM.
              JCNinjaTrader Customer Service

              Comment


                #8
                Originally posted by molecool View Post
                My *problem* is that I need to know the historical context of the 0 series in the 1 series:

                Code:
                if (BarsInProgress == 0) {
                   startIndex = Historical ? 0 : 1;
                }
                 
                if (BarsInProgress == 1) { 
                 
                 // what is the historical context of the 0 series?
                Print(Times[1][0] + ": Start index: " + startIndex);
                //
                So it seems to plot 0 even during live tape. That's a big problem for my strategy as I'm defining candle patterns on the 0 series but am managing entries, targets, stops in the 1 series (i.e. ticks).
                That is pretty much what I suggested. That should provide the information that you need, provided you are not setting startindex anywhere else.

                Are you sure that you are querying the correct 60-min bar? Whether that is Historical or not would depend on the COBC.
                Last edited by koganam; 05-30-2013, 12:14 PM.

                Comment


                  #9
                  My point being...

                  Originally posted by koganam View Post
                  That is pretty much what I suggested. That should provide the information that you need, provided you are not setting startindex anywhere else.

                  Are you sure that you are querying the correct 60-min bar? Whether that is Historical or not would depend on the COBC.
                  LOL - well I should have pointed out that the example below is NOT working (try it for yourself!)

                  What do you mean by 'correct 60-min bar'?

                  Anyway, not to get caught into details - is there a way for me to know whether the first series is historical or not? I think NT may be broken in that regard - still looking forward to hearing back from NT support (hint hint).
                  Last edited by molecool; 05-30-2013, 12:52 PM.

                  Comment


                    #10
                    Hello molecool,

                    I just want to confirm the issue.

                    You currently have this strategy applied to a 60 minute chart. You also have Add(PeriodType.Tick, 1); in the initialize.

                    The issue is that you would like to know if the primary 60 minute bar is historical or live.

                    A quick note, as was mentioned by NinjaTrader_JC in post #7, the 60 minute bar is not going to run OnBarUpdate with Historical false until a 60 minute bar has completed.

                    This means that with the following code, startIndex will not equal 1 until 1 hour after the strategy has been started.
                    Code:
                    if (BarsInProgress == 0)
                    {
                    	Print(Historical);
                    	startIndex = Historical ? 0 : 1;
                    }
                    			
                    if (BarsInProgress == 1)
                    {
                    	Print(Time[0] + ": Start index: " + startIndex);
                    }

                    So just to confirm, you do want to check the state of startIndex while the tick interval is processing. And you want startIndex to equal 1 once a live 60 minute bar has completed. Is this correct?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by molecool View Post
                      LOL - well I should have pointed out that the example below is NOT working (try it for yourself!)

                      What do you mean by 'correct 60-min bar'?

                      Anyway, not to get caught into details - is there a way for me to know whether the first series is historical or not? I think NT may be broken in that regard - still looking forward to hearing back from NT support (hint hint).
                      So then is COBC true or false?

                      Comment


                        #12
                        We're making progress

                        Originally posted by NinjaTrader_ChelseaB View Post
                        Hello molecool,

                        I just want to confirm the issue.

                        You currently have this strategy applied to a 60 minute chart. You also have Add(PeriodType.Tick, 1); in the initialize.
                        Exactly correct - yes.

                        Originally posted by NinjaTrader_ChelseaB View Post
                        The issue is that you would like to know if the primary 60 minute bar is historical or live.
                        Once again spot on.

                        Originally posted by NinjaTrader_ChelseaB View Post
                        A quick note, as was mentioned by NinjaTrader_JC in post #7, the 60 minute bar is not going to run OnBarUpdate with Historical false until a 60 minute bar has completed.
                        I actually missed that one due to Koganam's responses and just read it. Call me thick headed but I'm still a bit confused about why I need to wait an hour.

                        Originally posted by NinjaTrader_ChelseaB View Post
                        This means that with the following code, startIndex will not equal 1 until 1 hour after the strategy has been started.
                        Code:
                        if (BarsInProgress == 0)
                        {
                        	Print(Historical);
                        	startIndex = Historical ? 0 : 1;
                        }
                        			
                        if (BarsInProgress == 1)
                        {
                        	Print(Time[0] + ": Start index: " + startIndex);
                        }
                        Not sure why this is - shouldn't even the zero series be called on every tick during live mode? And shouldn't then the flag be set to true? Perhaps I have a problem grasping the exact paradigm.

                        Originally posted by NinjaTrader_ChelseaB View Post
                        So just to confirm, you do want to check the state of startIndex while the tick interval is processing. And you want startIndex to equal 1 once a live 60 minute bar has completed. Is this correct?

                        Yes, my strategy is rather complex and is based on 60-min candletick patterns. But I'm taking entries on the series 1 (i.e. 1-ticks) and that portion of the code needs to know which candle to evaluate. In historic mode it's actually 0 and it works fine because for instance at 18:33 (on the 1 series) the 19:00 candle does not exist yet. So I'm looking for instance at High[0] for a breach. However in live mode High[0] is the current 60-min candle as it's already active - thus my logic needs to look at High[1] for a breach to paint an entry.

                        I hope this makes sense - all of this seems to work fine except that the historic flag is not working the way I expect it to. All I need to know is whether or not my logic is currently parsing in historic or live mode on the zero series. If there is an open/active candle I need to get a 1 value and not a 0.

                        I may want to add that I attempted to set the index like this:

                        Code:
                        if (BarsInProgress == 1) {
                          startIndex = Historical ? 0 : 1;
                          ...
                        }
                        However it doesn't make a difference. I always get a 0 during live trading. It's driving me bonkers
                        Last edited by molecool; 05-30-2013, 02:51 PM.

                        Comment


                          #13
                          Originally posted by koganam View Post
                          So then is COBC true or false?
                          Of course it's set to false - that's a given with all this.

                          Comment


                            #14
                            Hello molecool,

                            With CalculateOnBarClose false, the first live tick on bars in progress 0 should flip your bool.

                            I have attached the .cs file I am using to test this. Please open the output window and then start this script with the default parameters.

                            Let me know if this is not printing the information you are after.
                            Attached Files
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by molecool View Post
                              Of course it's set to false - that's a given with all this.
                              Then I am really flumoxed. Hm. I was reasonably certain that Historical would be false for every tick of the developing bar, and should show so if COBC = false.

                              I guess I shall have to do a little experiementation later.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Salahinho99, 05-05-2024, 04:13 AM
                              7 responses
                              55 views
                              0 likes
                              Last Post Salahinho99  
                              Started by knighty6508, 05-10-2024, 01:20 AM
                              4 responses
                              26 views
                              0 likes
                              Last Post knighty6508  
                              Started by OllieFeraher, 05-09-2024, 11:14 AM
                              6 responses
                              19 views
                              0 likes
                              Last Post OllieFeraher  
                              Started by PaulMohn, 05-02-2024, 06:59 PM
                              2 responses
                              44 views
                              0 likes
                              Last Post PaulMohn  
                              Started by ETFVoyageur, Today, 02:10 AM
                              0 responses
                              19 views
                              0 likes
                              Last Post ETFVoyageur  
                              Working...
                              X