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.
    Kate W.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Tim-c, Today, 02:10 PM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by Taddypole, Today, 02:47 PM
    0 responses
    2 views
    0 likes
    Last Post Taddypole  
    Started by chbruno, 04-24-2024, 04:10 PM
    4 responses
    50 views
    0 likes
    Last Post chbruno
    by chbruno
     
    Started by TraderG23, 12-08-2023, 07:56 AM
    10 responses
    401 views
    1 like
    Last Post beobast
    by beobast
     
    Started by lorem, Yesterday, 09:18 AM
    5 responses
    25 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X