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

AddVolumetric crashes in OnRender()

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

    AddVolumetric crashes in OnRender()

    Good evening,

    I have attached a basic - as basic as you can get - indicator that I'm using to try to get around another problem I'm having. I'm using AddVolumetric to get information that I would like to render.

    My problem is the addition of AddVolumetric causes a crash in OnRender() for the call (that I got from here: https://ninjatrader.com/support/help...s/?gettime.htm:

    Code:
     
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
      base.OnRender(chartControl, chartScale);
      // loop through only the rendered bars on the chart
      for(int barIndex = ChartBars.FromIndex; barIndex <= ChartBars.ToIndex; barIndex++)
      {
        // get the time stamp at the selected bar index value
        [COLOR="blue"]DateTime timeValue = Bars.GetTime(barIndex);  // [B]This call crashes[/B]
    [/COLOR]    Print("Bar #" + barIndex + " time stamp is " + timeValue);
      }
    }

    It turns out, when BarsInProgress = 1, I get the crash with "Object reference not set to an instance of an object." And for what I want to render, I need to know if the bar is in a certain time parameter. The only way I know to get the bar time in OnRender is to call Bars.GetTime() which crashes if the Volumetric bars are loaded.

    I can render my objects if I check for BarsInProgress = 0 but my objects go away when OnRender when BarsInProgress = (Volumetric bars), which means I'm seemingly kind of screwed.

    Is there any other way to get that information?
    Thanks!

    #2
    Nevermind

    The call should be:

    Code:
    ChartBars.GetTimeByBarIdx( chartControl, idx);
    Not:

    Code:
    Bars.GetTime(barIndex)

    Comment


      #3
      Hello traderpards,

      Thank you for reporting this.

      I will test and inquire with our development if this is expected behavior.

      I appreciate your patience.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Hello traderpards,

        I was not able to reproduce this behavior when using Volumetric bars on the chart.

        Below is a public link to a video.


        Attached is an export of the test script.

        Using the test script, if you follow the same steps shown in the video are you experiencing different behavior?
        Attached Files
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          You didn't run the test script I sent you, and the one you ran, doesn't call AddVolumetric(). But the test script I attached seems to be missing. (Please tell me I didn't forget to attach...) Here it is again.

          The key is to add a volumetric data series in the background. If you look at this script I attached, that's what this does - it calls AddVolumetric() in OnStateChange. Then you run the indicator on a chart with range bars, or minute bars or whatever. Range bars reproduces the problem. Minute/Second bars seems to work fine as the framework goes through historically but then throws the exception during real time... I'll let you run it on any other bar type you support.

          Like I said, I have a workaround so that's what I'm using. But if you want to verify this, you do it by running the indicator I attached.

          PS. The volumetric bars are a great way to get bid/ask information when the bar closes. It's super-fast compared to the OnMarketData way of doing it that we've become accustomed to in the past. Plus, you don't need TickReplay. I love it!
          Attached Files

          Comment


            #6
            Hello traderpards,

            There was never any test script attached to https://ninjatrader.com/support/foru...207#post552207 that I saw.

            I took a look at the BarsRenderTest.cs file. I see that you loop through the primary bars and attempt to get data for a secondary bar.

            The chart bars are probably not matching your secondary series.
            You are probably calling a bar in the secondary series that does not exist and returning a null and trying to use this.

            What happens if you print the last bar of the secondary series?

            Print(BarsArray[1].GetTime(CurrentBars[1]);

            Are you still able to produce the error?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_ChelseaB View Post
              Hello traderpards,
              There was never any test script attached to https://ninjatrader.com/support/foru...207#post552207 that I saw.

              I took a look at the BarsRenderTest.cs file. I see that you loop through the primary bars and attempt to get data for a secondary bar.

              The chart bars are probably not matching your secondary series.
              You are probably calling a bar in the secondary series that does not exist and returning a null and trying to use this.

              What happens if you print the last bar of the secondary series?

              Print(BarsArray[1].GetTime(CurrentBars[1]);

              Are you still able to produce the error?
              OK, I probably forgot to attach. Sorry about that. Try running the one I did attach.

              I don't know. I don't want to print the last bar of the secondary series. I want to find the bar time for whatever bar it is while I loop through all of them.

              I tried this within the loop: DateTime barTime = BarsArray[1].GetTime(barIndex);

              It too crashes. My original workaround for this crash is the ticket.

              Comment


                #8
                Hello traderpards,

                I would expect this code to possibly have a logic error.

                The issue is with using barIndex of the primary series with BarsArray[1].GetTime() on the secondary series.

                Are you wanting me to run the script to verify I am also able to experience a logic error which I would be expecting?

                I was not able to confirm, are you experiencing an error if you print the last bar of the secondary series?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_ChelseaB View Post
                  Hello traderpards,

                  I would expect this code to possibly have a logic error.

                  The issue is with using barIndex of the primary series with BarsArray[1].GetTime() on the secondary series.

                  Are you wanting me to run the script to verify I am also able to experience a logic error which I would be expecting?

                  I was not able to confirm, are you experiencing an error if you print the last bar of the secondary series?
                  Maybe that's why using ChartBars.GetTimeByBarIdx( chartControl, idx) is the ticket...

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by pvincent, 06-23-2022, 12:53 PM
                  14 responses
                  238 views
                  0 likes
                  Last Post Nyman
                  by Nyman
                   
                  Started by TraderG23, 12-08-2023, 07:56 AM
                  9 responses
                  383 views
                  1 like
                  Last Post Gavini
                  by Gavini
                   
                  Started by oviejo, Today, 12:28 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post oviejo
                  by oviejo
                   
                  Started by pechtri, 06-22-2023, 02:31 AM
                  10 responses
                  125 views
                  0 likes
                  Last Post Leeroy_Jenkins  
                  Started by judysamnt7, 03-13-2023, 09:11 AM
                  4 responses
                  59 views
                  0 likes
                  Last Post DynamicTest  
                  Working...
                  X