Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can't Get DrawRectangle To Update OnBarUpdate()

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

    Can't Get DrawRectangle To Update OnBarUpdate()

    My indicator draws two rectangles on an intraday chart to represent the previous weekly candle and current weekly candle that is developing. Trouble is, the rectangle that represents the developing weekly candle does not update with the current price--I have to refresh the indicator before it updates. What simple solution am I missing? Thanks in advance.

    Code:
      
    
    	protected override void OnBarUpdate()
    	{	
    			
    				
    	if(BarsInProgress == 1 && FirstTickOfBar)
    	{
    	
    	if (CurrentBar < 3) return;
    	
    			if ((Open[1]) >= (Close[1]))//BEARISH BAR PREVIOUS
    			{
    				DrawRectangle("Body", false, Math.Min(CurrentBar, -15), Open[1], Math.Min(CurrentBar, -25), Close[1], Color.Red, Color.Transparent, 1);
    		
    				DrawLine("High", Math.Min(CurrentBar, -20), High[1], Math.Min(CurrentBar, -20), Open[1], Color.Pink);
    				DrawLine("Low", Math.Min(CurrentBar, -20), Low[1], Math.Min(CurrentBar, -20), Close[1], Color.Pink);
    			
    				DrawLine("halfwaybear", false, Math.Min(CurrentBar,-16), ((Close[1] + Open[1])/2), Math.Min(CurrentBar, -24), ((Close[1] + Open[1])/2), Color.Blue, DashStyle.Solid, 1);
    		
    				RemoveDrawObject("halfwaybull");
    										
    			}
    			else if ((Open[1]) <= (Close[1]))//Bullish PREVIOUS
    			{
    				DrawRectangle("Body", false, Math.Min(CurrentBar, -15), Open[1], Math.Min(CurrentBar, -25), Close[1], Color.Green, Color.Transparent, 1);
    			
    				DrawLine("High", Math.Min(CurrentBar, -20), High[1], Math.Min(CurrentBar, -20), Close[1], Color.Pink);		
    				DrawLine("Low", Math.Min(CurrentBar, -20), Low[1], Math.Min(CurrentBar, -20), Open[1], Color.Pink);
    			
    				
    				DrawLine("halfwaybull", false, Math.Min(CurrentBar,-16), ((Close[1] + Open[1])/2), Math.Min(CurrentBar, -24), ((Close[1] + Open[1])/2), Color.Blue, DashStyle.Solid, 1);
    		
    					
    				RemoveDrawObject("halfwaybear");
    					
    			}
    		
    				
    	}//if(BarsInProgress == 1 && FirstTickOfBar)
    		
    	
    	
    	if(BarsInProgress == 1 )
    		{	
    			
    			if ((Open[0]) >= (Close[0]))//BEARISH BAR CURRENT
    			{
    				DrawRectangle("Body0", false, Math.Min(CurrentBar, -26), Open[0], Math.Min(CurrentBar, -36), Close[0], Color.Red, Color.Transparent, 1);
    			
    				DrawLine("High0", Math.Min(CurrentBar, -31), High[0], Math.Min(CurrentBar, -31), Open[0], Color.Pink);
    									
    				DrawLine("Low0", Math.Min(CurrentBar, -31), Low[0], Math.Min(CurrentBar, -31), Close[0], Color.Pink);
    					
    			}
    			else if ((Open[0]) <= (Close[0]))//BULLISH BAR CURRENT
    			{
    				DrawRectangle("Body0", false, Math.Min(CurrentBar, -26), Open[0], Math.Min(CurrentBar, -36), Close[0], Color.Green, Color.Transparent, 1);
    			
    				DrawLine("High0", Math.Min(CurrentBar, -31), High[0], Math.Min(CurrentBar, -31), Close[0], Color.Pink);		
    			
    				DrawLine("Low0", Math.Min(CurrentBar, -31), Low[0], Math.Min(CurrentBar, -31), Open[0], Color.Pink);
    			
    				
    			
    					
    				    }
    	} //	if(BarsInProgress == 1 )
    				
    	
    					
    				
    	}//on bar update

    #2
    Hello shipolito,

    Thank you for reaching out to us. I see you are using an additional data series for these calculations. To clarify, could you please provide the code you are creating the additional data series with? It will be in the Initialize() method of your indicator and should look similar to:
    Add(PeriodType.Minute, 5);
    or
    Add("ES 12-06", PeriodType.Tick, 100);

    Thank you.
    Michael M.NinjaTrader Quality Assurance

    Comment


      #3
      Here you go:

      Code:
      protected override void Initialize()
      			{
      				CalculateOnBarClose	= false;
      				Overlay				= true;
      				PriceTypeSupported	= false;
      				Add(PeriodType.Week, 1);
      		
      			
      			}

      Comment


        #4
        Hello shipolito,

        Thank you for your response.

        Can you provide the full indicator file attached to your response?

        Comment


          #5
          Patrick,

          Thanks for your time--attached is the indicator. I hope you can replicate the issue on your side.
          Attached Files

          Comment


            #6
            Nevermind--solved. I abandoned use of BarsInProgress for the rectangle that represents the developing weekly bar and used Closes[1][0] etc., instead.

            Thank you for your time

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            571 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            330 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            548 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            549 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X