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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    41 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    20 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    29 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    46 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    37 views
    0 likes
    Last Post CarlTrading  
    Working...
    X