fotchstecker 304 posts msg #152953 - Ignore fotchstecker |
7/4/2020 11:48:37 PM
I'm trying to get:
-the average open-to-high of the last 100 days
-the average open-to-low of the last 100 days
My code below doesn't appear to be right. Anyone have any ideas?
/* avg open to high, 100 days, pct */
set{OpenHi, high - open}
set{GoHi, count(OpenHi > 0, 1)}
set{AvgOpenHi100,sum(GoHi,100) / 100}
/* avg open to low, 100 days, pct */
set{OpenLow, open - low}
set{GoLo, count(OpenLow > 0, 1)}
set{AvgOpenLow100,sum(GoLo,100) / 100}
add column AvgOpenHi100
add column AvgOpenLow100
|
wantonellis 161 posts msg #152955 - Ignore wantonellis |
7/5/2020 8:53:13 AM
|
fotchstecker 304 posts msg #152961 - Ignore fotchstecker |
7/5/2020 4:54:12 PM
Many thanks, Wantonellis.
|
JoeyVinyl 125 posts msg #152981 - Ignore JoeyVinyl |
7/6/2020 11:38:51 AM
@fotchstecker
I think part of why you weren't getting what you wanted in your code there was that you were counting the number of days the high was above the open instead of finding the difference and averaging it, as wantonellis did nicely. It's not bad code because that info could be useful depending on what you're filtering for. It's just different than what you needed.
I'd also be careful about variable names. I wonder if using "open" as part of the variable name caused issues. I'm going to say it probably didn't since it wasn't by itself, but I don't know for sure. Personally I like to abbreviate words that might be problematic in variable names, like using "op" for open, "cl" for close - things like that.
|
fotchstecker 304 posts msg #152998 - Ignore fotchstecker |
7/7/2020 10:34:28 AM
Good points, Joey. I think my approach was based on something I had worked out in the past but wasn't really going to work for this. Also, I'm not sure if "open" was causing issues but I should have probably not used it all, to your point.
|