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 helpwanted, Today, 03:06 AM
    1 response
    12 views
    0 likes
    Last Post sarafuenonly123  
    Started by Brevo, Today, 01:45 AM
    0 responses
    9 views
    0 likes
    Last Post Brevo
    by Brevo
     
    Started by aussugardefender, Today, 01:07 AM
    0 responses
    5 views
    0 likes
    Last Post aussugardefender  
    Started by pvincent, 06-23-2022, 12:53 PM
    14 responses
    242 views
    0 likes
    Last Post Nyman
    by Nyman
     
    Started by TraderG23, 12-08-2023, 07:56 AM
    9 responses
    387 views
    1 like
    Last Post Gavini
    by Gavini
     
    Working...
    X