Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Reading property of a drawing object

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

    Reading property of a drawing object

    Hi guys!

    I have a strategy that creates an unlocked HorizontalLine like this
    Code:
    myLine = Draw.HorizontalLine(this, "myLine", fillPrice, true, "");
    myLine.Stroke = new Stroke(Brushes.DarkRed, DashStyleHelper.Dot, 2);
    myLine.IsLocked = false;
    I can move myLine on the chart, but I don't know how to read its Y property in the onBarUpdate() section. It must be a basic C# thing I guess, couldn't find it anyhwere. Can anybody help please? Thanks!

    #2
    Hello RT001,

    Thank you for your post. You can retrieve the Y Value of the line using the following:

    Code:
    myLine.StartAnchor.Price
    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Thank you!

      Comment


        #4
        Hi again Kate,

        a couple of things changed in my ninjascript, and I need to update the myLine.StartAnchor.Price with a new price at each onBarUpdate loop. I tried the obvious
        Code:
        myLine.StartAnchor.Price = myValue
        (and searched a while) but it doesn't work. Can you tell me what would be the proper way to set a new y value to my HorizontalLine please?

        Comment


          #5
          Hello RT001,

          Thank you for your reply.

          To update a line drawing to a new level, you can just call it again in another iteration of On Bar Update with the same tag and a new price, which will update the existing line.

          For example, the following code in OnBarUpdate will consistently update the line to the low of the most recently processed bar when run On Bar Close:

          double YPrice = Low[0];
          DrawingTools.Line myLine = Draw.HorizontalLine(this, "myLine", YPrice, true, "");
          myLine.Stroke = new Stroke(Brushes.DarkRed, DashStyleHelper.Dot, 2);
          myLine.IsLocked = false;

          You don't have to try to change the anchor price of the existing object - I was rather curious why you were needing to access the price since you were hardcoding the line value.

          Please let us know if we may be of further assistance to you.

          Comment


            #6
            Thanks again!!!

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by CarlTrading, 03-31-2026, 09:41 PM
            1 response
            81 views
            1 like
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            42 views
            0 likes
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            64 views
            2 likes
            Last Post CaptainJack  
            Started by CarlTrading, 03-30-2026, 11:51 AM
            0 responses
            66 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 03-30-2026, 11:48 AM
            0 responses
            54 views
            0 likes
            Last Post CarlTrading  
            Working...
            X