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

    #16
    Hello tkaboris,

    Thanks for your notes.

    Yes, you could configure the custom Series in that way.

    If a value is not being assigned to the OBBullishLowerPrice[0] custom Series variable on the current bar then OBBullishLowerPrice[0] will return a value of 0.

    When a value is assigned to OBBullishLowerPrice[0] on the current bar then OBBullishLowerPrice[0] will return the value assigned to it on that bar.

    See this help guide page for more information about custom Series<T> variables: https://ninjatrader.com/support/help...t8/seriest.htm

    "...i evaluate if close < OBBullishLowerPrice​"

    As noted in my previous post, this condition is not becoming true since Closes[iDataSeriesIdx][0] is evaluating greater than OBBullishLowerPrice[0] which is why RemoveDrawObject() is not called.
    Brandon H.NinjaTrader Customer Service

    Comment


      #17
      i see i prints at the time of draw object everything is printed right including OBBullishLowerPrice​. However once i am in next condition OBBullishLowerPrice​ is 0 and then it prints a really previous OBBullishLowerPrice​ level, and not the one i set earlier in the first condition. I thought OBBullishLowerPrice should stay the same

      Code:
      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];
                          Draw.Dot(this, "tag33", true, 0, Low[0] - TickSize, Brushes.Red);
      //                    Draw.Rectangle( int startBarsAgo, double startY, int endBarsAgo, double endY, Brush brush, Brush areaBrush, int areaOpacity)
                          Print("==== Before Draw()=======");
                          Print("tag before Draw():"+tagobbull);
                          Print("OBBullishUpperPrice[0] before Draw():"+OBBullishUpperPrice[0]);
                          Print("OBBullishLowerPrice[0] before Draw():"+OBBullishLowerPrice[0]);
                          Print("==== end Before Draw()=======");
                          Draw.Rectangle(this, tagobbull, false, Time[0], OBBullishUpperPrice[0], Times[iDataSeriesIdx][0].AddDays(1), OBBullishLowerPrice[0], Brushes.Blue, Brushes.Blue, 25, true);
      //                    Draw.Rectangle(this, tagobbull, false, Times[0][0], OBBullishUpperPrice[0], Times[iDataSeriesIdx][0].AddDays(1), OBBullishLowerPrice[0], Brushes.Blue, Brushes.Blue, 25, true);
                          Print("==== After Draw()=======");
                          Print("tag before Draw():"+tagobbull);
                          Print("OBBullishUpperPrice[0] before Draw():"+OBBullishUpperPrice[0]);
                          Print("OBBullishLowerPrice[0] before Draw():"+OBBullishLowerPrice[0]);
                          Print("==== end After Draw()=======");
      
                      }
      
                      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=========");
                        }  ​
      Last edited by tkaboris; 10-05-2023, 12:54 PM.

      Comment


        #18
        Hello tkaboris,

        Thanks for your notes.

        "I thought OBBullishLowerPrice should stay the same"

        Since this is a Series<double> variable, each bar will hold a different value.

        For example, if you assign a value to the Series<double> variable OBBullishLowerPrice[0] on one bar, it will have that value for that bar.

        Say you assign a value of 100 to ​OBBullishLowerPrice[0] on bar 1 and then print OBBullishLowerPrice[0] on that same bar. You will see the value 100 return when printing that variable.

        If on the next bar (bar 2) you do not assign a value to the variable, then OBBullishLowerPrice[0] would return a value of 0 for bar 2 and OBBullishLowerPrice[1] would return a value of 100, since that value 100 was assigned to the Series<double> variable 1 bar ago.

        Note how we pass a barsAgo value of 1 when calling OBBullishLowerPrice[1] to access the value assigned to the variable on the previous bar (bar 1).

        See this help guide page detailing Series<double> variables: https://ninjatrader.com/support/help...t8/seriest.htm

        A regular double variable would need to be used if you want that variable to hold the same value as multiple bars pass since assigning a value to the variable. Or, you would need to modify your logic to assign the value to the Series<double variable> on each bar update.
        Brandon H.NinjaTrader Customer Service

        Comment


          #19
          ok i changed to
          private double OBBullishLowerPrice;
          OBBullishLowerPrice = Lows[iDataSeriesIdx][0];

          but now it seems condition for removal needs to be updated, i think. Becacuse like on this screenshot, previous drawn one doesnt get removed... only last one
          Closes[iDataSeriesIdx][0] < OBBullishLowerPrice

          What can i do?
          Thank you

          Click image for larger version

Name:	image.png
Views:	55
Size:	592.7 KB
ID:	1271681

          Comment


            #20
            Hello tkaboris,

            Thanks for your notes.

            Since the OBBullishLowerPrice variable is now a regular double variable, it will only hold the last price that was assigned to it.

            You would need to further debug the logic of your script by adding prints and evaluating those prints in the Output window to understand exactly how your custom logic is working.

            Once you understand how your custom logic is working when the script is run, you could modify the script to suit your specific goals.

            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


              #21
              I see whats going on
              when price crosses below second instance(screenshot above) is true, close < OBBullishLowerPrice, when it crosses below first instance close < OBBullishLowerPrice and OBBullishLowerPrice is the same as second instance, nothing is there and nothing gets removed.
              when second instance got executed OBBullishLowerPrice needs to go back to first instancce, but how?

              Comment


                #22
                Hello tkaboris,

                Thanks for your notes.

                As stated in my previous post a regular double variable will only hold the last price that you assigned to it.

                Something you could consider is implementing another double variable to hold the value of the first drawn object and use your current double variable to hold the value you are assigning to it for the second drawn object. Then create conditions that checks if the Close price you noted goes below each of the variables and call RemoveDrawObject() to remove a drawing object from the chart. You would have to pass in the exact tag name being used for the first draw object when calling RemoveDrawObject() to remove that specific draw object from the chart. You would have to pass in the exact tag name being used for the second draw object when calling RemoveDrawObect() to remove that second specific draw object from the chart.

                Note that it will be up to you to come up with the specific custom logic to accomplish your overall goals.
                Brandon H.NinjaTrader Customer Service

                Comment


                  #23
                  what if there will be 10 rectangles drawn then i need to implement 10 variables?
                  Why not use series ?

                  Comment


                    #24
                    Hello tkaboris,

                    Thanks for your notes.

                    You could consider using a Series<double> variable.

                    Note that Series<double> variables will hold the value assigned to the on the specific bar you are assigning a value to the variable. See post # 18.

                    To access values assigned to the Series<double> variable on previous bars, you would need to pass in the barAgo value you want to access the Series<double> value for.

                    Passing a barsAgo value of 0 into the Series<double> will access the value assigned to the variable on the current bar. Passing a barsAgo value of 1 into the Series<double> will access the value assigned to it on the previous bar. Passing a barsAgo value of 2 into the Series<double> will access the value assigned to it 2 bars prior to the current bar on the chart, and so on.
                    Brandon H.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by pibrew, Today, 06:37 AM
                    0 responses
                    0 views
                    0 likes
                    Last Post pibrew
                    by pibrew
                     
                    Started by rbeckmann05, Yesterday, 06:48 PM
                    1 response
                    12 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
                    10 views
                    0 likes
                    Last Post burtoninlondon  
                    Started by AaronKoRn, Yesterday, 09:49 PM
                    0 responses
                    15 views
                    0 likes
                    Last Post AaronKoRn  
                    Working...
                    X