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

Help with removing objects

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

    Help with removing objects

    I want to remove a bullish up object once price closed below OBBullishLowerPrice[0] and currently its not working, its not removing it. So the object stays on the chart until Price closes below.

    if(Close[0] > Open[0] && Close[0] > Open[1] && Low[0] < Low[1] && Close[1] < Open[1] && Close[0] > High[1])
    {
    OBBullishUpperPrice[0] = High[0];
    OBBullishLowerPrice[0] = Low[0];

    Draw.Rectangle(this, "DotHZ"+CurrentBar, false, Times[0][0], OBBullishLowerPrice[0], Times[iDataSeriesIdx][0].AddDays(1), OBBullishUpperPrice[0], Brushes.Blue, Brushes.Blue, 25, true);
    if(Close[1] < OBBullishLowerPrice[0])
    {
    RemoveDrawObject("DotHZ"+CurrentBar);
    }
    Print(OBBullishLowerPrice[0]);
    }​

    #2
    Hello tkaboris,

    Thanks for your post.

    RemoveDrawObject() would be used to remove a drawing object from the chart window in a NinjaScript strategy.

    You would need to make sure that you are passing in the exact tag name of the Draw object you want to remove in the RemoveDrawObject() method.

    If the RemoveDrawObject() method is not removing the Draw object from the chart then you might not be passing in the correct tag name for the Draw object. You should use prints to confirm exactly how your logic in the script is behaving.

    See this help guide page for more information about RemoveDrawObject(): https://ninjatrader.com/support/help...drawobject.htm

    Here is a reference sample demonstrating using RemoveDrawObject(): https://ninjatrader.com/support/help...s_from_the.htm

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      I am confused on how to print my tag?
      i am using an unique tag "DotHZ"+CurrentBar,
      How can i print the tag being used?

      Comment


        #4
        Hello tkaboris,

        Thanks for your notes.

        One line above where you are calling the Draw.Rectangle() method, print out the tag name you are passing into the Draw method and note the print in the NinjaScript Output window

        One line above where you are calling RemoveDrawObject, print out the tag name you are passing into the RemoveDrawObject() method to see how it is evaluating.

        You could loop through the DrawObjects collection to find the tag name of a drawing object.

        DrawObjects: https://ninjatrader.com/support/help...rawobjects.htm
        IDrawingTool: https://ninjatrader.com/support/help...rawingtool.htm
        .
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Hi it prints tag DotHZ5997
          I want to remove all those blue objects and i guess my condition is not evaluating to true. i guess its a wrong condition because its only looking for last bar but i need if any bar price closes below then remove object, otherwise it stays...
          OBBullishLowerPrice[0] evaluates right levels

          if(Close[1] < OBBullishLowerPrice[0])
          - remove object

          Click image for larger version

