Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

B5: User-drawn objects AttachedTo question?

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

    B5: User-drawn objects AttachedTo question?

    Hi

    I'm having trouble identifying which user-drawn rectangles are attached to the visible chart and which are attached to other instrument / time frames.

    Either I do not understand the correct usage (likely) or there is unexpected behaviour.

    The attached indicator tries to identify rectangles drawn on the visible instrument / time frame with this code in OnBarUpdate():

    Code:
    [SIZE=2]                if ( drawObj.AttachedTo.AttachedToType == AttachedToType.Bars )    // attached to the chart Bars
                    {
                        ChartBars attachedToChartBars = (ChartBars)(drawObj.AttachedTo.ChartObject);
                        if ( Bars.Instrument == attachedToChartBars.Bars.Instrument            // the visible instrument
                            && Bars.BarsPeriod == attachedToChartBars.Bars.BarsPeriod            // the period
                            && drawObj is Rectangle && drawObj.IsUserDrawn )        // user-drawn rectangle
                        {
                            Rectangle rect = drawObj as Rectangle;
                            Print( "Doing some stuff with " + drawObj.Tag );
                        }
                    }[/SIZE]
    However, when I use the attached indicator and do the following things, I see that the rectangle appears to change what it's attached to.

    In a workspace with 1 chart (e.g. 1 min EURUSD) and the Ninjascript output window...
    Add the attached indicator. At the new bar it should output DrawObjects.Count.
    Draw a rectangle. At the next new bar it outputs rectangle info.
    Change instrument. At the next new bar it shows the same rectangle attached the new instrument.

    Is this expected behaviour?
    How else do I identify which rectangles do not belong on the visible chart, so I can avoid working with them?

    Cheers
    Tony
    Attached Files

    #2
    Thank you for bringing this to our attention. I can confirm this same behavior on my end, so I am going to submit a report to our team to investigate the cause. (NTEIGHT-8854)
    Last edited by NinjaTrader_DaveI; 09-28-2015, 10:11 AM.
    Dave I.NinjaTrader Product Management

    Comment


      #3
      I've got an update on this issue for you. After speaking with our development team, I've discovered that there is a more efficient way to go about what you are trying to accomplish, and it is working as expected on my end. All you really need to do is compare <IDrawingTool>.AttachedTo.Instrument to Bars.Instrument, and this should effectively filter out the drawing objects which are drawn on the instrument that you are currently viewing.

      I've attached an updated copy of your indicator to this post to clarify.
      Attached Files
      Dave I.NinjaTrader Product Management

      Comment


        #4
        Hi Dave

        Thank you for your quick reply.

        I had seen <IDrawingTool>.AttachedTo.Instrument, but I thought I wanted the period the object was attached to as well. However, I can see now that drawn objects are not attached to instrument/period combinations, only instruments.

        I think my confusion arose because <IDrawingTool>.AttachedTo.DisplayName includes the period and the Drawing Objects window (attached) shows the period. All good now.

        So that leaves the minor issue of <IDrawingTool>.AttachedTo.DisplayName changing when the instrument changes, as you noted.

        Cheers
        Tony
        Attached Files

        Comment


          #5
          That's correct. After speaking with a developer, I discovered that .DisplayName is being used internally, mostly in the context of displaying popup messages. DisplayName takes the Instrument property from ChartBars.Bars, which essentially does the same thing as your original code -- it looks at whatever Bars are currently configured on the chart. I would avoid DisplayName altogether for your purposes.
          Dave I.NinjaTrader Product Management

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by argusthome, Yesterday, 10:06 AM
          0 responses
          22 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          19 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          14 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          10 views
          0 likes
          Last Post TheRealMorford  
          Started by Mindset, 02-28-2026, 06:16 AM
          0 responses
          41 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Working...
          X