Average Volume For X days but excluding last two bars
Author: swuzy
Creation Date: 6/9/2015 1:46 AM
profile picture

swuzy

#1
I discovered that the volume data for most current bar is often incorrect (and subsequently corrected).

I would like to take the EMA volume of the most recent 20 bars, but not including the most recent 2 bars.

How might I code for that?

I am using:

CODE:
Please log in to see this code.


I tried
CODE:
Please log in to see this code.


but the name 'bar' does not exist yet, and cannot convert 'double' to WLDataSeries.

profile picture

Eugene

#2
No "bar" exists outside of the loop. You can:

1) either exclude the last two bars from the calculation by creating a custom series as shown in the WealthScript Programming Guide (DataSeries > Filling a Custom DataSeries, Example #2),

2) or simply offset Volume forward two bars using a shift operator (>> in this case) again like shown in WealthScript Programming Guide (DataSeries > Series Operators > How to: Offset or Delay a DataSeries) or in the QuickRef > DataSeries object:

CODE:
Please log in to see this code.
profile picture

swuzy

#3
Great. Thank you.

If I merely saw this in code without context, I would have thought the >> meant "advancing" the series, but the Guide also confirms the opposite to be the case.

So I also learn or assume by this that data series are set up such that the most recent bar is on the left side, not the right side.
profile picture

Eugene

#4
Advancing with >> in your example means that you take the value from the day before yesterday (because yesterday's value is believed to be incorrect today) and shift it one bar forward (the same principle applies for shifting more than 1 bar).

>> shifts from the "left" (a.k.a. the past) to the right edge.
profile picture

swuzy

#5
Aahh. Thank you for your clarifying illustration. Now it makes better sense to me.

Is that like pulling the railroad tracks to the front right, from under the standing train which is facing the right?
profile picture

Eugene

#6
:) Amusing analogy. Yes, that's right.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).