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

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 algospoke, 04-17-2024, 06:40 PM
6 responses
48 views
0 likes
Last Post algospoke  
Started by arvidvanstaey, Today, 02:19 PM
4 responses
11 views
0 likes
Last Post arvidvanstaey  
Started by samish18, 04-17-2024, 08:57 AM
16 responses
61 views
0 likes
Last Post samish18  
Started by jordanq2, Today, 03:10 PM
2 responses
9 views
0 likes
Last Post jordanq2  
Started by traderqz, Today, 12:06 AM
10 responses
21 views
0 likes
Last Post traderqz  
Working...
X