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

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.
    JimNinjaTrader Customer Service

    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:	275
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.
        JimNinjaTrader Customer Service

        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.
            JimNinjaTrader Customer Service

            Comment


              #7
              Thank you Jim, it works fine!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by bmartz, 03-12-2024, 06:12 AM
              5 responses
              32 views
              0 likes
              Last Post NinjaTrader_Zachary  
              Started by Aviram Y, Today, 05:29 AM
              4 responses
              12 views
              0 likes
              Last Post Aviram Y  
              Started by algospoke, 04-17-2024, 06:40 PM
              3 responses
              28 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by gentlebenthebear, Today, 01:30 AM
              1 response
              8 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by cls71, Today, 04:45 AM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Working...
              X