StockFetcher Forums · General Discussion · Using a set variable<< >>Post Follow-up
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

3,828 posts
msg #124593
Ignore Kevin_in_GA
8/4/2015 3:39:47 PM

Why not just use the custom moving average() function?

add column cma(high,14)

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).


35 posts
msg #124594
Ignore DrJimO
8/4/2015 4:37:25 PM

Thanks Kevin - I'll give it a try.

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) /* fine */
add column cma(high, Days) /* ....not valid */

Is there a way to accomplish this without extensive gyrations?

963 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

35 posts
msg #124612
Ignore DrJimO
8/5/2015 6:22:41 PM

OK Thanks. I was definitely getting that impression

StockFetcher Forums · General Discussion · Using a set variable<< >>Post Follow-up

*** Disclaimer *** does not endorse or suggest any of the securities which are returned in any of the searches or filters. They are provided purely for informational and research purposes. does not recommend particular securities., Vestyl Software, L.L.C. and involved content providers shall not be liable for any errors or delays in the content, or for any actions taken based on the content.

Copyright 2016 - Vestyl Software L.L.C.Terms of Service | License | Questions or comments? Contact Us
EOD Data sources: DDFPlus & CSI Data Quotes delayed during active market hours. Delay times are at least 15 mins for NASDAQ, 20 mins for NYSE and Amex. Delayed intraday data provided by DDFPlus