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 mattbsea, Today, 05:44 PM
    0 responses
    2 views
    0 likes
    Last Post mattbsea  
    Started by RideMe, 04-07-2024, 04:54 PM
    6 responses
    31 views
    0 likes
    Last Post RideMe
    by RideMe
     
    Started by tkaboris, Today, 05:13 PM
    0 responses
    2 views
    0 likes
    Last Post tkaboris  
    Started by GussJ, 03-04-2020, 03:11 PM
    16 responses
    3,281 views
    0 likes
    Last Post Leafcutter  
    Started by WHICKED, Today, 12:45 PM
    2 responses
    19 views
    0 likes
    Last Post WHICKED
    by WHICKED
     
    Working...
    X