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 RookieTrader, Today, 09:37 AM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by alifarahani, Today, 09:40 AM
    0 responses
    5 views
    0 likes
    Last Post alifarahani  
    Started by Gerik, Today, 09:40 AM
    0 responses
    5 views
    0 likes
    Last Post Gerik
    by Gerik
     
    Started by KennyK, 05-29-2017, 02:02 AM
    3 responses
    1,284 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by AttiM, 02-14-2024, 05:20 PM
    11 responses
    185 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X