Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

DrawRectangle - error

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

    DrawRectangle - error

    Code:
    DrawRectangle("Second Resistance Cluster", false, 10, r4, 1, r3, Color.Crimson, Color.Crimson, 5);
                        DrawRectangle("First Resistance Cluster", false, 10, r2, 1, r1, Color.Crimson, Color.Crimson, 5);
                        
                        DrawRectangle("Second Support Cluster", false, 10, s4, 1, s3, Color.Green, Color.Green, 5);
                        DrawRectangle("First Support Cluster", false, 10, s2, 1, s1, Color.Green, Color.Green, 5);
    I get the exception:

    Error on calling 'OnBarUpdate' method for indicator 'PivotClusters' on bar 0: PivotClusters.DrawRectangle: startBarsAgo out of valid range 0 through 0, was 10.

    #2
    Hello TradingZen,

    You're running into this issue:
    Make sure you have enough bars in the data series you are accessing

    You can resolve by adding a CurrentBar check in your OnBarUpdate() method.

    if (CurrentBar < 10)
    return;
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      awesome, thanks... is there a way to tell if it is the last bar on the chart?

      Comment


        #4
        Bars.Count is not a supported property, but you can use it to determine last bar on chart.

        When CalculateOnBarClose == false, then OnBarUpdate() is being called for the last bar on the chart:

        if (CurrentBar == Bars.Count - 1)


        When CalculateOnBarClose == true, then OnBarUpdate() is being called for the last closed bar on the chart, not thein processbar:

        if (CurrentBar== Bars.Count -2)
        Ryan M.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        23 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        17 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        182 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Started by CaptainJack, 04-24-2026, 11:07 PM
        0 responses
        335 views
        0 likes
        Last Post CaptainJack  
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        259 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X