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

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 chbruno, Today, 04:10 PM
    0 responses
    1 view
    0 likes
    Last Post chbruno
    by chbruno
     
    Started by josh18955, 03-25-2023, 11:16 AM
    6 responses
    436 views
    0 likes
    Last Post Delerium  
    Started by FAQtrader, Today, 03:35 PM
    0 responses
    6 views
    0 likes
    Last Post FAQtrader  
    Started by rocketman7, Today, 09:41 AM
    5 responses
    19 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by frslvr, 04-11-2024, 07:26 AM
    9 responses
    127 views
    1 like
    Last Post caryc123  
    Working...
    X