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

Custom Indicator use ZigZag

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

    Custom Indicator use ZigZag

    Hi,

    I get an error
    Indicator 'zzTrend': Error on calling 'OnBarUpdate' method on bar 20: Object reference not set to an instance of an object.

    Look in attach please, there is a simple indicator which use ZigZag indicator, but there is an error. I need help

    private Series<double> zzH;
    private Series<double> zzL;
    private double DeviationValue = 0.14;

    ...

    if (State == State.Configure) {
    zzH = ZigZag(DeviationType.Points, DeviationValue, true).ZigZagHigh;
    zzL = ZigZag(DeviationType.Points, DeviationValue, true).ZigZagLow;
    }

    and then in OnBarUpdate

    I call
    Print (Time[0].ToString()+" ZZH[0]="+ZigZag(DeviationType.Points, DeviationValue, true).ZigZagHigh[0] + " ZZH[2]="+ZigZag(DeviationType.Points, DeviationValue, true).ZigZagHigh[2]+"\n"+"ZZL[0]="+ZigZag(DeviationType.Points, DeviationValue, true).ZigZagLow[0] + " ZZL[2]="+ZigZag(DeviationType.Points, DeviationValue, true).ZigZagLow[2]);

    and this code works fine

    BUT

    whte I change call to
    Print (Time[0].ToString()+" ZZH[0]="+zzH[0] + " ZZH[2]="+zzH[2]+"\n"+"ZZL[0]="+zzL[0] + " ZZL[2]="+zzL[2]);

    Then I get an error Indicator 'zzTrend': Error on calling 'OnBarUpdate' method on bar 20: Object reference not set to an instance of an object.

    What do I wrong in this simple code example?
    Attached Files
    Handlar
    NinjaTrader Ecosystem Vendor - Handlar

    #2
    Hello handlar,

    Thanks for your post.

    Your first print statement is calling the zigzag in line and while not a recommended practice, as you are providing all of the correct parameters will work.

    The second print statement is calling the local instances of the indicator you created in State.Configure. The indicator method is better created in State.Historical, please see performance practices in the helpguide section here:https://ninjatrader.com/support/help..._practices.htm
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by andrewtrades, Today, 04:57 PM
    1 response
    8 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by chbruno, Today, 04:10 PM
    0 responses
    6 views
    0 likes
    Last Post chbruno
    by chbruno
     
    Started by josh18955, 03-25-2023, 11:16 AM
    6 responses
    436 views
    0 likes
    Last Post Delerium  
    Started by FAQtrader, Today, 03:35 PM
    0 responses
    7 views
    0 likes
    Last Post FAQtrader  
    Started by rocketman7, Today, 09:41 AM
    5 responses
    19 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X