Name:	image.png
Views:	106
Size:	30.4 KB
ID:	1271431

          Comment


            #6
            Hello tkaboris,

            Thanks for your notes.

            "it prints tag DotHZ5997"

            Does it print this tag name in the print one line above calling Draw.Rectangle() to draw the object on the chart and print the same exact tag name in the print placed one line above where you are calling RemoveDrawObject()?

            CurrentBar refers to the bar index number of the current bar on the chart.

            If you are not calling Draw.Rectangle() and RemoveDrawObject() on the same bar then likely "DotHZ"+CurrentBar would not be the same when calling RemoveDrawObject() as it is when calling Draw.Rectangle() since the methods are called on different bars.

            For example, if you call Draw.Rectangle() with the tag name "DotHZ"+CurrentBar on say bar 10, this would have a tag name of "DotHZ10". Then, say you call RemoveDrawObject() with the tag name "DotHZ"+CurrentBar after 5 bars have passed (bar 15). In this case, you would be calling RemoveDrawObject() for a draw object with the tag name "DotHZ15" which is not the exact same tag name as the Draw.Rectangle() tag name (DotHZ10) when this method was called.

            You would have to call RemoveDrawObject() for each draw object that you want to remove and pass in the tag name of each Draw object you want to remove into the RemoveDrawObject() methods you call.

            Note that the tag being passed into RemoveDrawObject() would need to be exactly the tag for the individual object

            For example, if you had say 3 draw objects you want to remove with tag names of say 'Tag1', 'Tag2', and 'Tag3' then you would have to call RemoveDrawObject three times, once for each Draw object.

            RemoveDrawObject(Tag1);
            RemoveDrawObject(Tag2);
            RemoveDrawObject(Tag3);



            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              HI
              I am creating a tag with name OBBull_7d0220f0-fa3e-496c-85a2-c4ab560f9a89_6126 with level OBBullishLowerPrice[0] in Draw.15666.25

              then in condition when close is less then level, i want to remove object.
              However when price closes below it doesnt remove object and took like 6 bars before it removed but it prints a different level.

              if (DrawObjects[tagobbull] != null && DrawObjects[tagobbull] is DrawingTools.Rectangle && Closes[iDataSeriesIdx][0] < OBBullishLowerPrice[0])

              Below are my prints

              tagname in draw.rectangleOBBull_7d0220f0-fa3e-496c-85a2-c4ab560f9a89_6126
              time in draw:9/15/2023 4:08:00 AM
              OBBullishLowerPrice[0] in Draw.15666.25
              ======= In Condition=========
              test remove Time: 9/15/2023 4:27:00 AM
              closes idx15667.75
              OBBullishLowerPrice[0] in Condition15676.5
              tagname in draw.rectangle in conditionOBBull_7d0220f0-fa3e-496c-85a2-c4ab560f9a89_6126
              tag removed
              ======= End In Condition=========


              Code:
              protected override void OnBarUpdate()
                      {
                          // Only operate on selected data series type
                          if (BarsInProgress != iDataSeriesIdx || CurrentBars[iDataSeriesIdx] < 4) return;
              
                          if(Close[0] > Open[0] && Close[0] > Open[1] && Low[0] < Low[1] && Close[1] < Open[1] && Close[0] > High[1])
                              {
                                  tagobbull = "OBBull_" + InstanceId + "_" + CurrentBars[iDataSeriesIdx];
                                  OBBullishUpperPrice[0] = High[0];
                                  OBBullishLowerPrice[0] = Low[0];
                                  Draw.Rectangle(this, tagobbull, false, Times[0][0], OBBullishLowerPrice[0], Times[iDataSeriesIdx][0].AddDays(1), OBBullishUpperPrice[0], Brushes.Blue, Brushes.Blue, 25, true);
                                  Print("tagname in draw.rectangle"+tagobbull);
                                  Print("time in draw:"+ Time[0]);
                                  Print("OBBullishLowerPrice[0] in Draw."+OBBullishLowerPrice[0]);
              
                              }
              
                              if (DrawObjects[tagobbull] != null && DrawObjects[tagobbull] is DrawingTools.Rectangle && Closes[iDataSeriesIdx][0] < OBBullishLowerPrice[0])
                                    {
                                        Print("======= In Condition=========");
                                        Print("test remove Time: " + Time[0]);
                                        Print("closes idx"+Closes[iDataSeriesIdx][0]);
                                        Print("OBBullishLowerPrice[0] in Condition"+OBBullishLowerPrice[0]);
                                        Print("tagname in draw.rectangle in condition"+tagobbull);
                                        RemoveDrawObject(tagobbull);
                                        Print("tag removed");
                                        Print("======= End In Condition=========");
                                    }  ​
              }

              Comment


                #8
                I might not be drawing correctly.
                I want to draw on engulfing bullish bar with its high and low. Am I doing it right?
                I want to draw based on the high low bar that is marked by red dot.

                Click image for larger version

