Looping thru a Dataset (SMA Issue)
Author: wycan
Creation Date: 12/19/2008 2:19 PM
profile picture

wycan

#1

Would appreciate if someone could look at this code snipped and see what I may be doing wrong. I'm trying to loop thru a dataset and calculate the relative strength (RS) for each symbol in the list based on it's 126 SMA. The problem comes in for stocks that have less than 126 days. For some reason, Bars.Count always evaluates to the number of bars in the datapane (even after SetContext), so I am unable to skip those stocks. Further, somehow it calculates an erroneous SMA for those stocks. Any ideas ? Is there a better way to do this ? thx



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

Cone

#2
SetContext(DataSetSymbols[ds],true);

The "true" means that you're synching the symbol raw data to the primary series. (See the WealthScript Programming Guide: DataSeries > Accessing Secondary Symbols > Secondary Series Synchronization)

So, the answer is to calculate your RSs using the symbols' raw data (i.e., before synch) and then use the Synchronize command to synch the series to the chart.
profile picture

wycan

#3
thx Cone.