Weekly EMA, empty value at bar 0, why?
Author: jackmanjls
Creation Date: 4/19/2011 5:23 PM
profile picture

jackmanjls

#1
I want to determine the weekly EMA and then do some processing based on those values. I have the editior setup so that the Scale: Daily, Data Range: 500bars. So in my script I want to temporarily set the time frame to weekly, determine the weekly ema and then set back to daily. I use the following code for that:

SetScaleWeekly();
DataSeries wema34H = EMA.Series(High, 34, EMACalculation.Modern);
RestoreScale();
wema34H = Synchronize( wema34H );

If I do a PrindDebug of wema34H[0] or any other index I always get 0.

Based on what I've explained am I using the proper programming sequence?

Another question. How do I create my own array and populate it?
profile picture

Cone

#2
[] is a [bar] indexer. So the value of your indicator at bar 0 is 0. It's likely to be zero for 34 * 5 bars, but it really depends on how the indicator is initialized..

In any case, an EMA is an unstable indicator so it takes approximately 3 times its period to generate stable values. You should start the trading loop on bar 34 * 5 * 3. (See WealthScript PRogramming Guide > Indicators > Stability of Indicators
profile picture

Eugene

#3
QUOTE:
Another question. How do I create my own array and populate it?

There's nothing Wealth-Lab specific about it: you would create an array just as in any other C#-based IDE.

Check out the C# tutorials we collected here: How do I start with C# ?
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).