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 Mestor, 03-10-2023, 01:50 AM
    16 responses
    388 views
    0 likes
    Last Post z.franck  
    Started by rtwave, 04-12-2024, 09:30 AM
    4 responses
    31 views
    0 likes
    Last Post rtwave
    by rtwave
     
    Started by yertle, Yesterday, 08:38 AM
    7 responses
    29 views
    0 likes
    Last Post yertle
    by yertle
     
    Started by bmartz, 03-12-2024, 06:12 AM
    2 responses
    22 views
    0 likes
    Last Post bmartz
    by bmartz
     
    Started by funk10101, Today, 12:02 AM
    0 responses
    7 views
    0 likes
    Last Post funk10101  
    Working...
    X