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 kujista, Today, 06:23 AM
        4 responses
        14 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by traderqz, Yesterday, 09:06 AM
        2 responses
        16 views
        0 likes
        Last Post traderqz  
        Started by traderqz, Today, 12:06 AM
        3 responses
        6 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by RideMe, 04-07-2024, 04:54 PM
        5 responses
        28 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by f.saeidi, Today, 08:13 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X