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

check if draw object exists

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

    check if draw object exists

    is there a way to see if a draw object exits. I don't need to look I want to see if it exists by tag name

    #2
    Hello ballboy11,

    Thanks for the note.

    There exists the DrawObjects[] collection to get all of the draw objects applied to the chart:

    https://ninjatrader.com/support/help...rawobjects.htm

    That is a good way to find a drawing object by tag name.

    Alternatively, please see this example where I loop through all of the drawing objects on the chart by searching through the ChartPanel.ChartObjects collection on line 154 in OnRender(). This example finds the draw object by its type.

    This indicator will read the horizontal lines that you have applied to a chart and display the price at which that line sits.


    Please let us know if we may be of any further assistance.
    Last edited by NinjaTrader_ChrisL; 05-15-2019, 08:22 AM.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Chris, can you correct that 2nd link? i cant find which code you refer

      Comment


        #4
        Hi TazoTodua, Thanks, the link has been updated.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hello,

          from the link with looping to find specific draw object I got help for what I need and I use as name for the drawingobjects the price where it is drawn so that I can refer later to this drawobject by price. But I work round many hours and can´t fix one problem: how can one work with the tagname/price to compare with current price like if(High[0]>"drawobjectname/tagname/price") then Remove(....) If High[0]> ???

          Thank you!
          Tony

          Comment


            #6
            Hello Tony,

            You can reference a Drawing object by name with DrawObjects["YOURTAG"] and you can access the Anchors of the Drawing Object to see where it is drawn.
            From there you could use the tag with RemoveDrawObject to remove that object from the chart.

            Below is an example showing how to access Anchors of a DrawObject.

            Code:
            if (DrawObjects["Dot"] != null)
            {
                foreach (ChartAnchor anchor in DrawObjects["Dot"].Anchors)
                    Print(anchor.Price);
            }
            We look forward to assisting.
            JimNinjaTrader Customer Service

            Comment


              #7
              Hi,

              I have created a simple indicator to detect a horizontal line. The original value of the line is set to 1000. When a line is drawn or moved, the anchor price of the horizontal is shown and updated. However, when I delete the line, how do I get it to reset to 1000? Thanks your assistance. Code below.

              public class HorizontalLineDetector : Indicator
              {

              // Declare variables
              HorizontalLine HL;
              private double HLValue = 1000 ;



              protected override void OnStateChange()
              {
              if (State == State.SetDefaults)
              {
              Description = @"Enter the description for your new custom Indicator here.";
              Name = "HorizontalLineDetector";
              Calculate = Calculate.OnBarClose;
              IsOverlay = true;
              DisplayInDataBox = false;
              DrawOnPricePanel = true;
              DrawHorizontalGridLines = true;
              DrawVerticalGridLines = true;
              PaintPriceMarkers = false;
              ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
              //Disable this property if your indicator requires custom values that cumulate with each new market data event.
              //See Help Guide for additional information.
              IsSuspendedWhileInactive = true;
              }
              else if (State == State.Configure)
              {
              }
              }

              protected override void OnBarUpdate()
              {
              //Add your custom indicator logic here.
              }

              protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
              {

              foreach (Gui.NinjaScript.IChartObject thisObject in ChartPanel.ChartObjects)
              {

              if(thisObject is NinjaTrader.NinjaScript.DrawingTools.HorizontalLin e)
              {
              HL = thisObject as NinjaTrader.NinjaScript.DrawingTools.HorizontalLin e;
              HLValue = HL.StartAnchor.Price;
              }
              }

              Print ("HLValue : ");
              Print (HLValue);

              }




              }


              My code is highlighted in purple. I just copied and pasted here. I would also appreciate it if you could share with me the way to share a code so it shows up as properly formatted as above post #6.

              Comment


                #8
                Hello Rainmakersg,

                You can reset the variable before entering the loop. If the line is found, the variable will be updated to the line's anchor. If the line is not found, the variable will remain at the initial value.
                JimNinjaTrader Customer Service

                Comment


                  #9
                  Hi Jim, thanks so much

                  Can you share how to paste a code so it is properly formatted like in post #6 above?

                  Comment


                    #10
                    Hello Rainmakersg,

                    There is an issue with the VBulletin forum that we use that affects formatting code when we paste in.

                    I typically copy snippets and paste them in a [CODE] block, and then I press the space bar to format the code nicely.
                    JimNinjaTrader Customer Service

                    Comment


                      #11
                      Hi Jim, you mean you use the space bar to space out the tabs line by line?

                      Comment


                        #12
                        Yes, when I paste onto a forum message, the formatting is lost, and I use the space bar to format the code I post after I paste it in [CODE] blocks.
                        JimNinjaTrader Customer Service

                        Comment


                          #13
                          Thanks Jim. It's so tedious...

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by GLFX005, Today, 03:23 AM
                          0 responses
                          2 views
                          0 likes
                          Last Post GLFX005
                          by GLFX005
                           
                          Started by XXtrader, Yesterday, 11:30 PM
                          2 responses
                          11 views
                          0 likes
                          Last Post XXtrader  
                          Started by Waxavi, Today, 02:10 AM
                          0 responses
                          7 views
                          0 likes
                          Last Post Waxavi
                          by Waxavi
                           
                          Started by TradeForge, Today, 02:09 AM
                          0 responses
                          14 views
                          0 likes
                          Last Post TradeForge  
                          Started by Waxavi, Today, 02:00 AM
                          0 responses
                          3 views
                          0 likes
                          Last Post Waxavi
                          by Waxavi
                           
                          Working...
                          X