• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

High between two times with Getbar

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

    High between two times with Getbar

    Hi there,

    I am trying to get the high between two times, say 9:30 and 9:40 using tick charts.

    Can I use Getbar like I have below to achieve this?

    Code:
    startDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 9, 30, 0);
    
    if ((ToTime(Time[0]) == 94000)) 
    {
    	
      int ibarsAgo = Currentbar - Bars.GetBar(startDateTime);
    				
      openingRangeHigh =  MAX(High, ibarsAgo)[0];
      openingRangeLow = MIN(Low, ibarsAgo)[0];
    					
    // Draw
    
    }

    #2
    Hi ij001,

    Using Bars.GetBar() should work fine.

    Are you not getting the value you are looking for?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hi ij001,

      Using Bars.GetBar() should work fine.

      Are you not getting the value you are looking for?
      Yes. It appears that

      Code:
      if (ToTime(Time[0]) == 94000)
      wont work with tick charts?

      Comment


        #4
        Hi ij001,

        This will work as long as there is a bar that is stamped exactly 9:40 AM.

        If there is no bar at that time, the condition will not be true. (Meaning it can be skipped)

        Try using >= instead of == so you get the next bar after 9:40.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hi ij001,

          This will work as long as there is a bar that is stamped exactly 9:40 AM.

          If there is no bar at that time, the condition will not be true. (Meaning it can be skipped)

          Try using >= instead of == so you get the next bar after 9:40.
          Hi Chelsea,

          Yes, I see what you mean, thanks.

          I also noticed in my code below, the use of GetBar was incorrect and I have fixed it.

          The only issue I am having is with the DrawFibRetracement and having it draw once during that time.

          Code:
          timeOfInterest = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 9, 30, 0);
          			
          			if 	(
          				(ToTime(Time[0]) >= 93000) &&
          				(ToTime(Time[0]) <= 94000)
          				)
          			{
          				barsAgo = GetBar(timeOfInterest);
          				Print(barsAgo);
          				
          				openingRangeHigh = MAX(High, barsAgo)[0];
          				openingRangeLow = MIN(Low, barsAgo)[0];
          				
          				DrawFibonacciRetracements("Default", false, startDateTime, openingRangeHigh, endDateTime, openingRangeLow);
          			}
          The above code, will only draw once on the entire chart because the call to DrawFib tag is "Default" not "Default"+CurrentBar.

          If I call "Default"+CurrentBar it will draw over and over.

          How can I print once each day with CurrentBar?

          Comment


            #6
            Originally posted by ij001 View Post
            Hi Chelsea,

            Yes, I see what you mean, thanks.

            I also noticed in my code below, the use of GetBar was incorrect and I have fixed it.

            The only issue I am having is with the DrawFibRetracement and having it draw once during that time.

            Code:
            timeOfInterest = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 9, 30, 0);
                        
                        if     (
                            (ToTime(Time[0]) >= 93000) &&
                            (ToTime(Time[0]) <= 94000)
                            )
                        {
                            barsAgo = GetBar(timeOfInterest);
                            Print(barsAgo);
                            
                            openingRangeHigh = MAX(High, barsAgo)[0];
                            openingRangeLow = MIN(Low, barsAgo)[0];
                            
                            DrawFibonacciRetracements("Default", false, startDateTime, openingRangeHigh, endDateTime, openingRangeLow);
                        }
            The above code, will only draw once on the entire chart because the call to DrawFib tag is "Default" not "Default"+CurrentBar.

            If I call "Default"+CurrentBar it will draw over and over.

            How can I print once each day with CurrentBar?
            Code:
            private IFibonacciRetracements fR;
            Code:
            if (fR.Tag != Time[0].Date.ToString("d")) fR = DrawFibonacciRetracements(Time[0].Date.ToString("d"), false, startDateTime, openingRangeHigh, endDateTime, openingRangeLow);

            Comment


              #7
              Hi ij001,

              If you want to control when there is a new drawing object appears, use your own custom variable that is incremented when you like.

              For example:
              In #region Variables:
              private int newFib = 0;
              private bool once = false;

              In OnBarUpdate():
              if (ToTime(Time[0]) < 93000 && ToTime(Time[0]) > 94000 && once == false)
              {
              newFib++;
              once = true;
              }

              if (ToTime(Time[0]) >= 93000 &&ToTime(Time[0]) <= 94000 )
              {
              barsAgo = GetBar(timeOfInterest);
              Print(barsAgo);

              openingRangeHigh = MAX(High, barsAgo)[0];
              openingRangeLow = MIN(Low, barsAgo)[0];

              DrawFibonacciRetracements("Default"+newFib, false, startDateTime, openingRangeHigh, endDateTime, openingRangeLow);
              once = false;
              }
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by koganam View Post
                Code:
                private IFibonacciRetracements fR;
                Code:
                if (fR.Tag != Time[0].Date.ToString("d")) fR = DrawFibonacciRetracements(Time[0].Date.ToString("d"), false, startDateTime, openingRangeHigh, endDateTime, openingRangeLow);
                Was this line to be added after my DrawFibs line of code?

                I added it afterwards and no Fibs show up.

                Comment


                  #9
                  What is an example of this line of code?

                  if (ToTime(Time[0]) < 93000 && ToTime(Time[0]) > 94000 && once == false)

                  Comment


                    #10
                    Hi ij001,

                    This code:
                    Code:
                    if (ToTime(Time[0]) < 93000 && ToTime(Time[0]) > 94000 && once == false)
                    {
                    newFib++;
                    once = true;
                    }
                    Checks to see if the time is outside the hours you have specified in post #5 and increments the newFib variable so that the tag used for the fibonacci changes and allows for an additional fibonacci to be drawn.

                    The once variable, ensures that this variable is incremented once and not for every bar when outside of the specified hours.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      I see. I have used that code and it displays once on the current day but still does not display on previous days. I am not sure why since newfib is a unique id like CurrentBar?

                      Comment


                        #12
                        ij001,

                        Could you provide what you have written so far?
                        Cal H.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_Cal View Post
                          ij001,

                          Could you provide what you have written so far?
                          Yes please see below. I separated it into two snippets.
                          Code:
                          private double		openingRangeHigh		= 0;
                          private double		openingRangeLow		= 0;
                          private DateTime startDateTime; 
                          private DateTime endDateTime;
                          private DateTime timeOfInterest;
                          private int barsAgo2 = 0;
                          private int counter = 0;
                          private bool once = false;
                          Code:
                          if(CurrentBar < BarsRequired)
                          	return;
                          
                          startDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 9, 30, 0);
                          endDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 23, 00, 0);
                          timeOfInterest = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 9, 30, 0);
                          
                          if (ToTime(Time[0]) < 93000 && ToTime(Time[0]) > 94000 && once == false)
                          {
                          	counter++;
                          	once = true;
                          }
                          			
                          if 	(
                          	BarsPeriod.Id == PeriodType.Tick &&
                          	(ToTime(Time[0]) >= 93000) &&
                          	(ToTime(Time[0]) <= 94000)
                          	)
                          {
                          	barsAgo2 = GetBar(timeOfInterest);
                          				
                          	openingRangeHigh = MAX(High, barsAgo2)[0];
                          	openingRangeLow = MIN(Low, barsAgo2)[0];
                          				
                          	DrawFibonacciRetracements("Default"+counter, false, startDateTime, openingRangeHigh, endDateTime, openingRangeLow);				
                          
                          	once = false;
                          }

                          Comment


                            #14
                            ij001,

                            Try using CurrentBar instead of Counter for the DrawObject tag name -
                            Code:
                            				DrawFibonacciRetracements("Default"+CurrentBar, false, startDateTime, openingRangeHigh, endDateTime, openingRangeLow);
                            Cal H.NinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by NinjaTrader_Cal View Post
                              ij001,

                              Try using CurrentBar instead of Counter for the DrawObject tag name -
                              Code:
                              				DrawFibonacciRetracements("Default"+CurrentBar, false, startDateTime, openingRangeHigh, endDateTime, openingRangeLow);
                              Hi Cal,

                              I usually use "Default"+CurrentBar but here I am using Tick Charts so I can not simply use "Default"+CurrentBar because it will draw multiple times from barsAgo2.

                              Cheslea was discussing using a counter but it only appears to work on the current day.

                              I have an extra couple of lines of code where the fib will draw on all days with "Default"+CurrentBar but it prints multiple times so the lines are quite dark.

                              Code:
                              if 	(
                              				BarsPeriod.Id == PeriodType.Tick &&
                              				(ToTime(Time[0]) >= 93000) &&
                              				(ToTime(Time[0]) <= 94000)
                              				)
                              			{
                              				barsAgo2 = GetBar(timeOfInterest);
                              				
                              				openingRangeHigh = MAX(High, barsAgo2)[0];
                              				openingRangeLow = MIN(Low, barsAgo2)[0];
                              			}
                              			
                              			if 	(
                              				BarsPeriod.Id == PeriodType.Tick &&
                              				ToTime(Time[0]) > 94000
                              				)
                              			{
                              				DrawFibonacciRetracements("Default"+CurrentBar, false, startDateTime, openingRangeHigh, endDateTime, openingRangeLow);				
                              			}
                              Perhaps you can suggest how I can get it to print only once instead of each time after 9:40. Ideally I would like to just draw the lines on the last call to barsAgo2...

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Longhornmark, Today, 08:25 AM
                              3 responses
                              10 views
                              0 likes
                              Last Post bltdavid  
                              Started by mohdhm, Today, 04:09 PM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_ShawnB  
                              Started by BGWTEX, Today, 03:30 PM
                              1 response
                              4 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by marekflys, Today, 03:07 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post marekflys  
                              Started by GregoryBaskin, Today, 02:51 PM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_Tyler  
                              Working...
                              X