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

DrawText() Functions seem to be slow

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

    DrawText() Functions seem to be slow

    Hi,

    I'm using the DrawTextFixed() functions to print 5 minute volume numbers on my chart, the string to be printed is about 60 characters in length. I've noticed that during peak activity periods, when volume is changing rapidly, that my chart freezes or is very slow to respond.

    When I reduce the string length the problem is reduced, but thats not the best solution. Also, I know that its the string printing functions, not the calculations or some other part of the indicator, because I have tested it whilst removing the printing and leaving everything else as is.

    The indicator reprints on every volume update, which I guess means every tick. But why is it that the draw text functions affect performance so much, whereas other functions that plot, and have more complex calculations, do not.

    I thought about changing the output so that its on a, say, 1 second timer, but this is also not an ideal solution.

    Any suggestions?

    Thanks,
    Will.

    #2
    Hello WIll,

    Thank you for your post.

    Drawing methods can have an effect on performance especially in the case of drawing multiple characters on a chart that is already updating several other visual items. You can try switching to CalculateOnBarClose = true and/or increasing the Display Update Interval (right click in your chart > Properties > Display update interval (sec)).

    Comment


      #3
      Hi thanks for the suggestion, but I think I had already covered those options in my description, ie changing to a timer event or reducing the string length.

      What I was hoping for was a way to draw text with better performance, or to understand why the text drawing seems to be so slow compared to my other plotting indicators, which are equal or greater in complexity, but don't have the same issues simply because they dont have text output.

      Comment


        #4
        Originally posted by dontpanic View Post
        Hi thanks for the suggestion, but I think I had already covered those options in my description, ie changing to a timer event or reducing the string length.

        What I was hoping for was a way to draw text with better performance, or to understand why the text drawing seems to be so slow compared to my other plotting indicators, which are equal or greater in complexity, but don't have the same issues simply because they dont have text output.
        You can always use the direct C# drawing functions in a custom Plot.

        Comment


          #5
          Originally posted by dontpanic View Post
          Hi thanks for the suggestion, but I think I had already covered those options in my description, ie changing to a timer event or reducing the string length.

          What I was hoping for was a way to draw text with better performance, or to understand why the text drawing seems to be so slow compared to my other plotting indicators, which are equal or greater in complexity, but don't have the same issues simply because they dont have text output.
          All NinjaScript Draw methods have a negavtive impact on performance. This is particularly true, if you let your indicators recalculate with every incoming tick. In order to handle the problem you have the following options:

          -> Set your indicator to CalculateOnBarClose = true, in this case the Draw method will only be performed once at the bar close
          -> Alternatively only perform the draw method when the first tick of a bar is plotted (I personally code the indicators in a way that the Draw method is only executed once per bar, it is also possible to draw the text for the prior bar, when the first tick of the current bar is detected). Here is a sample how to code it:

          Code:
          // in this case the indicator is only calculated once per bar:
          if(Historical or CalculateOnBarClose)  
                    DrawText (.....);
          // in this case (real-time data + COBC = false) there are many ticks per bar
          else if (FirstTickOfBar)
                     DrawText(....... eventually for the prior bar);

          -> Alternatively you can create a custom plot to draw your objects. During a news release the custom plot is not executed with every incoming tick, but there is a display update interval of 500 msec with default settings, therefore it is preferable to have the drawing coded within the plot.
          -> You can also create an artificial display update interval within OnBarUpdate() to avoid that the Draw method is executed with every incoming tick

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by rtwave, 04-12-2024, 09:30 AM
          2 responses
          19 views
          0 likes
          Last Post rtwave
          by rtwave
           
          Started by tsantospinto, 04-12-2024, 07:04 PM
          5 responses
          67 views
          0 likes
          Last Post tsantospinto  
          Started by cre8able, Today, 03:20 PM
          0 responses
          6 views
          0 likes
          Last Post cre8able  
          Started by Fran888, 02-16-2024, 10:48 AM
          3 responses
          49 views
          0 likes
          Last Post Sam2515
          by Sam2515
           
          Started by martin70, 03-24-2023, 04:58 AM
          15 responses
          115 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X