Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Retrieving Horizontal Lines from .xml file

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

    #16
    No, there are only 63

    Comment


      #17
      Hello RJBen,

      I would suggest for the time being to close all charts and open a single chart and then apply 1 horizontal line to that chart. Then run your code and make sure it shows only 1 object as the count in your print. Then assuming that is successful try 2 objects on the chart and make sure the count matches again. If the counts become out of sync that would point to something being done in code with the script you are using.

      Comment


        #18
        I can send you the entire lines of code if you'd like so you can see if there's anything amiss earlier in the coding.

        Comment


          #19
          Okay, I'll try that...

          Comment


            #20
            I only have one ES chart open.

            So I removed the .xml files from the NinjaTrader 8\templates\GlobalDrawingObject folder and restarted the program.
            I ticked the "Show global draw objects" in the Data Series window. No global horizontal lines showed up on the chart so- so far so good. I added a Horizontal Line and set it to ES (All charts). I ran my Indicator and the Output window showed:

            @Horizontal Line 6107.75
            Total number of Draw Objects 772
            ****************************************

            It printed it 772 times
            Last edited by RJBen; 01-29-2025, 09:30 AM.

            Comment


              #21
              Hello RJBen,

              I would suggest attaching the .cs file for the script so we can see what specific code is being used now.

              Comment


                #22
                Here it is. Thanks for all your help Jesse.
                Attached Files

                Comment


                  #23
                  I should mention the program froze a lot- perhaps every time a new bar began or ended. Would that be due to the OnBarUpdate?

                  Comment


                    #24
                    Hello RJBen,

                    This is because you are using Count in your print:

                    Print("Total number of Draw Objects " + Count);

                    You need to use

                    Print("Total number of Draw Objects " + DrawObjects.Count);

                    If you are seeing slowness you also need to add a historical return because this collection is not intended to be used historically but only in realtime going forward.

                    protected override void OnBarUpdate()
                    {
                    if(State == State.Historical) return;​

                    Comment


                      #25
                      It's Printing

                      @Horizontal Line 6107.75
                      Total number of Draw Objects 1
                      *******************************************

                      772 times

                      I'll add the State info later. No use muddying the water until I get the Print to display once for one line.
                      Last edited by RJBen; 01-29-2025, 10:14 AM.

                      Comment


                        #26
                        Hello RJBen,

                        It prints that many times because you are executing it for every bar, that collection is resource intensive so it should not be used on historical bars. The best way to test that is to add that state check, connect to a live connection and open a small timeframe chart like 10 seconds and apply it there. That will execute the code once every 10 seconds so you can easily see what is being printed one time. if you make code changes and reload the script the next update will be in 10 seconds again.

                        Comment


                          #27
                          YES!!!!!!! Got it!!!!!!

                          Comment


                            #28
                            One more question: If it updates on bar Close, can I get it delete what it printed on the previous bar close so only one set is printed? It keeps adding to the Output Window on every bar Close.

                            Comment


                              #29
                              Hello RJBen,

                              You can use ClearOutputWindow() however keep in mind that clears the entire window, not just the last line. If you have other scripts producing output it will clear that info as well.

                              Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.

                              Comment


                                #30
                                Okay, where would this be added in my script? At the end of OnBarsUpdate?

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by NullPointStrategies, Yesterday, 05:17 AM
                                0 responses
                                71 views
                                0 likes
                                Last Post NullPointStrategies  
                                Started by argusthome, 03-08-2026, 10:06 AM
                                0 responses
                                143 views
                                0 likes
                                Last Post argusthome  
                                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                                0 responses
                                76 views
                                0 likes
                                Last Post NabilKhattabi  
                                Started by Deep42, 03-06-2026, 12:28 AM
                                0 responses
                                47 views
                                0 likes
                                Last Post Deep42
                                by Deep42
                                 
                                Started by TheRealMorford, 03-05-2026, 06:15 PM
                                0 responses
                                51 views
                                0 likes
                                Last Post TheRealMorford  
                                Working...
                                X