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

Indicator value different when OBC = true or false

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

    Indicator value different when OBC = true or false

    The following indicator, Smoothed Adaptive Momentum, gives different values at the close of a bar when onbarclose = true compared obc = false.

    Why is this? Is there a possible fix?

    Many thanks.



    protected override void Initialize ()
    {
    Add (new Line (Color.DarkGray, 0, "ZeroLine"));

    Add (new Plot (Color.Orange, PlotStyle.Line, "SmoothedAdaptiveMomentum"));

    CalculateOnBarClose = true;
    Overlay = false;
    PriceTypeSupported = true;
    }

    /// </summary>
    protected override void OnStartUp()
    {
    _ht = HilbertTransform2 (Input, Alpha);
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate ()
    {
    double period = _ht.Period [0];
    if (period >= CurrentBar)
    return;

    double value = Input [0] - Input [(int) Math.Floor (period)];

    double a1 = Math.Exp (-Math.PI / Cutoff);
    double b1 = 2 * a1 * Math.Cos (1.738 * Math.PI / Cutoff);
    double c1 = a1 * a1;

    double coeff2 = b1 + c1;
    double coeff3 = -c1 * (1 + b1);
    double coeff4 = c1 * c1;
    double coeff1 = 1 - coeff2 - coeff3 - coeff4;

    if (CurrentBar < 4)
    Value.Set (value);
    else
    Value.Set (coeff1 * value + coeff2 * Value [1] + coeff3 * Value [2] + coeff4 * Value [3]);
    }

    #2
    Hello,

    Thank you for the post.

    One major difference between the two modes would the data that is being referenced with bars ago. With COBC = true, 0 bars ago represents the most recent Closed bar, with COBC = false this would reference the most recent price of the building bar. There is a 1 bar difference in that respect, this could end up changing the overall logic or calculations if this is not taken into account.

    Likely the easiest way to determine if this is the cause of the difference you are seeing would be to make a copy of the script, and use 1 extra BarsAgo for the items you use a BarsAgo with. Then compare the copy to the original, if the copy while using COBC = false now matches the original, that was likely the case.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Rapine Heihei, 04-23-2024, 07:51 PM
    2 responses
    30 views
    0 likes
    Last Post Max238
    by Max238
     
    Started by Shansen, 08-30-2019, 10:18 PM
    24 responses
    943 views
    0 likes
    Last Post spwizard  
    Started by Max238, Today, 01:28 AM
    0 responses
    9 views
    0 likes
    Last Post Max238
    by Max238
     
    Started by rocketman7, Today, 01:00 AM
    0 responses
    7 views
    0 likes
    Last Post rocketman7  
    Started by wzgy0920, 04-20-2024, 06:09 PM
    2 responses
    28 views
    0 likes
    Last Post wzgy0920  
    Working...
    X