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 DanielTynera, Today, 01:14 AM
    0 responses
    2 views
    0 likes
    Last Post DanielTynera  
    Started by yertle, 04-18-2024, 08:38 AM
    9 responses
    40 views
    0 likes
    Last Post yertle
    by yertle
     
    Started by techgetgame, Yesterday, 11:42 PM
    0 responses
    12 views
    0 likes
    Last Post techgetgame  
    Started by sephichapdson, Yesterday, 11:36 PM
    0 responses
    2 views
    0 likes
    Last Post sephichapdson  
    Started by bortz, 11-06-2023, 08:04 AM
    47 responses
    1,615 views
    0 likes
    Last Post aligator  
    Working...
    X