Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Why check IsRemoveLastBarSupported?

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

    Why check IsRemoveLastBarSupported?

    I was hoping someone could explain what's going on below in this snippet of WMA indicator code. Why is there two sets of code depending on if IsRemoveLastBarSupported is set?

    The description of IsRemoveLastBarSupported is follows:

    "Determines if the bars type can use the RemoveLastBar() method when true, otherwise an exception will be thrown. Bar Types which use remove last bar concepts CANNOT be used with Tick Replay, and as a result Tick Replay will be disabled on the UI when IsRemoveLastBarSupported is set to true."

    Since the code is not calling RemoveLastBar(), what is the purpose of looking at IsRemoveLastBarSupported? What's the difference in the two sets of code and why is it required?


    Code:
            protected override void OnBarUpdate()
            {
                if (BarsArray[0].BarsType.IsRemoveLastBarSupported)
                {
                    if (CurrentBar == 0)
                        Value[0] = Input[0];
                    else
                    {
                        int back = Math.Min(Period - 1, CurrentBar);
                        double val = 0;
                        int weight = 0;
                        for (int idx = back; idx >= 0; idx--)
                        {
                            val += (idx + 1) * Input[back - idx];
                            weight += (idx + 1);
                        }
                        Value[0] = val / weight;
                    }
                }
                else
                {
                    if (IsFirstTickOfBar)
                    {
                        priorWsum = wsum;
                        priorSum = sum;
                        myPeriod = Math.Min(CurrentBar + 1, Period);
                    }
    
                    wsum = priorWsum - (CurrentBar >= Period ? priorSum : 0) + myPeriod * Input[0];
                    sum = priorSum + Input[0] - (CurrentBar >= Period ? Input[Period] : 0);
                    Value[0] = wsum / (0.5 * myPeriod * (myPeriod + 1));
                }
            }


    #2
    Hello linuxguru,

    Thank you for your reply.

    That bit of code is actually in reference to the bars type of the chart the indicator gets applied to. It calculates differently based on whether or not that bars type redraws the bar at some point, for example, renko bars redraw the open and the indicator must calculate slightly differently if that bar type is used.

    Here's a link to an older post here on our forum which goes in depth on discussing the WMA indicator and why the code for the two sections is different:



    Please let us know if we may be of further assistance to you.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    116 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    61 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    40 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    44 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    82 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X