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

Draw multiple objects and take control after days when price touches the object

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

    Draw multiple objects and take control after days when price touches the object

    Hello I'm creating an indicator where it draws a RegionHighlightYas follows

    Draw.RegionHighlightY(this, "Example", true, highPrice, bottomPrice, Brushes.Blue, Brushes.DodgerBlue, 25);

    The thing is, I'd like to draw N RegionHighlightY depending on the days loaded, so if there are 3 days loaded, I'd like to draw 3. The thing is they can not be named "Example" because the ID should be different, which ID should I put?

    Then what I need is, onEachTick I need to calculate if the price is touching this RegionHighlightY, but it may be the first one drawn (from the first day loaded) and I need to react to that RegionHighlightY, any idea how can I do this?

    I'm guessing to have a loop looking for all the RegionHighlightY ID drawn and get the top/bot price and then having the High Low of the price react to this.

    Shorter explanation with example :

    I've load 5 days
    Day1 RegionHighlightY1
    Day2 RegionHighlightY2
    Day3 RegionHighlightY3
    Day4 RegionHighlightY4
    Day5 RegionHighlightY5

    Then as I am on Day5 the price may be in below some RegionHighlightY, so I need to get the one or ones RegionHighlightY that are in that area and react to this.

    #2
    Hello cmtjoancolmenero,

    Thanks for your post.

    You would need to provide a different tag name for each Draw object you are drawing on the chart window.

    For example, if you are calling Draw.RegionHighlightY() three times in the script you would need to supply a different tag name for each Draw method.

    Yes, you could loop through the DrawObjects collection to get information about the RegionHighlightY drawing tools on the chart window.

    DrawObjects: https://ninjatrader.com/support/help...rawobjects.htm
    IDrawingTool: https://ninjatrader.com/support/help...rawingtool.htm
    Draw.RegionHighlightY(): https://ninjatrader.com/support/help...highlighty.htm
    Calculate: https://ninjatrader.com/support/help.../calculate.htm
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hello BrandonH,

      What's the efficient way to draw each object with different tag name? Imagine I add the tag MyRegion, what should I include next to it?

      Comment


        #4
        Hello cmtjoancolmenero,

        Thanks for your notes.

        You could consider providing a tag name to the first Draw method called something like "MyRegion1", and provide a tag name to the second Draw method called something like "MyRegion2", and provide a tag name to the third Draw method called something like "MyRegion2", and so on.

        Or, you could create class-level int variables and assign them values such as myInt1 = 1, myInt2 = 2, myInt3 = 3, and then use something like "MyRegion" + myInt1, "MyRegion" + myInt2, etc as the tag name for the Draw methods.

        It would ultimately be up to you to decide what you want to use as the tag name for each Draw method in the script.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Hello BrandonH,

          I've made it, and it's drawing the regions I want, I'm using this :


          private Dictionary<DateTime, bool> regionsDrawn = new Dictionary<DateTime, bool>(); // Dictionary to store dates for which regions have been drawn​

          Because I want to draw just one region per day, is it ok? Is there any other efficient way to do so?

          Once I have this, I need to get the top and bottom for each drawing object drawn by my indicator, is there any way I can get getting the tag?

          Shall I use this instead?

          private Dictionary<DateTime, double[]> regionsTopPrices = new Dictionary<DateTime, double[]>();
          private Dictionary<DateTime, double[]> regionsBottomPrices = new Dictionary<DateTime, double[]>();

          Comment


            #6
            Hello cmtjoancolmenero,

            Thanks for your notes.

            Yes, you could use a dictionary in your script as you have noted since this is drawing the regions you want the script to draw.

            Please keep in mind that using a Dictionary in a NinjaScript would go outside the scope of support we are able to provide you with since it would fall under C# education. We do not offer C# education in our support at NinjaTrader.

            You could consider looping through the DrawObjects collection to get the tag name of drawing tools that are drawn on the chart window.

            See the DrawObjects help guide page for more information and sample code: https://ninjatrader.com/support/help...rawobjects.htm

            See this help guide page for information about DrawObject information you could get: https://ninjatrader.com/support/help...rawingtool.htm
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              Hello BrandonH,

              Yes, I saw this, but is there any way I can get the top/bot from a RegionHighlightY? I couldn't find it anywhere, I need it because I need to know if the price have pierced it or not.

              Comment


                #8
                Hello cmtjoancolmenero,

                You can get this from the drawing object's anchors.


                RegionHighlightY myReg = Draw.RegionHighlightY(this, "tag1", 10, 0, Brushes.Blue);

                Print( "myReg.StartAnchor.Price: " + myReg.StartAnchor.Price + ", myReg.EndAnchor.Price: " + myReg.EndAnchor.Price );
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by ETFVoyageur, Yesterday, 10:27 AM
                3 responses
                23 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by KNalley, 01-24-2020, 10:33 AM
                5 responses
                942 views
                0 likes
                Last Post Trader17  
                Started by sdauteuil, 09-23-2021, 10:16 AM
                6 responses
                1,242 views
                0 likes
                Last Post marcus2300  
                Started by SilverSurfer1, Yesterday, 01:33 PM
                1 response
                22 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by smartromain, Today, 02:52 AM
                1 response
                21 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Working...
                X