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 detect hand-drawn lines

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

    How to detect hand-drawn lines

    hi,,

    if i hand draw line , in OnBarUpdate i dont see it..(if price is not working )

    I want to have the Drawing Object loader in every situation

    i must to use OnRender method?

    It true, how to use it? ...

    Examples:
    Code:
    On render protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
    
      foreach (DrawingTool draw in DrawObjects)
    .......
    
    }
    i know this examples is not correct but i would to use this method correctly


    (I practically i want to detect it at any time when i drawing )
    Last edited by turbofib; 07-24-2017, 03:34 AM.

    #2
    Hello turbofib,

    Thanks for opening the thread.

    It would not be necessarily recommended to loop through collections in OnRender() as OnRender() can be called often in a short period of time. For example, when clicking and dragging on a chart.

    I would suggest to check for the number of DrawObjects that are on the chart before looping through the collection. Another approach would be to use a custom event where you can check if the drawing objects have changed over a certain period of time.

    Various ways to reference the DrawObjects collection in addition to checking the count can be found here: https://ninjatrader.com/support/help...rawobjects.htm

    For information on using OnRender(), please see here: https://ninjatrader.com/support/help...e_onrender.htm

    The bundled SampleCustomRender indicator provides a good example of using OnRender() for custom rendering.

    An example NinjaScript for creating a custom event that triggers on a timer can be found here: http://ninjatrader.com/support/forum...ead.php?t=5965

    Please let me know if I may be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      A question:

      DrawObject is a list?

      if i draw line,this is in the last list Position ?

      DrawingTool draw1 = DrawObjects[DrawObject.count-1] ...is not correct ...it need String Not Int..


      Can you help, thanks
      Last edited by turbofib; 07-24-2017, 03:20 PM.

      Comment


        #4
        Hello turbofib,

        The DrawObjects collection should not be handled the same way as a list:
        Note: When reloading NinjaScript, all objects (including manual drawing tools) are reloaded at the same time. There is no guarantee a manually drawn object will be added to the DrawObjects collection before an indicator starts processing data.
        Considering this implication, it would not be advised to try and reference the last item in the collection.

        There is an example in the help guide that demonstrates how to reference a DrawObject by the DrawObject's tag. This is the string that is expected in your syntax.

        Code:
        protected override void OnBarUpdate()
        {
          if (DrawObjects["someTag"] != null && DrawObjects["someTag"] is DrawingTools.Line)
          {
            // Do something with the drawing tool line
          }       
         
          // An alternative approach to find the draw object by a tag
          if (DrawObjects["someTag"] as DrawingTools.Line != null)
          {
            // Do something drawing tool line
          }   
         
          // Yet another way to find a drawing tool by a tag
          if (DrawObjects["someTag"].GetType().Name == "Line")
          {
            // Do something drawing tool line 
          }
        }
        You could check if the Count property changes, and if it does you can update a list that you manage that keeps track of the tags added so you can identify a newly added DrawObject.
        JimNinjaTrader Customer Service

        Comment


          #5
          ah ok...i need to create a list...in this list i store all tag of draw...
          Is correct?


          can you give me information how i can to read last element of DrawObjects ? thanks
          Last edited by turbofib; 07-25-2017, 12:12 AM.

          Comment


            #6
            Hello turbofib,

            Yes, I would suggest to keep track of the tags for each drawing object in a list so when you see the count change, you can see which tag in the collection doesn't match a tag saved in your list. That will be the most recently added DrawObject.

            I would recommend to compare tags to identify DrawObjects that have been recently added because of the stipulation noted in the help guide. Referencing a "last" drawing object in another way would not be guaranteed after reloading the NinjaScript with F5.

            Here is a rough example outlining how you can loop through a collection of DrawObjects and the list you manage to see which DrawObject is added. This code is only meant to convey an idea and is is not intended to be used directly in a script.
            Code:
            List<string> myList = new List<string>();
            if (DrawObjects.Count > lastCount)
            {
            	foreach (DrawingTool draw in DrawObjects)
            	{
            	    foreach( string ListedTag in myList)
            	    {
            	        if (ListedTag != draw.Tag)
            			myList.Add(draw.Tag);
            	    }
            	}
            }
            JimNinjaTrader Customer Service

            Comment


              #7
              ok ....i understand it...
              but i ask you another question :

              can you give me information how i can to read last element of DrawObjects ? (i want find it but without loop it)

              (i don't use it in a code..ok.....)

              Comment


                #8
                Hello turbofib,

                I did not want to provide instruction because using the Last() method of the collection would not always guarantee the last item. If you press F5, the order of the DrawObjects could come out of order. It may not be an adequate solution.

                You may try getting the last IDrawingTool in the collection by referencing the Last() method to see if you it will work for you:

                Code:
                IDrawingTool myDrawingTool = DrawObjects.Last();
                JimNinjaTrader Customer Service

                Comment


                  #9
                  last question :

                  When I press the first point to draw the line, the drawobject counter is incremented ......
                  I just want to find out when the line is over at 2 points

                  how i do it?

                  Comment


                    #10
                    Hello turbofib,

                    Thanks of the additional question.

                    Since DrawObjects is a collection of IDrawingTools, you can use additional logic to check if the IDrawingTool is a certain type, and you can use the properties of the IDrawingTool to limit certain actions as well.

                    For example, you could check if the DrawingState of the draw object is in a Normal state, or you could check the Anchors of the IDrawingTool to see if any Anchors are editing.

                    Here are a couple examples:

                    Code:
                    foreach (DrawingTool draw in DrawObjects)
                    {
                    	if (draw is DrawingTools.Line)
                    	{
                    		DrawingTools.Line myLine = draw as DrawingTools.Line;
                    		if (myLine.DrawingState == DrawingState.Normal)
                    			Print("myLine complete.");		
                    	}
                    }
                    Code:
                    foreach (DrawingTool draw in DrawObjects)
                    {
                    	if (draw is DrawingTools.Line)
                    	{
                    		bool lineComplete = true; 
                    		DrawingTools.Line myLine = draw as DrawingTools.Line;
                    		        
                    		if(myLine.Anchors.Count() == 2)
                    			foreach (ChartAnchor anchor in myLine.Anchors)
                    				if(anchor.IsEditing)
                    					lineComplete = false;
                    		if (lineComplete)
                    			Print("myLine complete.");
                    	}
                    }
                    These properties are listed and documented here:

                    IDrawingTool - http://ninjatrader.com/support/helpG...rawingtool.htm

                    DrawingState - http://ninjatrader.com/support/helpG...awingstate.htm

                    ChartAnchor - http://ninjatrader.com/support/helpG...hartanchor.htm
                    JimNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Pattontje, Yesterday, 02:10 PM
                    2 responses
                    14 views
                    0 likes
                    Last Post Pattontje  
                    Started by flybuzz, 04-21-2024, 04:07 PM
                    17 responses
                    229 views
                    0 likes
                    Last Post TradingLoss  
                    Started by agclub, 04-21-2024, 08:57 PM
                    3 responses
                    17 views
                    0 likes
                    Last Post TradingLoss  
                    Started by TradingLoss, 04-21-2024, 04:32 PM
                    4 responses
                    43 views
                    2 likes
                    Last Post TradingLoss  
                    Started by cre8able, 04-17-2024, 04:16 PM
                    6 responses
                    56 views
                    0 likes
                    Last Post cre8able  
                    Working...
                    X