glgene 616 posts msg #128102 - Ignore glgene |
4/21/2016 9:15:33 PM
Is it possible in SF scripting to "count" how many Up weeks (ROC) selected ETFs have had over the past 4 weeks?
Example (using a Watchlist of some ETFs)
Symb UpWks
XLU .... 3
XLI .... 2
XLK ..... 1
XLF .... 4
SPY ..... 2
If it's doable, could you show me the 3-4 lines of code? Thanks so much.
Gene
|
glgene 616 posts msg #128103 - Ignore glgene |
4/21/2016 10:08:24 PM
Re: the start of my thread on this topic, I know how to partially script something "in the arena" I'm seeking (see below), but I don't know how to "count" how many Up ROC weeks ETFs (in a watchlist) have had over the past 4 weeks. Any suggestions for SF scripting to finish my project?
price > price 1 week ago
price 1 week ago > price 2 weeks ago
price 2 weeks ago > price 3 weeks ago
Gene
|
four 5,087 posts msg #128104 - Ignore four |
4/21/2016 11:34:27 PM
perhaps...
set{p0, count(price > price 1 week ago,1)}
set{p1, count(price 1 week ago > price 2 weeks ago,1)}
set{p2, count(price 2 weeks ago > price 3 weeks ago,1)}
set{z, p0 + p1}
set{zz, z + p2}
add column zz
|
glgene 616 posts msg #128108 - Ignore glgene |
4/22/2016 8:55:38 AM
"four" ... many thanks for your prompt reply. I applied your coding recommendation to the following script that I completed. I backtested it to Friday, April 15, 2016 to check results. Bingo! A question: Since I sorted on the # of Up Weeks, what is the "secondary sort" built inside SF when there is a tie (such as duplicate counts of 2 in the run dated April 15?
|
mahkoh 1,065 posts msg #128115 - Ignore mahkoh |
4/22/2016 12:50:35 PM
Not sure what the results are sorted by next, but you could add some code to achieve this. Suppose you want to sort by weeks up first and then by volume descending:
|
glgene 616 posts msg #128122 - Ignore glgene |
4/22/2016 5:42:28 PM
"mahkoh" --- Your idea of a 'pseudo' 2nd level sort works great. Using Volume -- as a 2nd part of the sort -- would not work for my intended purpose with ETFs, but something that does work suitably for me (2nd part of the sort) is Price/MA(50). See my SF script below. Some notes for SF subscribers who read this:
1) Use a run date of Friday, April 22, 2016
2) Primary part of the sort is the # of Up.Wks
3) Secondary part of the sort is Price/MA(50)
4) With only a few ETFs, this is no big deal (probably don't need it)
5) But with many ETFs (say 50), the 2-level 'pseudo' sort is VERY helpful
6) First result with the April 22, 2016 run is XLV (see next).
7) XLV has 4 Up.Wks (over the past 4 weeks)
8) XLV Price/MA(50) is 105.75, ie, price is 5.75% above MA(50)
9) Add the 2 fields together = 4105.75; [4 = 4 UpWks; 105.75 is Price/MA(50)]
10) Look at the next five ETFs, each with 3 UpWks;
Ahhh-- the 3 UpWks. tie breaker is the 2nd part of the sort. XLE is tops at 3109.93;
SPY is last of the 3's at 3103.82. Mission accomplished!
11) And so on. It works well as a 'pseudo' 2-level sort.
Thank you "four" and "mahkoh" for your help with this thread; without your assistance, I would NOT have figured it out. Here's my adjusted script:
|