Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

unlock line object?

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

    unlock line object?

    is there a way to unlock a line that can be moved around by mouse-click?

    found this link:


    this code doesn't seem to be working:

    Code:
            protected override void Initialize()
            {
                ...
                Add(new Line(Color.Blue, 10, "myLine"));
                ...
            }
    
            protected override void OnBarUpdate()
            {
                ...
                foreach (IDrawObject draw in DrawObjects)
                {
                    if (draw.DrawType == DrawType.Line)
                        draw.Locked = false;
                }
                ...
            }
    cheers,
    -e

    #2
    Hello,

    Thank you for your forum post.

    I copy and pasted your code into my NinjaTrader 7 and it executed for me without any issues and unlocked the line I drew on the chart. Are you using NinjaTrader 7 Beta 16 this is located in the control center->help->about to the right of the NinjaTrader logo. Also if you have calculate on bar close set to true for this indicator it will unlock all drawn objects every bar close.

    Also make sure that you are drawing a line and not an extended line or anything like that.

    Let me know if I can be of further assistance.
    BrettNinjaTrader Product Management

    Comment


      #3
      Hi Brett,

      thanks for the reply. yes, i'm using NT7b16 and have CalculateOnBarClose=true.

      this indicator plots in panel2 (eg. open up RSI or MACD and add the code). for whatever reason, it's not letting me select the line to move. do you think it has to do with panel2?

      also, is there a way to declare the line as undocked? i didn't see an overload with that option. ideally, i would like to initialize the line and just set the property as undocked, rather than calling this code on every OnBarUpdate().

      cheers,
      -e

      Comment


        #4
        Hello e-Man,

        That help guide section for draw objects applies to objects placed with Draw commands. Lines added using Add (new Line as you have can't be manipulated in the same way.

        You can DrawHorizontalLine() and adjust it with your mouse once it's drawn.

        DrawHorizontalLine("myLine", 10, Color.Blue) ;
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          excellent! thanks for your help ... that did the trick.

          in case anyone else needs the full code, here 'tis:
          Code:
                  protected override void OnBarUpdate()
                   {
                     ...
                     if (CurrentBar == 0)
                     {
                       // draw line
                       DrawHorizontalLine("myBand", false, 10, Color.Blue, DashStyle.Solid, 1);
                  
                       // unlock line
                       foreach (IDrawObject draw in DrawObjects)
                       {
                         if (draw.DrawType == DrawType.HorizontalLine)
                           draw.Locked = false;
                       }
                       ...
                     }
                   }
          also, if the lines are in a secondary panel (eg. if you're drawing lines on an osciallator like RSI or histogram like MACD), use DrawOnPricePanel in Initialize() like this:
          Code:
                  protected override void Initialize()
                  {
                      ...
                      DrawOnPricePanel = false;
                      ...
                  }
          cheers,
          -e

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          599 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          344 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
          558 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          557 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X