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:

    https://ninjatrader.com/support/foru...stbar-question

    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 WaveAtElliot, Today, 05:11 PM
    1 response
    7 views
    1 like
    Last Post hdge4u
    by hdge4u
     
    Started by bosajin, Yesterday, 09:15 AM
    5 responses
    36 views
    0 likes
    Last Post NinjaTrader_Jim  
    Started by Dolfan, Today, 12:24 PM
    4 responses
    23 views
    0 likes
    Last Post NinjaTrader_Jim  
    Started by WeyldFalcon, Today, 11:09 AM
    7 responses
    26 views
    0 likes
    Last Post WeyldFalcon  
    Started by DTSSTS, 08-10-2020, 09:48 AM
    12 responses
    67 views
    0 likes
    Last Post DTSSTS
    by DTSSTS
     
    Working...
    X