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

Regarding DrawObject in Ninjatrader 8.

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

    Regarding DrawObject in Ninjatrader 8.

    I am interested in creating an indicator that when I manually draw a rectangle, I know the exact position of it in terms of bars ago. The reason is so that i can return the bar closes than fall within the rectangle. I am able to detect the rectangle, but I am not able to figure out what properties to access, in order to calculate the position of he rectangle in relationship to the BarsArray. I was able to do it in Ninjatrader 7, but the properties seem to have changed.

    #2
    Hello,

    Thank you for the post.

    I am not sure I fully understand the question. If you have the BarsAgo already what value are you trying to get instead that you were able to get in NT7? It may be helpful if you could post the specific syntax you were using in NT7 that you are trying to recreate.

    You said you cannot calculate the position of the rectangle in relation to the BarsArray, the Position would be related by the BarsAgo being used by the tool. Are you instead referring to getting the objects X and Y values?


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you for your reply:

      I dont know the BarsAgo, Thats exactly what I am trying to accomplish. It was a typo in my first question.

      Imagine that I see a price pattern in the chart that interests me. I want to be able to draw a rectangle aground it, and the indicator will return the closing price of the bars enclosed by the rectangle.
      Right now this is what i can do:
      I can draw the rectangle, the indicator that I have right now, finds the rectangle and makes it available to me to access its properties and methods. However, I can not find any property or methods in the rectangle object, that will return the current position of the rectangle in the chart, nor its location with respect to the Bars Array. I am looking for an example that does the following:

      Returns the x and y coordinates of the four corners of the rectangle( can be the BarsAgo vs price, DateTime vs price, or X vs Y coordinates( as long as I can convert X and Y coordinates to Barsago vs Price)).
      Finds which bars are located within these x,y coordinates.
      Returns the closing prices of the bars within those coordinates.

      Attached you will see pictures of the objects properties for ninjatrader 7 and ninjatrader 8, noticed that the properties startbarsago and endbarsago are no longer available for ninjatrader 8.
      Thank you very much
      Attached Files
      Last edited by Yandychang; 07-07-2017, 09:52 AM.

      Comment


        #4
        Hello,

        Thank you for the reply and clairifing.

        To gather the BarsAgo and Price, you would need to use the objects Anchors.

        Rather than just having a set of default properties, each object can have its own unique properties along with multiple anchors.

        I would suggest using the following page and its examples to Get objects:

        Also if you plan to export this as a compiled assembly, there would be a different approach to finding objects and their properties here: http://ninjatrader.com/support/helpG...assemblies.htm

        Code:
        protected override void OnBarUpdate()
        {
            foreach (DrawingTool draw in DrawObjects)
            {
                // Finds line objects that are attached globally to all charts of the same instrument
                if (draw is DrawingTools.Rectangle)
                {
                    DrawingTools.Rectangle rec = draw as DrawingTools.Rectangle;
        
                    foreach (var globalLineAnchor in rec.Anchors)
                    {
                        int barsAgo = globalLineAnchor.BarsAgo;
                    }
        
                    // or
        
                    int startAnchor = rec.StartAnchor.BarsAgo;
                    double startAnchorPrice = rec.StartAnchor.Price;
                    int endAnchor = rec.EndAnchor.BarsAgo;
                    double endAnchorPrice = rec.EndAnchor.Price;
                }
            }
        }

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thank you for your response:

          I tried that in the past. The problem that I find is that the property BarsAgo is not available for objects created manually, which is the object that I draw on the chart. what other ways are there to achieve this?

          Comment


            #6
            Hello,

            In the case of manually drawing the rectangle, you could use the Slot index rather than the BarsAgo, and ChartControl to get a Time from that. Using the time you could get a Bar index and then use math or the Get methods to get specific values.

            Code:
            double startAnchorSlotIndex = rec.StartAnchor.SlotIndex;
            DateTime startAnchorTime = ChartControl.GetTimeBySlotIndex(startAnchorSlotIndex);
            int startAnchorBarIndex = ChartBars.GetBarIdxByTime(ChartControl, startAnchorTime);
            With the index, you could use math to figure out a number of BarsAgo or depending on what you want to do with the index you may be able to just use it directly.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by swestendorf, Today, 11:14 AM
            2 responses
            5 views
            0 likes
            Last Post NinjaTrader_Kimberly  
            Started by xiinteractive, 04-09-2024, 08:08 AM
            5 responses
            13 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by Mupulen, Today, 11:26 AM
            0 responses
            2 views
            0 likes
            Last Post Mupulen
            by Mupulen
             
            Started by Sparkyboy, Today, 10:57 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by TheMarlin801, 10-13-2020, 01:40 AM
            21 responses
            3,917 views
            0 likes
            Last Post Bidder
            by Bidder
             
            Working...
            X