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

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 RookieTrader, Today, 09:37 AM
    3 responses
    15 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by kulwinder73, Today, 10:31 AM
    0 responses
    5 views
    0 likes
    Last Post kulwinder73  
    Started by terofs, Yesterday, 04:18 PM
    1 response
    23 views
    0 likes
    Last Post terofs
    by terofs
     
    Started by CommonWhale, Today, 09:55 AM
    1 response
    3 views
    0 likes
    Last Post NinjaTrader_Erick  
    Started by Gerik, Today, 09:40 AM
    2 responses
    7 views
    0 likes
    Last Post Gerik
    by Gerik
     
    Working...
    X