Announcement

Collapse
No announcement yet.

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.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    599 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    344 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    558 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    557 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X