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

Chart data delay

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

    Chart data delay

    During todays higher volatility period my chart created a display delay of over a minute and my trade buttons lost functionality.
    This happened because I am using a few custom indicators and I'm guessing my code isn't optimally written for performance.

    What are the best practices for caching indicator data or could the team lead me to a different solution?

    #2
    Hello mlprice12,

    What you described could be expected depending on the configuration of the indicator in contrast to what your code is doing. Without more specific details on what your code does it would be difficult to point a direction other than general debugging steps. If your script runs OnPriceChange or OnEachTick that can compound problems in times of high volatility. if you are doing something not efficiently many times in a short period of time that can cause slow downs.

    The best suggestion as a starting point would be to identify where your script may have high cpu use. A good area to check would be your OnBarUpdate logic. Drawing objects and other complex rendering can also cause slow downs if you are doing something many times in a small period of time. Temporarily disabling drawing objects in your code and other visual items will help to identify if that relates to the problem or not.

    You may be able to utilize the playback connection if there is a specific instrument which you had observed this and know the time when that occurred. If you can re create the problem in playback then you can explore the code much more easily to find what parts contribute to the slowness.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks Jesse

      It is 100% drawing objects OnBarUpdate; however, these objects are vital for my trading.


      Are there recommendations for enhancing this code?
      This is occuring on Each Tick with Volumetric series added
      Code:
      AddVolumetric("ES 12-21", BarsPeriodType.Range, 2, VolumetricDeltaType.UpDownTick, 1);
      Code:
      protected override void OnBarUpdate()
      {
      if (CurrentBars[1] < 505)
      return;
      if (Bars == null)
      return;
      
      NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = BarsArray[1].BarsType as
      NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;
      
      if (barsType == null)
      return;
      if(BarsInProgress != 1)
      return;
      
      if (CurrentBars[1] > 505)
      {
      
      double price = High[0] - TickSize;
      //barsType.Volumes[CurrentBars[1]].GetMaximumVolume(null, out price);
      barVol[0] = barsType.Volumes[CurrentBars[1]].TotalVolume;
      double abarVol = SUM(barVol, 500)[0];
      double rbarVol = barVol[0] / (abarVol/500);
      double barDelta = barsType.Volumes[CurrentBars[1]].BarDelta;
      int rbarVolInt = (int)(rbarVol*1.1);
      //size based on vol 0,1,2,3,4, tick
      // color based on delta - black - pale - dark
      
      if (barDelta >= barVol[0]*.70)
      {
      Draw.Ellipse(this, "DOT"+CurrentBar, false, rbarVolInt, price+(rbarVolInt*.9)*TickSize, -rbarVolInt, price-(rbarVolInt*.9)*TickSize, Brushes.Green, Brushes.Green, 20);
      }
      else if (barDelta >= barVol[0]*.30)
      {
      Draw.Ellipse(this, "DOT"+CurrentBar, false, rbarVolInt, price+(rbarVolInt*.9)*TickSize, -rbarVolInt, price-(rbarVolInt*.9)*TickSize, Brushes.Navy, Brushes.Navy, 20);
      }
      else if (barDelta >= barVol[0]*-.05)
      {
      Draw.Ellipse(this, "DOT"+CurrentBar, false, rbarVolInt, price+(rbarVolInt*.9)*TickSize, -rbarVolInt, price-(rbarVolInt*.9)*TickSize, Brushes.LightSlateGray, Brushes.LightSlateGray, 20);
      }
      else if (barDelta <= barVol[0]*-.70)
      {
      Draw.Ellipse(this, "DOT"+CurrentBar, false, rbarVolInt, price+(rbarVolInt*.9)*TickSize, -rbarVolInt, price-(rbarVolInt*.9)*TickSize, Brushes.Orange, Brushes.Orange, 20);
      }
      else if (barDelta <= barVol[0]*-.30)
      {
      Draw.Ellipse(this, "DOT"+CurrentBar, false, rbarVolInt, price+(rbarVolInt*.9)*TickSize, -rbarVolInt, price-(rbarVolInt*.9)*TickSize, Brushes.Crimson, Brushes.Crimson, 20);
      }
      else
      {
      Draw.Ellipse(this, "DOT"+CurrentBar, false, rbarVolInt, price+(rbarVolInt*.9)*TickSize, -rbarVolInt, price-(rbarVolInt*.9)*TickSize, Brushes.LightSlateGray, Brushes.LightSlateGray, 20);
      }
      }
      }
      Thanks

      Comment


        #4
        Hello mlprice12,

        From the given code it appears there would likely be many unique objects.

        If you specifically needed the ellipse to highlight areas the more efficient way to do this would be to use OnRender. In that use case you would use plots or series to store data where you currently have your Draw.Ellipse statements. The way OnRender works is to only render the data for the currently visible bars so you could use OnRender to only render ellipses for the currently visible bars. That saves cpu by not creating many objects, you just have a few plots or series and then render the data from those.

        https://ninjatrader.com/support/help...htsub=onrender

        You could otherwise use plots to display the data which would be more efficient than drawing objects.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks a lot jesse,

          Do you have access to the code for Order Flow Trade Detector or have insight into how the ellipses are drawn efficiently for that indicator?

          Comment


            #6
            Hello mlprice12,

            While we cannot see into the code for the indicator I can say that it would use OnRender for that purpose. You can see an example of drawing using OnRender by viewing the indicator SampleCustomRender. The Pivots and ZigZag indicators show how to implement using Plots to store data and OnRender to render the data in a custom way.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Great. I will look at those for examples and reply back if I need further assistance.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Columbcille, Today, 02:04 PM
              0 responses
              1 view
              0 likes
              Last Post Columbcille  
              Started by Bhavika, Yesterday, 09:03 PM
              1 response
              4 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by slimcactus, Today, 10:26 AM
              1 response
              14 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by Monares, Today, 10:49 AM
              3 responses
              19 views
              0 likes
              Last Post NinjaTrader_JustinD  
              Started by d122y, Today, 10:20 AM
              1 response
              12 views
              0 likes
              Last Post NinjaTrader_ChrisL  
              Working...
              X