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 find user drawn object (hor. line)

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

    how to find user drawn object (hor. line)

    Hi,

    I'd like to find all user drawn horizontal lines and use their anchors for some calculations.
    How can I do that?

    Best regards
    Thomas

    #2
    Hello td_910,

    Thank you for your note.

    You would need to loop through the drawing objects collection, find horizontal lines and check they are user drawn, then you can get the line values from the anchors:

    Code:
    foreach (HorizontalLine line in DrawObjects.ToList())
    {
    // Use ToString().Equals() to check the object's Type
    if (line.ToString().Equals("NinjaTrader.NinjaScript.DrawingTools.HorizontalLine") && line.IsUserDrawn == true)
    {
    Print(String.Format("Horizontal Line {0} detected!", line.Tag));
    Print("Line Object: " + line.Tag + " Manually Drawn: " + line.IsUserDrawn);
    Print("Start Bar: " + line.StartAnchor.SlotIndex + " End Bar: " + line.EndAnchor.SlotIndex);
    Print("Price: " + line.StartAnchor.Price + " Time: " + line.EndAnchor.Time);
    }
    }
    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hello Kate,

      Thanks for your help. If I use that code snippet I get the following error:

      "Error on calling 'OnBarUpdate' method on bar 156: Unable to cast object of type 'NinjaTrader.NinjaScript.DrawingTools.Diamond' to type 'NinjaTrader.NinjaScript.DrawingTools.HorizontalLi ne'."

      There are a couple of other chart objects on that chart as well.

      Comment


        #4
        Hello td_910,

        Thank you for your reply.

        Ah yes, that code is specifically expecting the only drawing tools on the chart to be horizontal lines. Try this:


        Code:
        foreach (DrawingTool draw in DrawObjects.ToList())
        {
        if (draw.ToString().Equals("NinjaTrader.NinjaScript.D rawingTools.HorizontalLine") && draw.IsUserDrawn == true)
        {
        if (draw is DrawingTools.HorizontalLine)
        {
        DrawingTools.HorizontalLine line = draw as DrawingTools.HorizontalLine;
        Print(String.Format("Horizontal Line {0} detected!", line.Tag));
        Print("Line Object: " + line.Tag + " Manually Drawn: " + line.IsUserDrawn);
        Print("Start Bar: " + line.StartAnchor.SlotIndex + " End Bar: " + line.EndAnchor.SlotIndex);
        Print("Price: " + line.StartAnchor.Price + " Time: " + line.EndAnchor.Time);
        }
        }
        }
        Please let us know if we may be of further assistance to you.
        Last edited by NinjaTrader_Kate; 06-24-2022, 10:58 AM. Reason: copied an incorrect version of script
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Hello Kate,
          That one gives a compile error:

          NinjaTrader.NinjaScript.DrawingTools.DrawingTool' does not contain a definition for 'StartAnchor' and no extension method 'StartAnchor' accepting a first argument of type 'NinjaTrader.NinjaScript.DrawingTools.DrawingTool' could be found (are you missing a using directive or an assembly reference?)

          Best regards
          Thomas

          Comment


            #6
            Hello td_910,

            Thank you for your reply.

            Looks like I copied and pasted a "inbetween" version of the code - that's my fault! I've updated the code in my prior post.

            Please let us know if we may be of further assistance to you.
            Kate W.NinjaTrader Customer Service

            Comment


              #7
              Many Thanks!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by usazencort, Today, 01:16 AM
              0 responses
              1 view
              0 likes
              Last Post usazencort  
              Started by kaywai, 09-01-2023, 08:44 PM
              5 responses
              603 views
              0 likes
              Last Post NinjaTrader_Jason  
              Started by xiinteractive, 04-09-2024, 08:08 AM
              6 responses
              22 views
              0 likes
              Last Post xiinteractive  
              Started by Pattontje, Yesterday, 02:10 PM
              2 responses
              21 views
              0 likes
              Last Post Pattontje  
              Started by flybuzz, 04-21-2024, 04:07 PM
              17 responses
              230 views
              0 likes
              Last Post TradingLoss  
              Working...
              X