DrJimO 35 posts msg #124592 - Ignore DrJimO |
8/4/2015 2:38:31 PM
A basic coding question.
I'm trying to get the average high of an issue over a daily time period, but I want to be able to change the time frame without having to modify many lines of code. The code below returns correct values when I plug in the number "14" for days, but when I run it trying to use the "Days" variable instead (as shown below,) the values returned is 420 and 30 respectively for each issue.
Obviously, I am either doing something wrong of SF does not allow using a variable in this way?
/* Set up a day range in a variable so we can change it easily */
Set { Days, 14 }
and add column Days
Set { SumHigh, Sum(High, Days) }
and add column SumHigh
Set { AvgHigh, SumHigh / Days }
and add column AvgHigh
|
Kevin_in_GA 4,599 posts msg #124593 - Ignore Kevin_in_GA |
8/4/2015 3:39:47 PM
Why not just use the custom moving average() function?
You make the same change, but directly into the cma() function rather than creating a new function (which usually does not work as you are beginning to notice).
Kevin
|
DrJimO 35 posts msg #124594 - Ignore DrJimO |
8/4/2015 4:37:25 PM
Thanks Kevin - I'll give it a try.
Jim
|
DrJimO 35 posts msg #124607 - Ignore DrJimO |
8/5/2015 10:03:50 AM
Thanks Kevin
I was not aware the CMA function could provide the same result. I'm new to SF, but I am an experienced programmer in several languages.
Tried your suggestion and it works fine. However, defining a set variable and using it in subsequent calculations does not work.. Re: When replacing the period parameter with the "Days" variable, it causes an error. I assume this means that SF cannot substitute a predefined variable in a subsequent operation.
Re: ...
add column cma(high,14) /* ........works fine */
add column cma(high, Days) /* ....not valid */
Is there a way to accomplish this without extensive gyrations?
|
stockfetcher 980 posts msg #124608 |
8/5/2015 10:10:04 AM
StockFetcher does not support variables in place of numerical periods or offsets.
Hope that helps!
StockFetcher Support
|
DrJimO 35 posts msg #124612 - Ignore DrJimO |
8/5/2015 6:22:41 PM
OK Thanks. I was definitely getting that impression
Jim
|