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 Kaledus, Today, 01:29 PM
    5 responses
    12 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by Waxavi, Today, 02:00 AM
    1 response
    8 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by alifarahani, Today, 09:40 AM
    5 responses
    23 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by gentlebenthebear, Today, 01:30 AM
    3 responses
    16 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by PhillT, Today, 02:16 PM
    2 responses
    7 views
    0 likes
    Last Post PhillT
    by PhillT
     
    Working...
    X