Name:	image.png
Views:	106
Size:	13.8 KB
ID:	1271445
                Last edited by tkaboris; 10-04-2023, 10:57 AM.

                Comment


                  #9
                  Hello tkaboris,

                  Thanks for your notes.

                  You are calling the Draw.Rectangle() method correctly.

                  If you are giving the Draw object being drawn on the chart a tag name of "OBBull_7d0220f0-fa3e-496c-85a2-c4ab560f9a89_6126" then you would have to call RemoveDrawObject() and pass in that exact tag name "OBBull_7d0220f0-fa3e-496c-85a2-c4ab560f9a89_6126" for the string tag argument when calling RemoveDrawObject(string tag) to remove that specific draw object from the chart.

                  To understand how your conditions in the script are evaluating and calling Draw.Rectangle() and RemoveDrawObject(), you would have to further debug your script's logic by adding more prints.

                  One line above the condition to call Draw.Rectangle(), print out each value being used in the condition.

                  One line above the condition to call RemoveDrawObject() print out each value being used in the condition.

                  Note the print outputs in the NinjaScript Output window to see how the conditions are evaluating.

                  Below is a link to a forum post that demonstrates how to use prints to understand behavior.
                  https://ninjatrader.com/support/foru...121#post791121

                  Brandon H.NinjaTrader Customer Service

                  Comment


                    #10
                    HI
                    here are prints before and after draw. but prints before and after removedraw not displaying. maybe my condition is wrong?

                    ==== Before Draw()=======
                    tag before Draw():OBBull_f08e3c77-f7ff-42c5-98e0-08fdded779c2_5997
                    OBBullishUpperPrice[0] before Draw():15712.5
                    OBBullishLowerPrice[0] before Draw():15710.5
                    ==== end Before Draw()=======
                    ==== After Draw()=======
                    tag before Draw():OBBull_f08e3c77-f7ff-42c5-98e0-08fdded779c2_5997
                    OBBullishUpperPrice[0] before Draw():15712.5
                    OBBullishLowerPrice[0] before Draw():15710.5
                    ==== end After Draw()=======​

                    Prints that dont print in this logic

                    if (DrawObjects[tagobbull] != null && DrawObjects[tagobbull] is DrawingTools.Rectangle && Closes[iDataSeriesIdx][0] < OBBullishLowerPrice[0])
                    {
                    Print("==== Before RemoveDraw()=======");
                    Print("tag before Draw():"+tagobbull);
                    Print("OBBullishUpperPrice[0] :"+OBBullishUpperPrice[0]);
                    Print("OBBullishLowerPrice[0] :"+OBBullishLowerPrice[0]);
                    Print("Closes[iDataSeriesIdx][0] :"+Closes[iDataSeriesIdx][0]);
                    Print("==== end Before RemoveDraw()=======");
                    RemoveDrawObject(tagobbull);
                    Print("==== After RemoveDraw()=======");
                    Print("tag before Draw():"+tagobbull);
                    Print("OBBullishUpperPrice[0] :"+OBBullishUpperPrice[0]);
                    Print("OBBullishLowerPrice[0] :"+OBBullishLowerPrice[0]);
                    Print("Closes[iDataSeriesIdx][0] :"+Closes[iDataSeriesIdx][0]);
                    Print("==== end After RemoveDraw()=======");
                    }​

                    Comment


                      #11
                      I managed to get some prints but it didnt actaully plotted on the chart. OBBullishUpperPrice these levels are different when i make a draw and before i remove the draw

                      ==== Before Draw()=======
                      tag before Draw():OBBull_0efaae40-9f13-4d27-9075-3d8608e0ceb6_1665
                      OBBullishUpperPrice[0] before Draw():15629
                      OBBullishLowerPrice[0] before Draw():15604.5
                      ==== end Before Draw()=======
                      ==== After Draw()=======
                      tag before Draw():OBBull_0efaae40-9f13-4d27-9075-3d8608e0ceb6_1665
                      OBBullishUpperPrice[0] before Draw():15629
                      OBBullishLowerPrice[0] before Draw():15604.5
                      ==== end After Draw()=======​

                      ==== Before RemoveDraw()=======
                      tag before Draw():OBBull_0efaae40-9f13-4d27-9075-3d8608e0ceb6_1665
                      OBBullishUpperPrice[0] :15666.25
                      OBBullishLowerPrice[0] :15653
                      Closes[iDataSeriesIdx][0] :15634
                      ==== end Before RemoveDraw()=======
                      ==== After RemoveDraw()=======
                      tag before Draw():OBBull_0efaae40-9f13-4d27-9075-3d8608e0ceb6_1665
                      OBBullishUpperPrice[0] :15666.25
                      OBBullishLowerPrice[0] :15653
                      Closes[iDataSeriesIdx][0] :15634
                      ==== end After RemoveDraw()=======​

                      Comment


                        #12
                        Hello tkaboris,

                        Thanks for your notes.

                        Did you add prints to your script to understand how the conditions to call the RemoveDrawObject() in your script to understand how the condition is evaluating?

                        From my previous post:

                        "One line above the condition to call RemoveDrawObject() print out each value being used in the condition."

                        Also, add prints one line above your RemoveDrawObject() method that prints out the tag name being passed into RemoveDrawObject() is evaluating before the method is called.

                        For example:
                        Code:
                        Print("DrawObjects[tagobull] != null " + (DrawObjects[tagobbull] != null));
                        Print("DrawObjects[tagobbull] is DrawingTools.Rectangle: " + (DrawObjects[tagobbull] is DrawingTools.Rectangle));
                        Print("Closes[iDataSeriesIdx][0]: " + Closes[iDataSeriesIdx][0]);
                        Print("OBBullishLowerPrice[0]: " + OBBullishLowerPrice[0]);
                        if (DrawObjects[tagobbull] != null && DrawObjects[tagobbull] is DrawingTools.Rectangle && Closes[iDataSeriesIdx][0] < OBBullishLowerPrice[0])
                        {
                        Print("======= In RemoveDrawObject() Condition=========");
                        Print("test remove Time: " + Time[0]);
                        Print("tagname in draw.rectangle in condition: " + tagobbull);
                        RemoveDrawObject(tagobbull);
                        Print("tag removed");
                        Print("======= End of RemoveDrawObject() Condition=========");
                        } ​​
                        Review this forum thread linked below which demonstrates how to use prints to understand behavior.
                        https://ninjatrader.com/support/foru...121#post791121
                        Brandon H.NinjaTrader Customer Service

                        Comment


                          #13
                          HI i updated my prints in previous message and also here
                          the drawn levels are 15695 and 15684
                          and price closed well below that but it didnt remove the object

                          ==== Before Draw()=======
                          tag before Draw():OBBull_096d7b71-36d4-4356-ac95-1735bff446b0_5330
                          OBBullishUpperPrice[0] before Draw():15695.75
                          OBBullishLowerPrice[0] before Draw():15684
                          ==== end Before Draw()=======
                          ==== After Draw()=======
                          tag before Draw():OBBull_096d7b71-36d4-4356-ac95-1735bff446b0_5330
                          OBBullishUpperPrice[0] before Draw():15695.75
                          OBBullishLowerPrice[0] before Draw():15684
                          ==== end After Draw()=======
                          DrawObjects[tagobull] != null True
                          DrawObjects[tagobbull] is DrawingTools.Rectangle: True
                          Closes[iDataSeriesIdx][0]: 15693.75
                          OBBullishLowerPrice[0]: 15684
                          DrawObjects[tagobull] != null True
                          DrawObjects[tagobbull] is DrawingTools.Rectangle: True
                          Closes[iDataSeriesIdx][0]: 15695.75
                          OBBullishLowerPrice[0]: 15675.75
                          DrawObjects[tagobull] != null True
                          DrawObjects[tagobbull] is DrawingTools.Rectangle: True
                          Closes[iDataSeriesIdx][0]: 15689.75
                          OBBullishLowerPrice[0]: 0
                          DrawObjects[tagobull] != null True
                          DrawObjects[tagobbull] is DrawingTools.Rectangle: True
                          Closes[iDataSeriesIdx][0]: 15690.5
                          OBBullishLowerPrice[0]: 0
                          DrawObjects[tagobull] != null True
                          DrawObjects[tagobbull] is DrawingTools.Rectangle: True
                          Closes[iDataSeriesIdx][0]: 15686.75
                          OBBullishLowerPrice[0]: 0
                          DrawObjects[tagobull] != null True
                          DrawObjects[tagobbull] is DrawingTools.Rectangle: True
                          Closes[iDataSeriesIdx][0]: 15684.25
                          OBBullishLowerPrice[0]: 0
                          DrawObjects[tagobull] != null True
                          DrawObjects[tagobbull] is DrawingTools.Rectangle: True
                          Closes[iDataSeriesIdx][0]: 15686.25
                          OBBullishLowerPrice[0]: 0
                          DrawObjects[tagobull] != null True
                          DrawObjects[tagobbull] is DrawingTools.Rectangle: True
                          Closes[iDataSeriesIdx][0]: 15682.25
                          OBBullishLowerPrice[0]: 15602.75
                          DrawObjects[tagobull] != null True
                          DrawObjects[tagobbull] is DrawingTools.Rectangle: True
                          Closes[iDataSeriesIdx][0]: 15680.25
                          OBBullishLowerPrice[0]: 0
                          15691.75
                          distance between15703.75
                          distance 1
                          zzCurrHB15707.25
                          zzLastHB15709.25
                          DrawObjects[tagobull] != null True
                          DrawObjects[tagobbull] is DrawingTools.Rectangle: True
                          Closes[iDataSeriesIdx][0]: 15678.5
                          OBBullishLowerPrice[0]: 0
                          DrawObjects[tagobull] != null True
                          DrawObjects[tagobbull] is DrawingTools.Rectangle: True
                          Closes[iDataSeriesIdx][0]: 15683.75
                          OBBullishLowerPrice[0]: 0
                          DrawObjects[tagobull] != null True
                          DrawObjects[tagobbull] is DrawingTools.Rectangle: True
                          Closes[iDataSeriesIdx][0]: 15680.5
                          OBBullishLowerPrice[0]: 0
                          DrawObjects[tagobull] != null True
                          DrawObjects[tagobbull] is DrawingTools.Rectangle: True
                          Closes[iDataSeriesIdx][0]: 15674.25
                          OBBullishLowerPrice[0]: 15666.75
                          DrawObjects[tagobull] != null True
                          DrawObjects[tagobbull] is DrawingTools.Rectangle: True
                          Closes[iDataSeriesIdx][0]: 15675.25​





                          Comment


                            #14
                            Hello tkaboris,

                            Thanks for your notes.

                            In the print Output you shared, Closes[iDataSeriesIdx][0] is not evaluating to be less than OBBullishLowerPrice[0] so the condition to call RemoveDrawObject() is not becoming true.

                            From your code:

                            if (DrawObjects[tagobbull] != null && DrawObjects[tagobbull] is DrawingTools.Rectangle && Closes[iDataSeriesIdx][0] < OBBullishLowerPrice[0])
                            {​
                            ...


                            For example, see below from your shared print Output:

                            Closes[iDataSeriesIdx][0]: 15693.75
                            OBBullishLowerPrice[0]: 15684​

                            Closes[iDataSeriesIdx][0]: 15682.25
                            OBBullishLowerPrice[0]: 15602.75​

                            ​Closes[iDataSeriesIdx][0]: 15680.5
                            OBBullishLowerPrice[0]: 0​

                            Closes[iDataSeriesIdx][0]: 15674.25
                            OBBullishLowerPrice[0]: 15666.75​


                            The RemoveDrawObject() method will not become true until every condition to call the method is true and not all your conditions to call RemoveDrawObject() are true since Closes[iDataSeriesIdx][0] is not evaluating to be less than OBBullishLowerPrice[0].
                            Brandon H.NinjaTrader Customer Service

                            Comment


                              #15
                              Did i configure series right?

                              in the condition where i create reqtangle draw i define OBBullishLowerPrice​ and then later in the script i evaluate if close < OBBullishLowerPrice
                              Also i dont understand why sometimes prints print 0 even though there is a rectangle on the chart and it should at least print level
                              OBBullishLowerPrice[0]: 0

                              public Series<double> OBBullishLowerPrice;
                              OBBullishLowerPrice = new Series<double>(this);

                              if(Closes[iDataSeriesIdx][0] > Opens[iDataSeriesIdx][0] && Closes[iDataSeriesIdx][0] > Opens[iDataSeriesIdx][1] && Lows[iDataSeriesIdx][0] < Lows[iDataSeriesIdx][1]
                              && Closes[iDataSeriesIdx][1] < Opens[iDataSeriesIdx][1] && Closes[iDataSeriesIdx][0] > Highs[iDataSeriesIdx][1])
                              {
                              tagobbull = "OBBull_" + InstanceId + "_" + CurrentBars[iDataSeriesIdx];
                              OBBullishUpperPrice[0] = Highs[iDataSeriesIdx][0];
                              OBBullishLowerPrice[0] = Lows[iDataSeriesIdx][0];

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by ageeholdings, Today, 07:43 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post ageeholdings  
                              Started by pibrew, Today, 06:37 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post pibrew
                              by pibrew
                               
                              Started by rbeckmann05, Yesterday, 06:48 PM
                              1 response
                              14 views
                              0 likes
                              Last Post bltdavid  
                              Started by llanqui, Today, 03:53 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post llanqui
                              by llanqui
                               
                              Started by burtoninlondon, Today, 12:38 AM
                              0 responses
                              12 views
                              0 likes
                              Last Post burtoninlondon  
                              Working...
                              X