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, 03-31-2026, 09:41 PM
        1 response
        152 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        87 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        131 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        127 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        106 views
        0 likes
        Last Post CarlTrading  
        Working...
        X