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

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

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

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

*** Disclaimer *** StockFetcher.com 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. StockFetcher.com does not recommend particular securities. StockFetcher.com, 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 2022 - 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


This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.