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

How to move a user drawn object

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

    How to move a user drawn object

    How can I move a user drawn object (in this case a vertical line) without changing its other properties?

    I've gotten this far:

    Code:
    foreach (IDrawObject draw in DrawObjects) 
    				{
    					if (draw.UserDrawn && draw is IVerticalLine) 
    					{

    #2
    Hello,

    Thanks for the forum post.

    You are almost there! You simply can use the draw object and modify any of its properties by setting it to a different value. This will only affect this property.



    The below code changes the lines color for example and there are more properties you can change.

    foreach (IDrawObject draw in DrawObjects)
    {
    // Finds line objects that are attached globally to all charts of the same instrument
    if (draw.Tag.StartsWith("@") && draw is ILine)
    {
    ILine globalLine = (ILine) draw;

    // Changes the line color and prints its starting and end points
    globalLine.Pen.Color = Color.Black;
    Print("Start: " + globalLine.StartBarsAgo + " End: " + globalLine.EndBarsAgo);
    }

    Comment


      #3
      Thanks Brett,

      I guess I need a further pointer on how to access and alter the BarsAgo property itself, I am not finding the documentation for it.

      I tried globalLine.BarsAgo, but it doesn't look accessible that way.

      Comment


        #4
        Hello,

        Well you wouldn't use line since the drawing object is a verticle line. They are close but slightly different.



        Then BarsAgo is available.

        IVerticalLine vLine = (vLine) draw;
        // Print the number of bars ago the line is located at
        Print(vLine.BarsAgo);

        Comment


          #5
          Sorry if I am missing something simple here but how do I translate that into actually moving the line.

          I am thinking I need to be able to say something like:

          vLine.BarsAgo = 0;

          In other words, how do I change (not just display) that property?

          Comment


            #6
            Hello,

            I just went ahead and created some sample code for you. In this case every object that starts with an @ sign will be moved on each onBarUpdate to the current bar.

            foreach (IDrawObject draw in DrawObjects)
            {
            // Finds line objects that are attached globally to all charts of the same instrument
            if (draw.Tag.StartsWith("@") && draw is IVerticalLine)
            {
            IVerticalLine globalLine = (IVerticalLine) draw;

            // Changes the line color and prints its starting and end points
            globalLine.BarsAgo = 0;
            }
            }

            Comment


              #7
              Here's what I have that isn't working, The lines change color, but they do not move. I checked and the lines are not locked.

              Code:
              foreach (IDrawObject draw in DrawObjects) 
              				{
              					if (draw.UserDrawn && draw is IVerticalLine) 
              					{
              						IVerticalLine measuringLine = (IVerticalLine) draw;
              						measuringLine.Pen.Color = Color.Red;
              						Print(measuringLine.BarsAgo);
              						measuringLine.BarsAgo = 0;
              					}
              				}

              Comment


                #8
                Hello,

                Thanks for the note.

                The object you have drawn is a vertical line correct? Do you get the print that you added in? What does it Print?

                Can you try printing it after you make the change as well?

                I look forward to assisting you further.

                Comment


                  #9
                  Yes they are 2 vertical lines. The updated code and output are below:

                  Code:
                  foreach (IDrawObject draw in DrawObjects) 
                  				{
                  					if (draw.UserDrawn && draw is IVerticalLine) 
                  					{
                  						IVerticalLine measuringLine = (IVerticalLine) draw;
                  						measuringLine.Pen.Color = Color.Red;
                  						Print(measuringLine.BarsAgo);
                  						measuringLine.BarsAgo = 0;
                  						Print("ok, I shoulda moved but I didn't see: " + measuringLine.BarsAgo);
                  					}
                  				}
                  231
                  ok, I shoulda moved but I didn't see: 231
                  332
                  ok, I shoulda moved but I didn't see: 332

                  Comment


                    #10
                    strange. Would expect this to work let me test this really quick on my side.

                    Comment


                      #11
                      Still checking into, thanks for your patience.

                      Comment


                        #12
                        Hello,

                        Checked into with development.

                        This is actually purposely not allowed, as development does not want malicious code capable of moving peoples drawing objects.

                        Therefor you would need to draw this vertical line with the script to be able to move it unfortunately.

                        Let me know if I can be of further assistance.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by GussJ, 03-04-2020, 03:11 PM
                        16 responses
                        3,281 views
                        0 likes
                        Last Post Leafcutter  
                        Started by WHICKED, Today, 12:45 PM
                        2 responses
                        19 views
                        0 likes
                        Last Post WHICKED
                        by WHICKED
                         
                        Started by Tim-c, Today, 02:10 PM
                        1 response
                        9 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by Taddypole, Today, 02:47 PM
                        0 responses
                        5 views
                        0 likes
                        Last Post Taddypole  
                        Started by chbruno, 04-24-2024, 04:10 PM
                        4 responses
                        53 views
                        0 likes
                        Last Post chbruno
                        by chbruno
                         
                        Working...
                        X