Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Looping through DrawObjects shown in Guide doesn't work?

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

    #16
    Hello hillborne, thanks for your reply.

    The only thing I have to do to make State.RealTime show up again is remove and re-add the indicator. Removing the Print statements does not affect the way this works. You can also try to deleting the NinjaScript generated code and compiling again, this will re-generate the code.

    Comment


      #17
      Hi Chris,

      I recorded some video of what's happening.

      The first time I start up NT and connect and add the indicator, it does print all the price anchors. After changing the code, saving, compiling it does not work until restarting and reconnecting. Which means after every edit, I have to wait several minutes in order to test it again.

      I tried re-adding the indicator like you suggested but no luck.

      Do you see anything in the video that I'm doing wrong?

       

      Comment


        #18
        Hi hillborne, thanks for showing me. I was able to reproduce the problem this time. I'll ask my supervisor on the issue.

        Thanks in advance for your patience.

        Comment


          #19
          Hi hillborne,

          Our development team has already visited this issue and they decided to leave this issue of manually drawn objects not being available. We have a feature request open to add an event method that will trigger when the DrawObjects collection is changed, SFT-1358 Ill add a vote to this feature for you. Unfortunately, the draw object must be drawn by the script.

          Comment


            #20
            Hi Chris,

            Well, I'm glad it's there's not something wrong with my software or sanity!

            However, I'm not sure that issue is the same thing here. After running the code the first time, nothing changed in the DrawObjects that I could tell.

            You're saying that if the lines were script-drawn I wouldn't have the same problem?

            Comment


              #21
              Hello hillborne, thanks for your reply.

              The only ways around the issue would be to either have a script draw the lines or use the example I linked earlier, in my tests, this event method was called for every user drawn line:

              Comment


                #22
                I am having the same issue. I have horizontal lines that were manually placed on the chart already. I want to programmatically get the brush information for each line.

                1. "draw is DrawingTools.HorizontalLine" returns false in the "for loop"
                2. The code in https://forum.ninjatrader.com/forum/...jE3MjI5NTcxOTM. does not work (in fact it crashes my NinjaTrader when compiled).
                3. I can get the type with "if (draw.GetType().Name == "HorizontalLine"){"
                4. In Visual Studio I see that the "draw" object has a Brush in it, but I cannot access it via code.

                Is there a way to get to the Brush information on horizontal lines that were added manually and already exist before the indicator is run?

                Comment


                  #23
                  Hello cannotfindname,

                  Thank you for your inquiry.

                  I am able to get this information for Horizontal Lines drawn manually on the chart (before the indicator is run as well) using the following code:

                  Code:
                  List<IDrawingTool> drawingTools = DrawObjects.ToList();
                  for (int index = 0; index < drawingTools.Count; index++)
                  {
                  if (drawingTools[index] is DrawingTools.HorizontalLine)
                  {
                  DrawingTools.HorizontalLine myDraw = drawingTools[index] as DrawingTools.HorizontalLine;
                  
                  Print("Hline object tag: " + myDraw.Tag + ", HLineBrush: " + myDraw.Stroke.Brush + ", userDrawn: " + myDraw.IsUserDrawn);
                  }
                  }
                  Last edited by NinjaTrader_Gaby; 08-08-2024, 10:03 AM.

                  Comment


                    #24
                    Hi, I tried your code and got a compiler error: "The name 'drawingTools' does not exist in the current context CS0103".

                    My code has the statement "using NinjaTrader.NinjaScript.DrawingTools;"

                    My NinjaTrader version is "8.1.1.6 64-bit". I've noticed that some other examples I've found that were built for version 7 do not work with mine. Not sure if that makes a difference or not here.

                    Comment


                      #25
                      Hello,

                      My apologies, this code is for NinjaTrader 8 however in my post I accidentally omitted this line of code you need to add before the for loop:

                      Code:
                      List<IDrawingTool> drawingTools = DrawObjects.ToList();

                      Comment


                        #26
                        Thanks, that line solved that particular issue. However, "if (drawingTools[index] is DrawingTools.HorizontalLine)" does not find any horizontal lines. If I use "if (drawingTools[index].GetType().Name == "HorizontalLine")" then that finds the lines, but "DrawingTools.HorizontalLine myDraw = drawingTools[index] as DrawingTools.HorizontalLine" gives me a "myDraw" = null

                        Comment


                          #27
                          Hello,

                          Are you applying the script to a chart that has HorizontalLine objects?

                          Below I am attaching a sample script that works when I test it out, and a video demonstrating me testing out the script.

                          World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.
                          Attached Files

                          Comment


                            #28
                            It's working now. But it seems that it didn't have anything to do with the code. Here is what happened:
                            - I used your code and it did not work
                            - I then duplicated my chart and put the indicator on the new chart
                            - I removed all other indicators on that chart. It still didn't work.
                            - I right clicked the chart and went into "Drawing tools | Drawing objects"
                            - In the list I noticed that there were two objects left from the indicators that I had deleted
                            - I deleted those objects
                            - I removed your indicator and added it again. Now it worked!

                            That generally seems to work. I've had to restart NinjaTrader a couple of times but I think that's because of something hanging internally when I get a runtime error and kill it from Visual Studio (re-attaching the process doesn't seem to help there).

                            Thanks for all your help.

                            Comment


                              #29
                              I've found this way to reproduce the issue. Originally I created a test indicator that forced an error:
                              Code:
                                      protected override void OnBarUpdate()
                                      {
                                          string x = null;
                                          // Generate a runtime error
                                          x.ToUpper();
                                      }​
                              Once I ran that then the HorizontalLineDetectExample stopped detecting the horizontal line (i.e. "if (drawingTools[index] is DrawingTools.HorizontalLine)" would not find a line).

                              Adding an object manually and then removing it using the right-click menus fixes the issue until it is compiled again.

                              I made a video of it but the video is too large to upload



                              Comment


                                #30
                                Aaaahhh. I am able to reproduce the issue as I mentioned previously, but I've found that I don't have to go through all those shenanigans of adding and deleting an object, or even removing the indicator after a recompile. I can simply select the chart and hit "F5". That reloads the indicator and the DrawObjects data is filled in correctly.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                650 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                370 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                109 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                574 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                577 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X