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

slow performance using custom indicators

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

    slow performance using custom indicators

    Hello,

    I have developed a couple of custom indicators which really take a long time to load (e.g. when applied to 1 Min charts it could take 30 secs to load)

    Once they load, they update ok even though they seem to use a lot of PC resources (I am not a techie, but I can sense symptoms such as the time it takes to display a chart when flicking between chart windows or computer noise - sounds as if PC is going to take off any minute! - and/or temperature)

    Not sure if I am coding something incorrectly. Common features these two indicators have are the following:
    • They plot or use 4 to 5 data series each.
    • They use TimeSpan variables and LRO/MRO methods to filter out bars*
    • Once compiled they generate about 300 lines of code
    • I use them real-time (i.e. CalculateOnBarClose set to False)
    Do you see any potential problems in those settings? (I am aware some of them could be a drain on performance, but really by that much?)

    I have read the Help file on ways to improve PC performance when using NT, but is there anything else you could suggest to improve code efficiency and/or PC performance when developing custom indicators?

    Thanks in advance,

    Stopped

    * I was referring to the following code:
    TimeSpan refTime = TimeZoneInfo.ConvertTime(Time[0], Bars.Session.TimeZoneInfo).TimeOfDay;

    int barsAgoInit = LRO(delegate{return TimeZoneInfo.ConvertTime(Time[0], Bars.Session.TimeZoneInfo).TimeOfDay == refTime;}, 1, CurrentBar + 1);
    int barsAgo = MRO(delegate{return TimeZoneInfo.ConvertTime(Time[0], Bars.Session.TimeZoneInfo).TimeOfDay == refTime;}, 2, CurrentBar + 1);

    #2
    Hello Stopped,

    Thank you for your post.

    How many days to load do you have set in your chart? If you are Adding multiple data series, you will need to wait for this data to load in the Initialize() method before it will begin. Once it is loaded, the more days to load you have set, the more memory this indicator will be using.

    I wouldn't suspect any major performance issues by using the TimeSpan filter. It may take longer for this script to load, but you shouldn't see any negative real-time performance.

    You should check how many Draw methods you are using as many draw objects that need to be redrawn frequently can impact performance.

    Setting your indicator to COBC to true will help with your CPU processing time. Please refer to our reference sample on Separating logic to either calculate once on bar close or on every tick. Although this sample is in the context of a strategy, the same principles would apply to an indicator:



    Please let me know if you have additional questions.
    MatthewNinjaTrader Product Management

    Comment


      #3
      Originally posted by Stopped View Post
      Hello,

      I have developed a couple of custom indicators which really take a long time to load (e.g. when applied to 1 Min charts it could take 30 secs to load)

      Once they load, they update ok even though they seem to use a lot of PC resources (I am not a techie, but I can sense symptoms such as the time it takes to display a chart when flicking between chart windows or computer noise - sounds as if PC is going to take off any minute! - and/or temperature)

      Not sure if I am coding something incorrectly. Common features these two indicators have are the following:
      • They plot or use 4 to 5 data series each.
      • They use TimeSpan variables and LRO/MRO methods to filter out bars*
      • Once compiled they generate about 300 lines of code
      • I use them real-time (i.e. CalculateOnBarClose set to False)

      Do you see any potential problems in those settings? (I am aware some of them could be a drain on performance, but really by that much?)

      I have read the Help file on ways to improve PC performance when using NT, but is there anything else you could suggest to improve code efficiency and/or PC performance when developing custom indicators?

      Thanks in advance,

      Stopped

      * I was referring to the following code:
      TimeSpan refTime = TimeZoneInfo.ConvertTime(Time[0], Bars.Session.TimeZoneInfo).TimeOfDay;

      int barsAgoInit = LRO(delegate{return TimeZoneInfo.ConvertTime(Time[0], Bars.Session.TimeZoneInfo).TimeOfDay == refTime;}, 1, CurrentBar + 1);
      int barsAgo = MRO(delegate{return TimeZoneInfo.ConvertTime(Time[0], Bars.Session.TimeZoneInfo).TimeOfDay == refTime;}, 2, CurrentBar + 1);
      The LRO() will incur a penalty as written, if it is in OnBarUpdate(), as to determine the LRO, you must needs calculate from the beginning of the chart every time. If on top of that, you are calculating it on every tick (COBC = false), can you see how that might impact performance? That translates into, "on every tick, start from the beginning of the chart and perform some operation, and return a value."

      Comment


        #4
        Thanks Mathew and koganam,

        Do you know if there is an intermediate way between COBC true and false? I am thinking something along the lines of "update every 30 seconds" instead of every tick.

        As I was writing that code I realised I was putting a heavy burden on my PC. However, I could not find a different way of coding it to achieve the desired results (mind you, I am a newbie when it comes to coding indicators, so I am sure someone more experienced would find a more efficient way around).

        Having said that, the problem with these indicators do not arise when they are running - which they do ok (albeit at a heavier cost to my PC). The problem comes when loading them: It takes so long to load a 1 Min chart that once you have done it you do not want to switch back to another time frame (as you would spend the whole day waiting for charts to load up rather than trading). Therefore, I opt to leave that particular chart linked to a specific time frame during the day, and use a different chart window (without those indicators) to quickly flick between time frames. This is a second-best solution as, ideally, I would like to make those indicators more efficient (i.e. able to load much quicker) and use only one chart window.

        Thanks again,

        Stopped

        Comment


          #5
          A related question please: What is more efficient? Coding one indicator that displays 7 plots or coding 7 indicators that display 1 indicator each? Thanks.

          Comment


            #6
            Originally posted by Stopped View Post
            Thanks Mathew and koganam,

            Do you know if there is an intermediate way between COBC true and false? I am thinking something along the lines of "update every 30 seconds" instead of every tick.

            As I was writing that code I realised I was putting a heavy burden on my PC. However, I could not find a different way of coding it to achieve the desired results (mind you, I am a newbie when it comes to coding indicators, so I am sure someone more experienced would find a more efficient way around).

            Having said that, the problem with these indicators do not arise when they are running - which they do ok (albeit at a heavier cost to my PC). The problem comes when loading them: It takes so long to load a 1 Min chart that once you have done it you do not want to switch back to another time frame (as you would spend the whole day waiting for charts to load up rather than trading). Therefore, I opt to leave that particular chart linked to a specific time frame during the day, and use a different chart window (without those indicators) to quickly flick between time frames. This is a second-best solution as, ideally, I would like to make those indicators more efficient (i.e. able to load much quicker) and use only one chart window.

            Thanks again,

            Stopped
            There are a few ways to go about that.

            One way is to use the computers clock and only update when the clock is at the scheduled time; say every 30 seconds. You will need to use the more elaborate TimeDate structures of C# if you want to do this.

            Another way is to look at what your code is actually doing, and only update if the item of interest changes. For example, if you only use Close for doing calculations, then you just code such that if the Close has not changed from one tick to the next, the indicator returns without doing anything.

            Comment


              #7
              Originally posted by Stopped View Post
              A related question please: What is more efficient? Coding one indicator that displays 7 plots or coding 7 indicators that display 1 indicator each? Thanks.
              That depends on how you define "efficient".

              Generally speaking, 1 indicator will use less computing resources (Plot() will be called only once to update all seven plots) at the expense of flexibility as all 7 plots are loaded on every chart, unless you make provision for disabling the plots selectively. Even then, you will still incur the small penalty of the "test" required to disable the plot on each pass.
              Last edited by koganam; 09-16-2011, 05:44 PM. Reason: Corrected grammar

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by TheWhiteDragon, 01-21-2019, 12:44 PM
              4 responses
              541 views
              0 likes
              Last Post PaulMohn  
              Started by GLFX005, Today, 03:23 AM
              0 responses
              2 views
              0 likes
              Last Post GLFX005
              by GLFX005
               
              Started by XXtrader, Yesterday, 11:30 PM
              2 responses
              11 views
              0 likes
              Last Post XXtrader  
              Started by Waxavi, Today, 02:10 AM
              0 responses
              7 views
              0 likes
              Last Post Waxavi
              by Waxavi
               
              Started by TradeForge, Today, 02:09 AM
              0 responses
              14 views
              0 likes
              Last Post TradeForge  
              Working...
              X