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

Invoke the LINE drawing tool from code

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

    Invoke the LINE drawing tool from code

    Is there a proper way to invoke the Line drawing tool from ninjascript. The only way I've been able to do it is by calling: SendKeys.Send("{F2}"); (which is the hotkey for the line tool)

    This works okay, but my fear is that it is somehow confusing NinjaTrader, since when a line is deleted it still shows up in the DrawObjects object... which is confusing MY code.

    #2
    Originally posted by neoikon View Post
    This works okay, but my fear is that it is somehow confusing NinjaTrader, since when a line is deleted it still shows up in the DrawObjects collection... which is confusing MY code.
    After much digging, I found out that the "StartBarsAgo" property on the "hidden" lines have a large negative number. I just make sure that "valid" lines have a StartBarsAgo value of >= -1.

    I still feel like there is a larger problem going on. I'm not sure if this work around will work in all cases either.

    EDIT: And by "hidden", I mean the lines that were deleted, but are still in the DrawObjects collection.

    Any help is greatly appreciated!
    Daniel
    Last edited by neoikon; 04-02-2012, 10:34 PM.

    Comment


      #3
      neoikon, I guess I'm not exactly sure why you're not working with the NinjaScript DrawLine commands available?





      Those programmatically drawn lines could also be managed via the DrawObjects collection then as you seeked.
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_Bertrand View Post
        neoikon, I guess I'm not exactly sure why you're not working with the NinjaScript DrawLine commands available?





        Those programmatically drawn lines could also be managed via the DrawObjects collection then as you seeked.
        Yes, I am familiar with those calls, but those require you know the start and end point to draw. I need the user to draw those points, then I do calculations based on the start/end point, prices, etc.

        Thus, I am sending an "F2" to initiate it for the user, with my script listening for it. This feels like a hack. I would really like to initiate the "Line" drawing tool via code, directly.

        I don't listen for every line drawn by the user, only the ones that are initiated via my tool.

        Does that make sense?

        Daniel

        Comment


          #5
          I see Daniel, another idea I would then have is having the user normally draw the line via F2 and then changing to a unique tag id for your tool, you can then monitor DrawObjects collection for a user drawn line with a specific tag, this is 'your' line then to be further used in the script.

          Some great ideas are also contained in RyanM's script from our sharing dealing with user line Alerts - http://www.ninjatrader.com/support/f...catid=4&id=472
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Bertrand View Post
            I see Daniel, another idea I would then have is having the user normally draw the line via F2 and then changing to a unique tag id for your tool, you can then monitor DrawObjects collection for a user drawn line with a specific tag, this is 'your' line then to be further used in the script.

            Some great ideas are also contained in RyanM's script from our sharing dealing with user line Alerts - http://www.ninjatrader.com/support/f...catid=4&id=472
            Having the user manually change the tag name is not an option. I understand what you are saying, but what professional tool would require such a thing? Plus, speed of using the tool is extremely important (as is most drawing in a real-time, trading environment)

            What we really need is a generic string param that the programmer can set in the object to use how they see fit. The programmer could put in a delimited list of params or a unique tag name, etc in that string. It would open so many doors. I realize this doesn't exist, but it's what would help.

            What I need to do is to be able to change some kind of line attribute to something unique (programmatically, so it can't be read-only) in order to identify it. Thinking outside the box, perhaps I can set the line to one very specific RGB color (that's different from the default Line color) and I look for that specific color. Is there another attribute that I could key off of? Perhaps some Pen attribute that isn't obvious that the user wouldn't commonly already have set as default?

            Thanks for the script. I'm not sure it applies to me, but it does bring up an unrelated question. When looking at the DrawObjects collection and you cast a specific object to a line, is it better to cast to ILine or ChartLine? Or does it matter?

            Thanks!
            Daniel

            Comment


              #7
              Hi Daniel, thanks for the feedback, I will add to our product enhancement tracking lists.

              I'm not sure where the ChartLine comes into play, we would support those types listed here - http://www.ninjatrader.com/support/h...drawobject.htm

              The custom color sounds like a neat idea, perhaps combine that with a specific PenStyle and width for 'your' line to be used.
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Bertrand View Post
                I'm not sure where the ChartLine comes into play, we would support those types listed here - http://www.ninjatrader.com/support/h...drawobject.htm
                This is what I mean... when looking at the DrawObjects collection and I find a line object, is it better to cast it as a NinjaTrader.Gui.Chart.ILine or a NinjaTrader.Gui.Chart.ChartLine object. Both are lines and both seem to be very similar (if not the same). Just wondering what is the better practice.

                PHP Code:
                foreach(IDrawObject DrawObj in DrawObjects)
                {
                   if (
                DrawObj.DrawType == DrawType.Line)
                   {
                      
                ChartLine oLine = (ChartLine)DrawObj;  // Using "ChartLine" as the type
                      
                ...
                   }
                }

                // VERSUS
                foreach(IDrawObject DrawObj in DrawObjects)
                {
                   if (
                DrawObj.DrawType == DrawType.Line)
                   {
                      
                ILine oLine = (ILine)DrawObj;   // Using ILine as the type
                      
                ...
                   }

                Comment


                  #9
                  Originally posted by NinjaTrader_Bertrand View Post
                  The custom color sounds like a neat idea, perhaps combine that with a specific PenStyle and width for 'your' line to be used.
                  I'm going down the path of making unique Pens to identify certain lines. After some hiccups, so far so good.

                  On a related note, is it possible to programmatically look at the default pen that the Line tool uses? In other words, I want to look at the default settings of a line and make sure that I am using a different color, style, etc.

                  Daniel

                  Comment


                    #10
                    Hello,

                    Unfortunately nothing supported in our API to do this.

                    The Iline interface is what is recommended.


                    -Brett

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by judysamnt7, 03-13-2023, 09:11 AM
                    4 responses
                    59 views
                    0 likes
                    Last Post DynamicTest  
                    Started by ScottWalsh, Today, 06:52 PM
                    4 responses
                    36 views
                    0 likes
                    Last Post ScottWalsh  
                    Started by olisav57, Today, 07:39 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post olisav57  
                    Started by trilliantrader, Today, 03:01 PM
                    2 responses
                    22 views
                    0 likes
                    Last Post helpwanted  
                    Started by cre8able, Today, 07:24 PM
                    0 responses
                    10 views
                    0 likes
                    Last Post cre8able  
                    Working...
                    X