Offset of a moving average?
Author: kvmp
Creation Date: 8/19/2010 9:15 AM
profile picture

kvmp

#1
How can I move back say a 5 period EMA by 3 periods
profile picture

Eugene

#2
Hit F11 to open the QuickRef tool, then click on "DataSeries Object" to read how to shift a data series.
profile picture

Cone

#3
Just a note on your terminology. While you can perform a "move back" operation with <<, almost for sure it's something that you don't want to do in a Trading Strategy because it automatically creates a peeking condition. Instead, to "move forward" or "delay" a series, use >>.
profile picture

kvmp

#4
Thank you Eugene and Cone,

It worked, but with a little problem. I shifted the EMA to the left. At the end the plotted EMA had a vertical line going right up to zero price. The script was:
CODE:
Please log in to see this code.


Thanks for your help
profile picture

Eugene

#5
This is not a problem, this is 1) exactly by design and 2) the incorrect (peeking) usage.

You're shifting future values to the past, so obviously, the 3 values (<<3) will be 0 because we can't see 3 bars to the future.
profile picture

kvmp

#6
Thank you Eugene and Cone for your help. In WL4, fundtimer developed the following script:

QUOTE:
{Offset EMA}
const Offset = 3;
var {Bar,} EMA11: integer;
EMA11 := OffsetSeries(EMASeries( #Close, 3), Offset);
for Bar := 3 to BarCount-1-Offset do
SetSeriesBarColor(Bar,EMA11,990);
for Bar := BarCount-1 downto BarCount-0-Offset do
@EMA11[Bar] := @EMA11[BarCount-1-Offset-0];
for Bar := BarCount-1 downto BarCount-0-Offset do
SetSeriesBarColor(Bar,EMA11,#Black);
PlotSeries( EMA11, 0, 0, 2 );

This assigns, say, yellow color to the shifted EMA, Then by assigning the same value to the last 3 days (= the value of the 4th day), and the color as that of the background (in this case black), the composite yellow EMA stands out without the last 3 days going to zero.

I translated this script to WL5, the whole composite EMA picks up the color assigned to the last 3 days. The translated script is:

CODE:
Please log in to see this code.


The script needs a little touch up to have different colors for the shifted EMA and the last 3 days. Please help.

profile picture

Cone

#7
1. When posting code, please click the CODE button and paste your code between the tags.

2. I'm really not interested in promoting or developing scripts that peek. Why are you?