• 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

How do I draw a rectangle at the OPEN of a minute based bar?

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

    How do I draw a rectangle at the OPEN of a minute based bar?

    I am trying to draw a rectangle at the OPEN of a 15 minutes bar highlighting the gap between the close of the previous bar, and the open of the current bar.
    My code seems to work for all previous bars - HOWEVER, I cannot seem to be able to call the draw function WHEN the bard is OPENED. It seems to draw after the bar is closed - which is too late for me.

    Code:
    protected override void Initialize()
    {
            Overlay				= true;
    	CalculateOnBarClose = false;
    }
    
    protected override void OnBarUpdate()
    {
            if (CurrentBar < 1)
                    return;
    			
            if (Open[0] != Close[1])
            {
                    DrawRectangle("Region"+ CurrentBar.ToString(), ......); //This section does the right thing.
            }
    }
    The problem for me is that the rectangles are drawn at the CLOSE of the current bar, instead of the OPEN of the current bar.

    What can I do to fix it?

    Thank you.

    #2
    Hello NBKing,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    I am not seeing the same item on my end unless the Open[0] is the same as Close[1]. Can you provide a screenshot of this on your end on the current bar?
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NBKing View Post
      I am trying to draw a rectangle at the OPEN of a 15 minutes bar highlighting the gap between the close of the previous bar, and the open of the current bar.
      My code seems to work for all previous bars - HOWEVER, I cannot seem to be able to call the draw function WHEN the bard is OPENED. It seems to draw after the bar is closed - which is too late for me.

      Code:
      protected override void Initialize()
      {
              Overlay                = true;
          CalculateOnBarClose = false;
      }
      
      protected override void OnBarUpdate()
      {
              if (CurrentBar < 1)
                      return;
                  
              if (Open[0] != Close[1])
              {
                      DrawRectangle("Region"+ CurrentBar.ToString(), ......); //This section does the right thing.
              }
      }
      The problem for me is that the rectangles are drawn at the CLOSE of the current bar, instead of the OPEN of the current bar.

      What can I do to fix it?

      Thank you.
      With the way that you have that coded, it will draw on the Open. If you seem to be seeing something else, it has to be a misinterpretation. The only possibility that I can see at this time would be on how you are using DrawRectangle(). Would you care to show the statement as you are using it?

      Comment


        #4
        Details

        Here is the code in it's full state.
        I have also enclosed a screen shot - of the current bar.
        You will notice how the previous bars shows the rectangle correctly.
        However, the "live" bar, with the open at a different spot than the close, does not show the rectangle.

        Code:
            public class eGap : Indicator
            {
        			private int rOpacity = 2;
        			private double rLow;
        			private double rHigh;
        			private Color rColor;
                protected override void Initialize()
                {
                    Overlay				= true;
        			CalculateOnBarClose = false;
                }
        
                protected override void OnBarUpdate()
                {
        			if (CurrentBar < 1)
        				return;
        //			if( ! FirstTickOfBar)
        //				return;
        			
        			if (Open[0] != Close[1])
        			{
        				if (Open [0] > Close[1])
        				{
        					rLow=Close[1];
        					rHigh=Open[0];
        				}
        				else
        				{
        					rHigh=Close[1];
        					rLow=Open[0];
        				}
        				
        				rColor = Color.White;
        				
        				DrawRectangle("Region1"+ CurrentBar.ToString(), false, 1, rLow, 0, rHigh, Color.Empty, rColor, rOpacity);
        				
        			}
                }
        Thank you for looking into this.
        Attached Files

        Comment


          #5
          Originally posted by NBKing View Post
          Here is the code in it's full state.
          I have also enclosed a screen shot - of the current bar.
          You will notice how the previous bars shows the rectangle correctly.
          However, the "live" bar, with the open at a different spot than the close, does not show the rectangle.

          Code:
              public class eGap : Indicator
              {
                      private int rOpacity = 2;
                      private double rLow;
                      private double rHigh;
                      private Color rColor;
                  protected override void Initialize()
                  {
                      Overlay                = true;
                      CalculateOnBarClose = false;
                  }
          
                  protected override void OnBarUpdate()
                  {
                      if (CurrentBar < 1)
                          return;
          //            if( ! FirstTickOfBar)
          //                return;
                      
                      if (Open[0] != Close[1])
                      {
                          if (Open [0] > Close[1])
                          {
                              rLow=Close[1];
                              rHigh=Open[0];
                          }
                          else
                          {
                              rHigh=Close[1];
                              rLow=Open[0];
                          }
                          
                          rColor = Color.White;
                          
                          DrawRectangle("Region1"+ CurrentBar.ToString(), false, 1, rLow, 0, rHigh, Color.Empty, rColor, rOpacity);
                          
                      }
                  }
          Thank you for looking into this.
          Is your picture from a live chart, or a backtest?

          Comment


            #6
            Live and Market Replay are the same

            The previous picture was from market replay.
            The picture provided is from live data.
            They both exhibit the same problem.
            Attached Files

            Comment


              #7
              Hello NBKing,

              Thank you for your response.

              Using your code I am not seeing the same behavior.

              Can you advise if there are any error messages listed in the Log tab of the NinjaTrader Control Center?

              In addition, even though the code sets CalculateOnBarClose to False, if you right click in the chart and select Indicators > is the indicator set to CalculateOnBarClose = True?
              Patrick H.NinjaTrader Customer Service

              Comment


                #8
                CalculateOnBarClose setting on the indicator was true

                NinjaTrader_PatrickH - THANK YOU.

                You nailed it - the CalculateOnBarClose setting on the indicator was "true".
                I set it to false - and everything is working now.

                Thank you again!!!

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by dltharpe, Today, 09:17 AM
                0 responses
                7 views
                0 likes
                Last Post dltharpe  
                Started by HiddenPhilosopher, Today, 06:45 AM
                0 responses
                7 views
                0 likes
                Last Post HiddenPhilosopher  
                Started by PG7940, Today, 04:26 AM
                0 responses
                11 views
                0 likes
                Last Post PG7940
                by PG7940
                 
                Started by marcus2300, Today, 02:25 AM
                0 responses
                2 views
                0 likes
                Last Post marcus2300  
                Started by drpapp, 01-24-2019, 06:57 AM
                5 responses
                70 views
                0 likes
                Last Post pjsmith
                by pjsmith
                 
                Working...
                X