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 CaptainJack, 05-29-2026, 05:09 AM
        0 responses
        213 views
        0 likes
        Last Post CaptainJack  
        Started by CaptainJack, 05-29-2026, 12:02 AM
        0 responses
        127 views
        0 likes
        Last Post CaptainJack  
        Started by charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        145 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        229 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        190 views
        0 likes
        Last Post CarlTrading  
        Working...
        X