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

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.


    To make sure you have enough bars in a data series you are accessing you may view the following link.


    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.


    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.



    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:
    [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]
    [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (Close[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]] > Close[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]3[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]
    && Close[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]] > Close[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]
    && Close[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]] > Close[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]])
    {[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]
    DrawRectangle([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"My rectangle"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + CurrentBar, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], Open[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], Close[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]], Color.Blue);
    }
    [/SIZE][/FONT][/SIZE][/FONT]
    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 jaybedreamin, Today, 05:56 PM
0 responses
7 views
0 likes
Last Post jaybedreamin  
Started by DJ888, 04-16-2024, 06:09 PM
6 responses
18 views
0 likes
Last Post DJ888
by DJ888
 
Started by Jon17, Today, 04:33 PM
0 responses
4 views
0 likes
Last Post Jon17
by Jon17
 
Started by Javierw.ok, Today, 04:12 PM
0 responses
12 views
0 likes
Last Post Javierw.ok  
Started by timmbbo, Today, 08:59 AM
2 responses
13 views
0 likes
Last Post bltdavid  
Working...
X