StockFetcher Forums · Filter Exchange · Count feature on ROC indicator<< >>Post Follow-up
glgene
613 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
613 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
613 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?

Fetcher[
/*Count up weeks over past 4 weeks*/
symlist(xlb,xle,xlf,xli,xlv,xlu,xlp,xly,xlk,spy)

add column separator

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{p3, count(price 3 weeks ago > price 4 weeks ago,1)}

set{z, p0 + p1}
set{zz, z + p2}
set{zzz, zz + p3}

add column price 1 week ago{1wk.ago}
add column price 2 weeks ago{2wks.ago}
add column price 3 weeks ago{3wks.ago}
add column price 4 weeks ago{4wks.ago}

add column separator
add column zzz{Up.Wks}

Sort column 11 descending
]



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:

Fetcher[
/*Count up weeks over past 4 weeks*/
symlist(xlb,xle,xlf,xli,xlv,xlu,xlp,xly,xlk,spy)

add column separator

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{p3, count(price 3 weeks ago > price 4 weeks ago,1)}

set{z, p0 + p1}
set{zz, z + p2}
set{zzz, zz + p3}

add column price 1 week ago{1wk.ago}
add column price 2 weeks ago{2wks.ago}
add column price 3 weeks ago{3wks.ago}
add column price 4 weeks ago{4wks.ago}

add column separator
add column zzz{Up.Wks}
set{sort1,zzz * 1000000000}
set{sort, sort1 + volume}
add column sort
Sort column 12 descending
]



glgene
613 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:

Fetcher[
/*Count up weeks over past 4 weeks*/
symlist(xlb,xle,xlf,xli,xlv,xlu,xlp,xly,xlk,spy)

add column separator

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{p3, count(price 3 weeks ago > price 4 weeks ago,1)}

set{z, p0 + p1}
set{zz, z + p2}
set{zzz, zz + p3}

add column price 1 week ago{1wk.ago}
add column price 2 weeks ago{2wks.ago}
add column price 3 weeks ago{3wks.ago}
add column price 4 weeks ago{4wks.ago}

add column separator
add column zzz{Up.Wks}

set{a, close/ma(50)}
set{a1, 100}
set{a2, a*a1}
add column a2{price/ma50}
add column separator

set{sort1,zzz*1000}
set{sort, sort1+a2}
add column sort{2-lev.sort}

Sort column 14 descending
]



StockFetcher Forums · Filter Exchange · Count feature on ROC indicator<< >>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.