Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Rectangles which group price bars

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

  • DarkPool
    replied
    Thanks very much for your help. I've been working with the code you provided and have now gotten it to work how I wanted it to.

    thanks again.

    Leave a comment:


  • NinjaTrader_JC
    replied
    Hello DarkPool,
    Welcome to the Forums. Thanks for your post. I am happy to help.
    To continue to grow you rectangle after a rectangle has been drawn you would have to remove the old rectangle and draw a new one every time OnBarUpdate() is called. Note that this method may take up a bit of CPU and memory depending on how much historical data you are loading. An example of growing your rectangle would be the following.

    Code:
    #region Variables
    // Wizard generated variables
    	double point1Y = 0; // Default setting for point1Y
    	double point2Y = 0; // Default setting for point1Y
    	int numOfBarsAgo = 1; // Default setting for numOfBarsAgo
    // User defined variables (add any user defined variables below)
    #endregion
    
    protected override void OnBarUpdate()
    {
    
    if (Close[2] > Close[3]
        && Close[1] > Close[2]
        && Close[0] > Close[1])
    {
    	DrawRectangle("My rectangle" + CurrentBar, 2, Open[2], 0, Close[0], Color.Blue);
    
    	point1Y = Open[2]; //User defined Double input
    	point2Y = Close[0]; //User defined Double input
    	
    	//User defined Int input		
    	numOfBarsAgo = 1; //Resets numOfBarsAgo
    }
    else
    {
    	if(numOfBarsAgo != 1)
    	{
    		RemoveDrawObject("My rectangle"+(CurrentBar - 1));
    	}
    	DrawRectangle("My rectangle" + CurrentBar, numOfBarsAgo, point1Y, 0, point2Y, Color.Blue);
    	numOfBarsAgo++; //Increments numOfBarsAgo by 1
    }
    }
    For more information about "How to remove a Drawing Object" you may read our online help guide at the following link.
    http://www.ninjatrader.com/support/h...drawobject.htm

    To make sure you have enough bars in a data series you are accessing you may view the following link.
    http://www.ninjatrader.com/support/f...ead.php?t=3170

    Also, if you are having trouble with you code here is a link to help you debug your code to find out what is going on.
    http://www.ninjatrader.com/support/f...ead.php?t=3418

    Note that when writing NinjaScript code the, CalculateOnBarClose(COBC) can vastly effect how your code functions. Which means that if CalculateOnBarClose is true, then the strategy/indicator will be calculated at the close of each bar. If your strategy is set to COBC=false, then it will act differently since it will be calculated on each tick. See the following link for more info on COBC.
    http://www.ninjatrader.com/support/h...onbarclose.htm


    Please let me know if I can be of further assistance.
    Last edited by NinjaTrader_JC; 05-04-2012, 03:00 PM.

    Leave a comment:


  • NinjaTrader_Matthew
    replied
    Hello Dark Pool,

    Thank you for your post and welcome to our forums!

    We've assigned one of our NinjaScript trainees to help you accomplish your goal. We'll be posting a reply shortly. Thank you for your patience.

    Leave a comment:


  • DarkPool
    started a topic Rectangles which group price bars

    Rectangles which group price bars

    Hi All,

    Im new to NinjaTrader and the forum. To say that im impressed with NinjaTrader would be an understatement. Im just scratching the surface but the more I learn about NT, it seems the more the platform is able to do.

    Anyway, please could someone offer some advice on an indicator im trying to code. Essentially what I want to do is whenever there are 3 consecutive higher closes, I want to draw a rectangle around those bars. That part is easy enough. What is also required is that the rectangle must continue growing along the X axis until a new set of 3 consecutive higher closes occurs. At that point the new rectangle's bottom starts from the top of the previous one and the top is at the top of the new 3 consecutive high closes.

    I've attached a screenshot to try and explain this better. I drew this (ie: no code), to illustrate how it should work. Bars a, b, c result in 3 higher closes, therefore a rectangle is drawn round them. This rectangle increases in size along the x axis until a new set of 3 consecutive higher closes occurs. In this case, that occurs 1 bar later (ie: bars b, c, d result in 3 consecutive higher closes). Then when bar e is printed, that also results in 3 consecutive higher closes (ie: c, d, e) so a new rectangle is drawn again. After that there are several bars until the next 3 consecutive higher closes occur at f. This meant that the rectangle which started at e just kept growing until a new set of 3 consecutive higher closes occured.

    Hope that makes sense?

    My feable attempt at coding this is below:
    Code:
    
    if (Close[2] > Close[3]
    && Close[1] > Close[2]
    && Close[0] > Close[1])
    {
    DrawRectangle("My rectangle" + CurrentBar, 2, Open[2], 0, Close[0], Color.Blue);
    }
    
    I think the problem is that I need to record the co-ordinates of the rectangles and be able to reference a specific rectangle but I haven't had any luck figuring that out.

    Is anyone able to offer some advice?
    thanks.
    Attached Files

Latest Posts

Collapse

Topics Statistics Last Post
Started by chartchartchart, Today, 08:08 AM
1 response
5 views
0 likes
Last Post NinjaTrader_Emily  
Started by andreslazor7, Today, 08:08 AM
2 responses
12 views
0 likes
Last Post andreslazor7  
Started by FatCanary, Today, 08:09 AM
2 responses
6 views
0 likes
Last Post FatCanary  
Started by vantojo, 01-12-2021, 02:13 PM
15 responses
196 views
0 likes
Last Post FatCanary  
Started by nailui, Today, 07:26 AM
0 responses
24 views
0 likes
Last Post nailui
by nailui
 
Working...
X