Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Alert within a box

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

    Alert within a box

    Hi

    I want to develop a simple indicator with two pieces of conditions

    1. Price close with in 10% of high. I know how to write code for this condition
    2. Price stays with in the rectangle I draw on the chart

    I dont know how to write code for the second condition. I want to draw a rectangle box every morning (which means it will be different/new one every morning but it will be rectangle) and check price stay with in the box I draw . I want draw same rectangle box in other instruments as well.

    Can you please help me the code?

    #2
    Hello chakriare,

    Thank you for your post.

    Below is an example of looping through the drawing objects to find a manually draw rectangle and check if the close is within the bounds of the rectangle.
    Code:
    		protected override void OnBarUpdate()
    		{
    			foreach (DrawingTool draw in DrawObjects)
    			{
    				if (draw is DrawingTools.Rectangle && draw.IsUserDrawn)
    				{               
    					Rectangle uRect = draw as DrawingTools.Rectangle;
    					if ((Close[0] > uRect.StartAnchor.Price || Close[0] > uRect.EndAnchor.Price) && (Close[0] < uRect.StartAnchor.Price || Close[0] < uRect.EndAnchor.Price))
    					{
    						Print("Current price is within the rectangle.");
    					}
    				}
    			}
    		}
    For information on DrawObjects please visit the following link: http://ninjatrader.com/support/helpG...rawobjects.htm

    Please let me know if you have any questions.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    597 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    343 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    556 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    555 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X