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

Line is locked from Draw.HorizontalLine

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

    Line is locked from Draw.HorizontalLine

    When I use Draw.HorizontalLine() to draw a HL, the HL is locked, i.e. I can't manually move it unless I do a manual unlock. When the code use Draw.HorizontalLine() again to move the HL to a new price level, it's again locked. Questions:
    1) Is there a way for Draw.HorizontalLine() to don't lock the line?
    2) Is using Draw.HorizontalLine() again to move the HL the correct way? i.e. is there like a 'move' function instead?

    Thanks for your help.

    #2
    Hello,

    Thank you for the post.

    By nature, a line should lock when drawn by a script so this is expected. You can, however, unlock the line using its IsLocked property. Please note that this property is hidden from the NinjaScript editor so you would not see it when trying this in the editor.

    Code:
    HorizontalLine aLine = Draw.HorizontalLine(this, "tag", Close[0], Brushes.Red);
    aLine.IsLocked = false;
    Calling the draw method again would be the suggested way to move a tool by price. If you use the property shown this should prevent locked from being used.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank-you very much. That work!

      Comment


        #4
        I am trying to set default for trend channels to unlocked. How would I change this code so that it works?

        Comment


          #5
          Hello VTrades, thanks for your post.

          If you wanted to change the default behavior of the Trend Channel drawing tool, you would need to create an entirely new version of the TrendChannel script from the NinjaScript Editor. The most straight forward way to get around the default lock is to set the drawing tool's IsLocked property to false.

          Please let me know if I can assist any further.
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            Chris,

            I attempted to change the setting by writing

            TrendChannel.IsLocked = false;

            but received an error stating
            An object reference is required for the non-static field, method, or property ‘Ninjatrader.NinjaScript.DrawingTools.DrawingTool. IsLocked.get’
            CS0120

            Comment


              #7
              Hello VTrades, thanks for your reply.

              You are trying to change the property of the class itself. You would need an object reference to the class to be able to set the IsLocked property. See Post #2 here for an example of that.

              Please let me know if I can assist any further.
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                Chris, I attempted it and it didn’t work. I have multiple trend channels plotting and they have their own tag using current bar number. Is that why it won’t work? Is there a way to create a Lock switch in the indicator input menu similar to when you go into drawing properties?

                Comment


                  #9
                  Hello VTrades, thanks for your reply.

                  It would be possible to add a Bool property in your indicator then use that property to set the IsLocked property. After the obect is drawn, set "TheObject.IsLocked = MyBool".

                  My test script is working fine, could you test the same on your end and see what the differences between my example and your script are?

                  Code:
                  protected override void OnBarUpdate()
                  {
                      if(State == State.Historical) return;
                  
                      TrendChannel TC = Draw.TrendChannel(this, "MyTC", false, 10, Low[10], 0, High[0], 5, High[5]);
                      TC.IsLocked = false;
                  }

                  Kind regards.
                  Chris L.NinjaTrader Customer Service

                  Comment


                    #10
                    I am trying to add the Is.locked to this after an if statement with parameters for when to draw the channel.

                    if(Time[0].Date == DateTime.Now.Date)
                    Draw.TrendChannel( this, @"Trading Range" + Convert.ToString(CurrentBars[0]), false, 2, Upperboundary, 0, Upperboundary, 2, Lowerboundary);
                    AllowRemovalOfDrawObjects = true;

                    Comment


                      #11
                      Update, I removed the if state == Historical and it seems to be working now. I appreciate all of the help.

                      Comment


                        #12
                        Hello VTrades, thanks for your reply.

                        This goes back to my post #7. You are not setting the TrendChannel to an object, so the IsLocked property can not be changed after drawing. See how I assigned Draw.TrendChannel to an TrendChannel object in my previous post:

                        TrendChannel TC = Draw.TrendChannel(this, "MyTC", false, 10, Low[10], 0, High[0], 5, High[5]);
                        TC.IsLocked = false;
                        Chris L.NinjaTrader Customer Service

                        Comment


                          #13
                          Chris,

                          The code you provided is working properly now. Thank you very much for your help.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by bmartz, 03-12-2024, 06:12 AM
                          3 responses
                          26 views
                          0 likes
                          Last Post NinjaTrader_Zachary  
                          Started by Aviram Y, Today, 05:29 AM
                          2 responses
                          8 views
                          0 likes
                          Last Post Aviram Y  
                          Started by gentlebenthebear, Today, 01:30 AM
                          1 response
                          8 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Started by cls71, Today, 04:45 AM
                          1 response
                          7 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by TradeForge, Today, 02:09 AM
                          1 response
                          23 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Working...
                          X