Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Show Values of historical data with draw.text

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

    Show Values of historical data with draw.text

    Click image for larger version

Name:	image.png
Views:	300
Size:	9.4 KB
ID:	1238929
    Im just looking for a bit of advice to nudge me in the right direction, i have an indicator that shows order flow delta on the current bar im looking for a way to store the value the the previous bar once it closes or show the value on all the previous bars but doing so gives me the You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart. error

    #2
    Hello Kylemcfar57x,

    Thanks for your post.

    To access the previous Order Flow Cumulative Delta value, you could pass in a 1 for the barsAgo parameter when calling the OrderFlowCumulativeDelta method, such as OrderFlowCumulativeDelta().DeltaClose[1].

    Order Flow Cumulative Delta: https://ninjatrader.com/support/help...ive_delta2.htm

    This error message indicates that you are trying to access a BarsAgo value that is not valid.

    A more simple example using one series would be on bar 5 you check for 6 BarsAgo. There are not yet 6 bars so the CurrentBar minus 6 would be a negative number or a non-existent bar.

    A CurrentBar check could be used in your indicator's logic to ensure that a certain number of bars have processed before the indicator begins calculation. A CurrentBar check would look something like this.

    Code:
    if (CurrentBar < 10)
        return;
    This would check to make sure that 10 bars have processed before the indicator begins it's calculations.

    See the help guide documentation below for more information.
    CurrentBar - https://ninjatrader.com/support/help...currentbar.htm
    CurrentBars - https://ninjatrader.com/support/help...urrentbars.htm
    Make sure you have enough bars - https://ninjatrader.com/support/help...nough_bars.htm

    Let us know if we may assist further.​
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      This is a custom Ninjascript im developing, i dont have a lifetime license so i dont think i can use that

      Comment


        #4
        Hello Kylemcfar57x,

        Thanks for your note.

        " i have an indicator that shows order flow delta on the current bar"

        The above comment from your initial post led me to believe that you are using the Order Flow Cumulative Delta indicator.

        What exactly do you mean by you have an indicator that shows 'order flow delta' on the current bar? Is this a custom calculation you are doing in your script?

        How exactly are you calling Draw.Text() in your script to draw the object on a chart?

        Generally, to access previous bar values, you would pass in a barsAgo value of 1. Is this what you are attempting to do in your script when the error occurs?

        To resolve the error, you could implement a CurrentBar check to ensure there are enough bars in the data series you are accessing to resolve the "You are accessing an index with a value that is invalid since it is out-of-range." error message.

        Make sure you have enough bars - https://ninjatrader.com/support/help...nough_bars.htm

        I look forward to assisting further.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          Click image for larger version

Name:	image.png
Views:	199
Size:	28.3 KB
ID:	1239168


          thankyou for the quick response, im not to familiar with multi data series a simple if (Bars.Count < 6) return; solved my issue

          Comment


            #6
            Click image for larger version

Name:	image.png
Views:	202
Size:	47.2 KB
ID:	1239272
            every so often im running into an issue where the text stops lining up with the bars, only way it can be reset that i found is by closing NT and resetting the database, this uses tick replay have any ideas of what could be happening

            Comment


              #7
              also getting this exception if i use a time based bar,

              1/23/2023 6:04:58 PM System.ArgumentOutOfRangeException: 'barsAgo' needed to be between 0 and 0 but was 1
              Parameter name: barsAgo
              at NinjaTrader.NinjaScript.TimeSeries.get_Item(Int32 barsAgo)
              at NinjaTrader.NinjaScript.DrawingTools.DrawingTool.C reateChartAnchor(NinjaScriptBase ownerNinjaScript, Int32 barsAgo, DateTime time, Double y)
              at NinjaTrader.NinjaScript.DrawingTools.Draw.TextCore (NinjaScriptBase owner, String tag, Boolean autoScale, String text, Int32 barsAgo, DateTime time, Double y, Nullable`1 yPixelOffset, Brush textBrush, Nullable`1 textAlignment, SimpleFont font, Brush outlineBrush, Brush areaBrush, Nullable`1 areaOpacity, Boolean isGlobal, String templateName, DashStyleHelper outlineDashStyle, Int32 outlineWidth)
              at NinjaTrader.NinjaScript.DrawingTools.Draw.Text(Nin jaScriptBase owner, String tag, Boolean isAutoScale, String text, Int32 barsAgo, Double y, Int32 yPixelOffset, Brush textBrush, SimpleFont font, TextAlignment alignment, Brush outlineBrush, Brush areaBrush, Int32 areaOpacity, DashStyleHelper outlineDashStyle, Int32 outlineWidth, Boolean isGlobal, String templateName)
              at NinjaTrader.NinjaScript.Indicators.VolumeDelta.OnB arUpdate()

              Comment


                #8
                Hello Kylemcfar57x,

                Thanks for your notes.

                Do you have a CurrentBar check in your script to make sure that you have enough bars processed on the chart as mentioned in post # 4?

                How exactly are you calling your Draw methods in the script?

                Have you reduced the code and added debugging prints to the script to locate the exact line of code causing the error to occur?

                Please send me a reduced exported copy of the script and the exact steps and settings used to reproduce the behavior so I may look into this further.

                Note that a reduced copy refers to a copy of the script that contains the minimum amount of code needed to reproduce the issue. All other code is commented out or removed.

                To create a copy of your script to modify, open a New > NinjaScript Editor, select your script, right-click in the Editor, select 'Save as', name the script, and click OK.

                To export a script, go to Tools > Export > NinjaScript AddOn.​

                I look forward to further assisting.
                <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                Comment


                  #9
                  sorry for the late reply, i was finishing up some other indicators and im coming back to this one i solved the indexing issue with this check, if (CurrentBars[0] > 9) i found the issue with the anchory problem, for some reason its giving me close values for highs

                  output window

                  Highs[0][0]: 4168.25 Closes[0][0]: 4168.25
                  Highs[0][0]: 4169.25 Closes[0][0]: 4169.25
                  Highs[0][0]: 4170.75 Closes[0][0]: 4170.75
                  Highs[0][0]: 4171 Closes[0][0]: 4171
                  Highs[0][0]: 4174.75 Closes[0][0]: 4174.75​

                  Comment


                    #10
                    you can disregard this, I was using the wrong index solved with Highs[0][1]

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    656 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    371 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    109 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    574 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    579 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X