• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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]).
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by mquinteroj, Today, 02:41 PM
    1 response
    8 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by JPPoulin, Today, 01:32 PM
    2 responses
    14 views
    0 likes
    Last Post JPPoulin  
    Started by bltdavid, Today, 01:09 PM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_Kate  
    Started by pstrusi, Today, 12:50 PM
    2 responses
    8 views
    0 likes
    Last Post pstrusi
    by pstrusi
     
    Started by ralett, Today, 11:52 AM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_PatrickG  
    Working...
    X