• 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

  • NBKing
    replied
    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!!!

    Leave a comment:


  • NinjaTrader_PatrickH
    replied
    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?

    Leave a comment:


  • NBKing
    replied
    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

    Leave a comment:


  • koganam
    replied
    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?

    Leave a comment:


  • NBKing
    replied
    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

    Leave a comment:


  • koganam
    replied
    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?

    Leave a comment:


  • NinjaTrader_PatrickH
    replied
    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?

    Leave a comment:


  • 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.

Latest Posts

Collapse

Topics Statistics Last Post
Started by ntdev, Today, 07:31 AM
1 response
7 views
0 likes
Last Post NinjaTrader_Kate  
Started by Kabua, Today, 07:19 AM
1 response
4 views
0 likes
Last Post NinjaTrader_Jim  
Started by brianshih, Today, 02:40 AM
1 response
8 views
0 likes
Last Post NinjaTrader_PatrickG  
Started by ubreun, Yesterday, 10:27 PM
1 response
39 views
0 likes
Last Post NinjaTrader_PatrickG  
Started by 7robert, Yesterday, 06:19 PM
1 response
18 views
0 likes
Last Post NinjaTrader_Marco  
Working...
X