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

Moving DrawingTool Anchors

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

    Moving DrawingTool Anchors

    I am writing an indicator that will advance DrawingTool anchors 1 slot on each OnBarUpdate so that the anchors will stay in the same relative position to the current bar. Some anchors are forward, and others behind, the current bar. The anchors are manually drawn on the chart.

    To accomplish this I am using:
    anchor.SlotIndex = anchor.SlotIndex + 1;

    The problem is that if an Anchor is in a slot of an existing bar then it "cannot" be moved, but if the anchor is in an empty slot where there are no bars then the anchor "is" movable.

    Here is the code of a simple test indicator that will move a manually placed dot:
    Code:
    namespace NinjaTrader.NinjaScript.Indicators.Cam.Development
    {
    	public class Test5 : Indicator
    	{
    
    		protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				Description									= @"Move dot 1 bar on bar close";
    				Name										= "Test5";
    				Calculate									= Calculate.OnBarClose;
    				IsOverlay									= true;
    			}
    			else if (State == State.Configure)
    			{
    				ClearOutputWindow();
    			}
    		}
    
    
    		
    		
    		protected override void OnBarUpdate()
    		{
    			Print(" ");
    			foreach (DrawingTool dt in DrawObjects)
    			{
    				if(dt.Name == "Dot")
    				{
    					Print("Got the dot");
    					foreach (ChartAnchor anchor in dt.Anchors)
    					{
    						Print(anchor.DisplayName);
    						if(anchor.DisplayName == "Anchor")
    						{
    							Print("Before incrementing,   anchor.SlotIndex = " + anchor.SlotIndex);
    							anchor.SlotIndex = anchor.SlotIndex + 1;
    							Print("After incrementing,    anchor.SlotIndex = " + anchor.SlotIndex);
    						}
    					}
    					
    				}
    			}
    		}
    
    
    		#region Properties
    
    		#endregion
    
    	}
    }
    Procedure:
    1. Start the indicator.
    2. Draw a dot over an existing bar. (see screen shot "a")
    3. Observe that it does not advance on bar update.
    4. Draw a dot forward of the bars 2 slots to be sure. (see screen shot "b")
    5. Observe that the dot advances 1 slot on each bar update.


    Click image for larger version

Name:	20170404a.png
Views:	1
Size:	112.3 KB
ID:	907398
    Click image for larger version

Name:	20170404b.png
Views:	1
Size:	111.4 KB
ID:	907399

    Any help would be greatly appreciated.

    #2
    Hello Camdo, and thank you for your question. The documentation for IDrawingTool has this to say, emphasis mine,

    Originally posted by http://ninjatrader.com/support/helpGuides/nt8/en-us/idrawingtool.htm
    Anchors : A read-only collection of all of the IDrawingTool's ChartAnchors
    Your ability to edit chart anchors in the second case is being investigated as a bug. For the time being, I would like to ask that you refrain from using this approach, as your code which does this will not work in a future edition of NinjaTrader.

    In order to modify a drawing object's chart anchors, the entire drawing object must be re-drawn. If you use the same tag, the existing object will be replaced with the newly drawn object, thus modifying the existing object. For example,

    Code:
    [FONT=Courier New]
    DrawingTools.Dot exampleDot = dt as DrawingTools.Dot;
    if (exampleDot != null)
    {
        Draw.Dot(this, exampleDot.Tag, IsAutoScale, exampleDot.Anchor.BarsAgo + 1, exampleDot.Anchor.Price, exampleDot.AreaBrush);
    }[/FONT]
    Note that NinjaScripts can only reliably manage objects for which IDrawingTool.Anchors[i].IsNinjaScriptDrawn is true for any given legal i. The above code may work with user drawn objects, but should be tested before your code is deployed.
    Last edited by NinjaTrader_JessicaP; 04-05-2017, 11:39 AM.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Are you saying that <ChartAnchor>.SlotIndex is readonly? That I should not use code like this to keep a <ChartAnchor>.IsNinjaScriptDrawn drawing object visible but should redraw every such object?
      Code:
      object.Anchor.SlotIndex = Bars.Count  [COLOR=DarkGreen];// move the anchor to last visible bar[/COLOR]

      Redrawing is how I did in in NT7, but I was hoping that NT8 would not require that, since adjusting the Anchor.SlotIndex works fine currently.

      Comment


        #4
        Thank you for your help Jessica.
        I tried the re-draw with same tag idea, although the dot is redrawn, the manually drawn dot remains and the chart winds up with two dots with the same tag name. Do you have any other ideas??



        This was the code I wound up using:
        Code:
        						DrawingTools.Dot exampleDot = dt as DrawingTools.Dot;
        						if (dt != null)
        						{
        							Draw.Dot(this, exampleDot.Tag, IsAutoScale, 0, exampleDot.Anchor.Price, Brushes.Red);}
        I used 0 for BarsAgo because exampleDot.BarsAgo returned int.Max
        Last edited by Camdo; 04-04-2017, 10:30 PM.

        Comment


          #5
          Thank you for your input Tradesmart. I tried your code snip but it does not work. Here is a screen shot of the test. Although the anchor.slot is correctly incremented, the dot does not move on the chart and the incremented parameter is somehow lost on the next go around.

          Click image for larger version

