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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    82 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    43 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    64 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    68 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    56 views
    0 likes
    Last Post CarlTrading  
    Working...
    X