Further Clarification on Data Aliasing

[follow_me]I was speaking with Mike Chalek on the phone this weekend concerning Data Aliasing and he felt this post was a little confusing. After re-reading it I can see where he is coming from. Using the same example let me see if I can clarify: assume the trading day is Wednesday and you want to keep track of the slope of a 19-day weighted moving average of data2 (weekly bars) by using a variable. The following code will give an erroneous result:

wAvg = wAverage(c of data2,19);
mySlope = wAvg – wAvg[1];

If you interrogate mySlope intra-week then it will always be equal to zero. The wAvg is by default tied to data1 which in this case is daily bars. So the value of wAvg is carried over from one day to the next. It only changes when the average of the weekly bar changes and that only occurs on Friday.

There are two possible solutions:

Without the use of data aliasing – inLine function calls
mySlope = wAverage(c of data2,19) – wAverage(c[1] of data2,19) ;

With the use of data aliasing –
vars: wAvg(close of data2,0);

wAvg = wAverage(c of data2,19);
mySlop = wAvg – wAvg[1];

Either examples will work, but if you have several variables tied to a different data stream, then the code will be much cleaner looking using data aliasing – plus it cuts down on multiple function calls.


Discover more from George Pruitt

Subscribe to get the latest posts sent to your email.

Leave a Reply