Name:	20170404c.png
Views:	1
Size:	105.6 KB
ID:	882552

          Comment


            #6
            Well, my code snippet was simply to demonstrate what I'm doing to see if Jessica would give it a thumbs up or down.

            That being said, I'm not iterating through Anchors, but only through DrawObjects and modifying their Anchor.SlotIndex values to keep my NinjaScriptDrawn Text objects visible as new bars get built. If I don't do something like that, eventually the Text objects will disappear off the left edge of the chart.

            One alternative, as Jessica pointed out, is to redraw the objects, which in my case involves reimporting a CSV file. Another alternative would be to override OnRender() and use RenderTarget.DrawText().

            Comment


              #7
              I am reviewing our specifications and discussing with our responsible teams how editing chart anchors should work in the future. I will have more information regarding this shortly.

              Camdo I noticed in your code that you are checking to see if dt, rather than exampleDot, is null. Does this behavior persist when you are instead checking to see if exampleDot is null?
              Jessica P.NinjaTrader Customer Service

              Comment


                #8
                Thanks for catching that Jessica.
                I changed the null check to exampleDot, but no change in behavior. The manually drawn dot does not move with OnBarUpdate, but the redrawn dot does. Here is a screen shot of the test with a view of the draw object form showing the two objects with the same tag id.

                Click image for larger version

Name:	20170405a.png
Views:	1
Size:	107.7 KB
ID:	882558

                Comment


                  #9
                  Thank you for this additional information Camdo. I did not notice any logic in your code to draw the initial dot. Is it safe to assume the initial dot is hand drawn? This is what was meant by the earlier advice

                  Note that NinjaScripts can only reliably manage objects for which IDrawingTool.Anchors[i].IsNinjaScriptDrawn is true for any given legal i.
                  If you test this out for your blue dot I believe you will see that this variable is false for your dot's anchor. You will need to have your script draw and manage its own objects. You can read values from existing user drawn objects, but managing and editing objects is only guaranteed for objects that your script has had control of over the life of the object.
                  Jessica P.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_JessicaP View Post
                    Is it safe to assume the initial dot is hand drawn?
                    Yes, the first dot (Blue) was hand drawn. I understand now, that there is a limitation. I am trying to bend the rules.

                    The purpose of my code was to have an indicator move a "manually" drawn anchor so it stays in same relative position of the current bar.

                    Comment


                      #11
                      From the help guide http://ninjatrader.com/support/helpG...drawobject.htm
                      User drawn objects CANNOT be removed from via NinjaScript.
                      So, while we are able to inspect user-drawn objects, evidently we should not expect to be able to modify everything about them programmatically. In addition to moving anchors, I also modify appearance attributes, such as OutlineStroke, AreaBrush, AreaOpacity, ZOrder, etc. I have run into a situation where changing OutlineStroke in OnBarUpdate() throws an error, whereas doing so in OnRender() does not.

                      Comment


                        #12
                        I have prepared a code sample as a work around which makes a user drawn dot invisible, and makes a NinjaScript created copy of the object you will be able to modify. Code samples we provide are for educational purposes, and are not intended for live trading, and are not guaranteed to accomplish any user goal or to be maintained.
                        Attached Files
                        Last edited by NinjaTrader_JessicaP; 04-05-2017, 11:58 AM.
                        Jessica P.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_JessicaP View Post
                          I have prepared a code sample
                          Thank you Jessica for the code sample. I am pondering the issue.

                          On a side note, I notice that the editor does not present any class members or properties when exampleDot. is typed but it does for dt. Is this expected behavior or a bug? I am not a proficient object oriented programmer, but when the member list box doesn't pop up I assume that something is wrong and try to write the code in other ways which wastes lots of time.

                          In regards to NT8 not being able to move a manually drawn anchor:
                          Today's trend is human assisted automation. Factories are now utilizing human workers along side robots without cages on the assembly lines. This trend is also seen in artificial intelligence such as the computer map guides in automobiles. More examples will abound in the future. Manual placement of objects and having a program automatically interact and modify them would be a powerful collaborative feature for NT and a natural extension for AI trading. It is my suggestion to Development that the NT8 language have complete access to all the features of manually drawn chart objects.

                          Comment


                            #14
                            You are correct that IntelliSense does not come up for ChartMarkers. This thread has caused us to review the documentation and performance of several IDrawingObjects related to Dots. These kinds of drawing objects can be considered to be under active development. This fact will be one of the facts investigated. We appreciate your patience as we review this part of NinjaTrader.

                            I have submitted a feature request to the product management team for the following feature :

                            This user would prefer a drawing object's anchors no longer be read-only. This user would also like NinjaScript to be allowed full control over user drawn objects. User drawn objects would then need all their data, such as BarsAgo, populated.
                            I will follow up with more information as soon as it's available. If the feature requests already exists, a vote will be added to it.


                            Please let us know if there are any other ways we can help.
                            Last edited by NinjaTrader_JessicaP; 04-06-2017, 08:26 AM.
                            Jessica P.NinjaTrader Customer Service

                            Comment


                              #15
                              Hello Camdo and tradesmart,

                              This feature is being reviewed by the product management team and has been assigned the following unique tracking ID


                              For control of drawing objects, SFT-2100

                              For anchor points/read only, SFT-2139



                              Please let us know if there is any other way we can help.
                              Jessica P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Sparkyboy, Today, 10:57 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post Sparkyboy  
                              Started by TheMarlin801, 10-13-2020, 01:40 AM
                              21 responses
                              3,916 views
                              0 likes
                              Last Post Bidder
                              by Bidder
                               
                              Started by timmbbo, 07-05-2023, 10:21 PM
                              3 responses
                              152 views
                              0 likes
                              Last Post grayfrog  
                              Started by Lumbeezl, 01-11-2022, 06:50 PM
                              30 responses
                              809 views
                              1 like
                              Last Post grayfrog  
                              Started by xiinteractive, 04-09-2024, 08:08 AM
                              3 responses
                              11 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Working...
                              X