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

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 inanazsocial, Today, 01:15 AM
        0 responses
        2 views
        0 likes
        Last Post inanazsocial  
        Started by trilliantrader, 04-18-2024, 08:16 AM
        5 responses
        22 views
        0 likes
        Last Post trilliantrader  
        Started by Davidtowleii, Today, 12:15 AM
        0 responses
        3 views
        0 likes
        Last Post Davidtowleii  
        Started by guillembm, Yesterday, 11:25 AM
        2 responses
        9 views
        0 likes
        Last Post guillembm  
        Started by junkone, 04-21-2024, 07:17 AM
        9 responses
        71 views
        0 likes
        Last Post jeronymite  
        Working...
        X