Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

DrawingObject Index

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

    #31
    Hello James,

    There isn't anything out of box to do this, you would have to track the drawing tags you would want to remove on your own.

    You could consider tracking the drawing object tags you add in your script inside a List<string>, and then on a new session, you can loop through the list and call RemoveDrawObject for each string in the list, and this will remove all the drawing objects in the list. (The list should then be cleared after the drawing objects have been removed.

    Taking this a step further, you could consider having multiple lists, I.E. 10 lists, and then in OnBarUpdate on Bars.IsFirstBarOfSession, you can update a variable which will represent which list you need to clear. (Then loop through that list and call RemoveDrawObject for each string in that specific list.)

    Comment


      #32
      Thank you, Jim.
      Adding the objects to a List (string) and then remove those at the end of the session. This sounds like it could work for me. Do you have an example of how this would be coded?
      Sorry for the request. I'm a complete novice at coding (trying to learn hands-on).
      Thanks again for your help.
      James

      Comment


        #33
        Hello James,
        You can try as suggested by Jim, or you can refer below thread for 2 methods, one by Paul & other by myself:
        i've run into a situation where signals from an indicator bog down performance and i'ld like to add a &quot;number of days&quot; i.e. 2 to the signal portion of the indicator. i tried using RemoveDrawObject( @&quot;HEsignalUp&quot; + (CurrentBar - SignalsToKeep) ); where SignalsToKeep is set to 500 but this causes major

        Paul's method allows you to draw only defined number of drawing objects & my allows you to remove old objects & keep defined number of new objects.

        Code:
        [INDENT]if (conditions to draw an object)[/INDENT][INDENT=2]{
        myDrawCounter++; // increment draw counter
        
        Draw.Dot(this, "myDot"+myDrawcounter, 0....);
        }[/INDENT][INDENT]
        if (myDrawCounter == 100)[/INDENT][INDENT=2]{
        myDrawCounter == 0; // reset for next 100 objects
        }[/INDENT]
        Code:
        [INDENT]for (int i = 0; i < CurrentBar - 500; i++)[/INDENT][INDENT=2]{
        RemoveDrawObject("HEsignalUp" + i);
        RemoveDrawObject("HEsignalDown" + i);
        }[/INDENT]
        Hope it helps!

        Comment


          #34
          s.knra, thank you.
          I will try and keep it simple for now. Thank you for some direction.
          I think I will try the second option you suggested above and see if I can get a bool to not show history then use the CurrentBar - 500 code.
          Thank you again for all your time in helping us wanting to learn.
          James

          Comment


            #35
            s.knra,
            I figure that with the code below I would need to put in any and all of the object's individual tags (there are multiple different signals which have their own tag). Also, I want to add a bool so if I want to see the history beyond the 500 bars then I can select that. If it is left to false then it will not show the signals beyond 500 bars.

            I guess I'm wondering two things if I can put a bool right in front of the code and two if I put this right under the last DrawObject line of code in the OnBarUpdate.

            for (int i = 0; i < CurrentBar - 500; i++)
            { RemoveDrawObject("HEsignalUp" + i); RemoveDrawObject("HEsignalDown" + i); }

            Thanks again for all of your help

            Edited:
            I tried this and placed it at the bottom of OnBarUpdate. I have SignalBarHistory set as 200. It compiles but when loading the signal indicator it just stays "Calculating" and doesn't load. I comment out the lines of code and then the signal indicator loads. I must be missing something (or a few things. ).

            for (int i = 0; i < CurrentBar - (SignalBarHistory); i++)
            {

            RemoveDrawObject("rhwaimb-sp-tsell" + i); RemoveDrawObject("rhwaimb-sp-ctsell" + i);
            }
            Last edited by laoshr; 10-01-2021, 08:53 PM.

            Comment


              #36
              Hello James,
              Yes, you can keep this for loop inside if statement with bool, so it will run based on your selection.
              SignalBarHistory should be int variable, you can try with fixed number first & see if it works fine. Or if all is good, you may need to convert i to string. While defining draw objects be sure to use exact same tag names. Lastly you can share your code so I can have a look.
              Hope it helps!

              Comment


                #37
                s.kinra,
                Thank you for your reply. I did try adding the bool but that didn't seem to work. I also tried to use just the code I posted above with just the number instead of the int of SignalBars (ie. 200) and that didn't work (the indicator won't load. It just keeps "Calculating" in the upper left corner of the screen). This is what I have right now but for some reason, it won't load.

                if (ShowSignalHistory == false)

                for (int i = 0; i < CurrentBar - (SignalBars); i++)
                {

                RemoveDrawObject("rhwaimb-sp-tsell" + i); RemoveDrawObject("rhwaimb-sp-ctsell" + i);

                }

                P.S.
                I was possibly going to try and change all the DrawObjects (signals) to Plots. I'm not sure if that would make things easier or not?

                Comment


                  #38
                  Hello James,
                  It seems there are huge number of bars loaded so it might take more time to remove objects in loop.
                  Try to remove a small number of objects to see if it works for you or you can reduce the number of days to load from properties.
                  You need below code for if block:-
                  Code:
                  if (ShowSignalHistory == false)[INDENT]{[/INDENT][INDENT]for (int i = 0; i < CurrentBar - (SignalBars); i++)[/INDENT][INDENT=2]{
                  RemoveDrawObject("rhwaimb-sp-tsell" + i);
                  RemoveDrawObject("rhwaimb-sp-ctsell" + i);
                  }[/INDENT][INDENT]}[/INDENT]
                  Hope it helps!

                  Comment


                    #39
                    s.kinra
                    Yes, there are averaging 2000 bars per session on the NQ. I can't get the above code to load with only loading 1 day. Paul stated that Plots would be a better use of resources. I wonder if it might be better to use Plots and then remove the Plots with the for loop or the myDrawCounter? I need to have the option to see the history or not.

                    I can't seem to get the Plot so the user input is only the color, it shows dropdowns for all the settings. Is there a way to limit the user inputs for the Plot?

                    Is removing Plots on the same line as the DrawObjects?


                    Thanks again for helping me with this.
                    James
                    Last edited by laoshr; 10-02-2021, 08:24 PM.

                    Comment


                      #40
                      Hello James,
                      You need to check it by using higher timeframe so the no. of signals / objects are less as it will surely take time to remove all objects & is resource hungry so better use the first method to only draw defined no. of objects when not needed all.
                      No you can't remove plots but you can make them transparent. You can do this by: PlotBrushes[0][0] = Brushes.Transparent;
                      I am attaching a sample code with both methods to remove objects, I would recommend using higher number to retain with second method, it will allow you to understand the performance & you will be able to use either as per sample script. With both options similar results can be obtained and you can then choose the best one for your requirements. I believe first method would be more suitable as you've large no. of bars / objects.
                      Hope it helps!
                      Attached Files

                      Comment


                        #41
                        s.kinra,
                        Thank you for the direction. I will look through the sample code and see what I can do. I really appreciate all the help you have extended.
                        Thanks again for all your time.
                        James

                        Comment


                          #42
                          s.kinra,
                          I wanted to say thank you again for all your help. With some trial and error, I used the first method you outlined in the sample code and got it to work with all my signals.
                          Thanks again for all your knowledge and willingness to help others.

                          James

                          Comment


                            #43
                            Hello s.kinra,
                            It looked like I had everything working. I noticed looking at the log that there is a warning that the signal object is being used and not unique.
                            Would I also need to add CurrentBar to the string as well?
                            I have 6 different signals.
                            Thank you for any help
                            James
                            Attached Files

                            Comment


                              #44
                              Hello James,
                              This error message indicates you're using same tag for 2 diff dwg objects so only one will prevail & other is ignored. For all tools be sure to have unique tag names or it may miss out. Your all 6 signals shouldn't be named as long_signal+CurrentBar or you never know which will miss if 2 or more are coming on same bar. So use 6 diff tag names.
                              Hope it helps!

                              Comment


                                #45
                                Thanks s.kinra.
                                So, I should have all different tags with the +CurrentBar and then add the + def_obj (from the sample code you posted above)? for the counter to work correctly?

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                606 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                353 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                105 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                560 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                561 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X