jchariton 5 posts msg #162032 - Ignore jchariton |
11/19/2025 8:24:31 AM
Looking for help creating a filter that will give me stocks that:
yesterdays close is > 2x average daily price volatility
average volume > 1 millions shares per day
at least second consecutive day of this criteria
I started with this and am getting an error I can't fix - any ideas?
/* --- DEFINE AVERAGE DAILY % VOLATILITY --- */
set{avg_vol_pct, ( atr(20) / close ) * 100}
/* --- YESTERDAY'S % MOVE --- */
set{pct_move_yest, abs(close 1 day ago / close 2 days ago - 1) * 100}
/* --- 5× VOLATILITY THRESHOLD --- */
set{threshold, avg_vol_pct * 2}
/* --- FILTER: YESTERDAY'S MOVE > 5× VOLATILITY --- */
pct_move_yest > threshold
|
xarlor 627 posts msg #162033 - Ignore xarlor |
11/19/2025 9:46:32 AM
Oof, buddy. You got hit by a double whammy of SF syntax peculiarities:
1. SF can only do 1 operation per line. If you subtract something and divide in the same line, SF breaks. Split each operation into its own line.
2. abs() takes a single value. You cannot do an operation within it. Do all operations in prior lines, then take the single resulting value and put it in abs().
Here is the filter you posted in working form:
Now, to your original intent, I'm not understanding what your goal is.
"yesterdays close is > 2x average daily price volatility"
This is comparing the ticker's price with its (high - low) value. The two do not correlate. A ticker trading at $5 or more is always going to be higher than its trading range. Can you explain what you're going for in more detail?
|
jchariton 5 posts msg #162034 - Ignore jchariton |
11/19/2025 1:36:21 PM
this is perfect. thank you!
I don't get the one item per line caveat. For example how would I add to this filter
- market cap must be 1 billion
- average daily volume must be 1million
|
xarlor 627 posts msg #162035 - Ignore xarlor |
11/19/2025 5:43:41 PM
What I mean by multiple operations:
You had this:
set{avg_vol_pct, ( atr(20) / close ) * 100}
You are doing two operations in one line:
1. Division: atr(20) / close
2. Multiplication: * 100
You cannot have both in the same line. They must be split into two lines by assigning the first to a variable, then calling that variable on the second line and doing the next operation:
set{avg_vol_pct1,atr(20) / close}
set{avg_vol_pct,avg_vol_pct1 * 100}
Market cap is covered here.
Your volume requirement is a simple operation:
Putting it all together:
|
jchariton 5 posts msg #162036 - Ignore jchariton |
11/20/2025 7:16:10 AM
What I'm looking for is to see a stock that had an outsized move the previous day.
So for example if the average daily volatilty in stock XYZ is 1 percent, I want to see it if it has a 2 percent move.
but: I only want to see that if it has two consecutive days, at least, of 2 percent moves.
also I want to filter this list by a minimum market cap and average daily volume
|
jchariton 5 posts msg #162037 - Ignore jchariton |
11/20/2025 7:23:11 AM
The issue I'm having is the 'at least two days in a row' part. Does sf have this functionality?
|
jchariton 5 posts msg #162038 - Ignore jchariton |
11/20/2025 9:05:46 AM
I found a bug. The code you gave me uses the stock price as reference. I want to see stocks that are having 2x average daily volatility but your using average trading range as the variable. As a result as a stock goes down in price average the percentage move (vol) appears bigger and bigger.
I tried solving this as follows but am getting no results. please help!
set{market_cap, shares outstanding * close}
market_cap > 1
average volume(30) > 1
/* DEFINE AVERAGE DAILY PERCENT VOLATILITY */
// ---------- DAY PERCENT MOVE (20-day series) ----------
set{c_div_c1, close / close 1 day ago}
set{c_div_c1_minus1, c_div_c1 - 1}
set{day_pct_move, abs(c_div_c1_minus1) * 100}
// ---------- 20-DAY AVERAGE VOLATILITY ----------
set{avg_pct_vol, average(day_pct_move,20)}
/* YESTERDAY'S PERCENT MOVE */
set{pct_move_yest1, close 1 day ago / close 2 days ago}
set{pct_move_yest2, pct_move_yest1 - 1}
set{pct_move_yest3, abs(pct_move_yest2)}
set{pct_move_yest, pct_move_yest3 * 100}
/* 2x VOLATILITY THRESHOLD */
set{threshold, avg_pct_vol * 2}
/* FILTER: YESTERDAY'S MOVE more than 2x VOLATILITY */
pct_move_yest > threshold
add column market_cap
add column pct_move_yest
add column threshold
|
xarlor 627 posts msg #162039 - Ignore xarlor modified |
11/20/2025 11:59:05 PM
The bug you found I already mentioned in my first reply to you (see the last line of that reply).
As to why you are not getting results:
set{avg_pct_vol, average(day_pct_move,20)}
average is not a SF command. Try using cma instead:
|