Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

if (draw is DrawingTools.HorizontalLine) Doesn't work

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

    if (draw is DrawingTools.HorizontalLine) Doesn't work

    Hi,

    I am trying to list out all the horizontal lines I have on the chart using the following code

    Code:
    foreach (DrawingTool draw in DrawObjects.ToList())
    {
    
         if (draw is DrawingTools.HorizontalLine)
         {
              Do something here...
         }
    }
    For some reason, it doesn't seem to work.

    In the example here, the same thing is done just with DrawingTools.Line and it works (also when I tried it)



    Thanks for the help!

    #2
    Hello liadmz,

    Thanks for your post.

    I have provided a video demonstration testing this snippet.

    Demo - https://drive.google.com/file/d/11KK...w?usp=drivesdk

    Please note that when we access the DrawObjects collection, we can only expect to be able to read DrawObjects that are fully loaded on the chart. DrawObjects are NinjaScripts as well, so if NinjaScripts are reloaded, the indicator may not find the DrawObjects in the collection until they are fully loaded.

    If you require finding the drawing objects as soon as they are added, you can try an unsupported approach similar to the one linked below.

    https://ninjatrader.com/support/foru...ete#post677423

    We look forward to assisting.

    Comment


      #3
      Hi Jim,

      Thank you for the great explanation.
      I am not sure why the same script won't do the same :/

      This is the script and the output, The objects are found but they are not recognized as horizontal lines

      Is there a time factor involved in this? (those lines were drawn in the past days, manually)

      Click image for larger version

Name:	Untitled.png
Views:	306
Size:	59.1 KB
ID:	1115635


      Thank you!




      Comment


        #4
        Hello liadmz,

        I may suspect that the script is not reloaded or there is a potential installation issue that is causing trouble. With your code, I would expect 2 prints whenever a HorizontalLine is found. We see the line is found in the first print, but we are not seeing the second print.

        Could you test restarting the computer and testing in a clean environment?

        Clean Environment Test:

        Creating a clean environment can be done by following the steps below:
        1. Close NinjaTrader 8, and rename the "NinjaTrader 8" folder in My Documents to something like: "NinjaTrader 8 OLD"
        2. Uninstall NinjaTrader from the Windows Control Panel
        3. Delete the C:\Program Files (x86)\NinjaTrader 8 folder. (DO NOT delete the folder in My Documents)
        4. Reinstall using the installer from http://ninjatrader.com/PlatformDirect
        5. Add your test script and test to confirm if the issue persists there.
        If you ever need to switch back to your original platform, you may do so by closing NinjaTrader and swapping the platform folder names.

        For example, Close NinjaTrader and rename the new "NinjaTrader 8" folder to "NinjaTrader 8 NEW" and the "NinjaTrader 8 OLD" folder to "NinjaTrader 8." Then restart the platform. Simply put: NinjaTrader 8 will always load the "NinjaTrader 8" folder in My Documents.

        If issues are persisting, I may want to get connected with you to observe this behavior. If that is the case, please reach out to me at platformsupport [at] ninjatrader [dot] com with the text "Attn Jim 2714534" Please also include a link to this thread.

        I look forward to assisting.

        Comment


          #5
          Hello Jim,

          I need that my strategy finds a specific horizontal line drawn on my chart (specific tag or name), and then get the price (anchor point) from this horizontal line, and then assign this to a variable. Any idea or example?

          Thanks

          Comment


            #6
            Hello federicoo,

            You can do something like the following:

            Code:
            private double myDbl;
            
            protected override void OnBarUpdate()
            {
                foreach (DrawingTool draw in DrawObjects.ToList())
                {
            
                    if (draw is DrawingTools.HorizontalLine && draw.Tag == "TagToFind")
                    {
                        myDbl = (draw as DrawingTools.HorizontalLine).StartAnchor.Price;
                    }
                }
                ClearOutputWindow();
                Print(myDbl);
            }
            We look forward to assisting.

            Comment


              #7
              Thank you Jim, it works fine!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              601 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              347 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              103 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              559 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              558 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X