Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Newbie issue. Bar index error

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

    Newbie issue. Bar index error

    Hello to all!
    Started to write the new strategy. Having trouble in next things.
    Want to find index of the bar of the current ZigZag high & low.
    Having next code:

    Code:
            protected override void Initialize()
            {
                CalculateOnBarClose = true;
            
                
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            /// 
            
                int highZindex = 0;
                int lowZindex = 0;
    
            
            protected override void OnBarUpdate()
            {
                if(CurrentBar < 20)
                    return;
    
                ZigZag zz = ZigZag(DeviationType.Percent, 0.5, true);
                highZindex = CurrentBar - zz.HighBar(0, 1, CurrentBar);
                lowZindex = CurrentBar - zz.LowBar(0,1, CurrentBar);
    
                
                
                Print("Current ZigZag High is" + highZindex + Time[lowZindex]);
                Print("Current ZigZag Low is" + lowZindex + Time[highZindex]);
    
            }
    But when I'm trying to run strategy it doesn't works. In log I see next error:
    Error on calling 'OnBarUpdate' method for strategy *NAME OF THE STRATEGY* Bar index needs to be greater/equal 0

    What do I need to do with this?
    Thanks!

    #2
    Hello YevhenShynkarenko,

    Thanks for your reply.

    I would recommend commenting out your current code in the OnBarUpdate section and some tests using this print statement to assist:

    Print ("CB: "+ CurrentBar+" ZZ: "+ ZigZag(DeviationType.Percent, 0.5, true).HighBar(0, 1, CurrentBar));

    Please note that the ZigZag will return a -1 value if a swing point is not found in the lookback period. the print statement will show you the currentbar number followed by the Highbar. I suspect you were getting stuck by the -1 value.

    Finally the Print statement show that you had mixed the low and high indexes in the same print statment, example: highZindex + Time[lowZindex]).

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    602 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    347 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    559 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    558 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X