Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Capture location of a drawing object on a chart?

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

    Capture location of a drawing object on a chart?

    I have an indicator I want to draw something on chart, and that will be based on the x-position of a created drawing object(this object will have a unique string tag and will only be drawn once on last bar of chart), that the user can manually drag left and right.

    I will create that line in onBarUpdate() at some point via:
    Code:
    var myLine = Draw.VerticalLine(this,"xLoc", 0,Brushes.Yellow);
    Later, I'll likely create the drawing in an onRender() method, so that anytime this object is unlocked and then moved by the user, it will be recalcualted so that I can get this x-position.

    My question is, is it possible to report the x position of that line as it will have both a variable name "myLine" AND a unique string tag of "xLoc" ?

    #2
    So... I can find the location of the line I've defined as described above with:
    Code:
    Print(Time[0] + "  " + myLine+"   "+ myLine.StartAnchor.SlotIndex );
    That third string in the above print statement will return the bar location of the line.

    I'd like to check and see if it updates as I move that line around in OnRender().

    To do this though, I need to be able to define that segment in the first post globally, but I am unsure how to instantiate a drawing object in the class level?

    For example, to define an int, you could go:
    Code:
    private int myCounter = 0;
    To define a plotstyle you could go:
    Code:
    private PlotStyle                        plot0Style                    = PlotStyle.Line;
    But how to define a drawing object I plan on assigning a value to as I did in the first post?

    Comment


      #3
      I think I got it.

      In the class level, It was simply:
      Code:
      private VerticalLine myLine;

      In onBarUpdate, it was simply:
      Code:
      myLine = Draw.VerticalLine(this, "xLoc", 0, Brushes.Yellow, DashStyleHelper.Dot, 1, true);
      And in onRender(), I did:
      Code:
      protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
      {
      if (ChartBars != null)
        {
          Print(Time[0] +" "+ myLine.StartAnchor.SlotIndex );
      
        }
      }
      This gives me a line that will report the bar location on the chart where the line is when I drag it.

      Comment


        #4
        Hello forrestang,

        Sounds like you got it.

        One note, is that if this is in OnRender(), you will need to call TriggerCustomEvent() to synchronize all series for anything series based. Drawing objects are series based and are drawn attached to the chart bars.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello forrestang,

          Sounds like you got it.

          One note, is that if this is in OnRender(), you will need to call TriggerCustomEvent() to synchronize all series for anything series based. Drawing objects are series based and are drawn attached to the chart bars.
          https://ninjatrader.com/support/help...ustomevent.htm
          Thank you Chelsea.

          Just so I understand... you need to do this when you need to MODIFY something that is attached to a series or something correct?

          For what I'm doing, I don't think I'll be modifying any of the series, I'll just need to capture values from already existing series. E.g., based on WHERE that line is, I will just be looking at OHLC values prior to the location of the line.

          Thanks!

          Comment


            #6
            Hello forrestang,

            TriggerCustomEvent() must be used when involving a series from a non-data-driven method. If you want a value from a series, or are using an object attached to a series, such as a drawing object which is attached to chart bars series, TriggerCustomEvent() must be used.

            No, I have not mentioned setting values. I am referring to getting information from a drawing object.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thanks for that Chelsea, I didn't quite get it till today. I still don't really(but at least a little bit), but I had a problem with some of the items not syncing up EVERY time. Sometimes it would, and sometimes it wouldn't.

              So I managed to ham-fistedly get the TriggerCustomEvent() in my script, and it seems to update the way I expect it to now.

              Comment


                #8
                If curious, this quick video shows what I was attempting to do.

                You can see when this indicator loads, it initially loads with the cursor at the right most bar, and updates as new tics come in(you can see the green projection moving).

                Then if desired, I can grab the line, drag it backwards, and it will show the historical projections, and at that point won't update, as it is processing the historical bars.

                I can if I want, drag it back to the right most bar, and it will then start updating again, and follow each new bar, as the vertical line will stay LOCKED on the most recent bar, until I manually drag it off the right-most bar.

                THe projection is unimportant, I was more interested in the coding exercise of this. So thanks for the help.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                581 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                338 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                103 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                554 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                552 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X