Filter rule buy sell
Marks when price has risen a set percentage off its recent low (buy) or fallen off its recent high (sell).
For each bar it takes the lowest and highest close over the last k bars, the current bar included. Buy is on while the close sits more than up above that low, and sell is on while it sits more than down below that high; up and down are fractions, so 0.01 means 1%. Each output is a level test, not a crossover, so it stays on for as long as the condition holds, and buy and sell can both be on at once.
How to read it
- Buy markers sit on candles more than up above the lowest close of the last k bars: price has bounced off a recent low.
- Sell markers sit on candles more than down below the highest close of the last k bars: price has dropped off a recent high.
- A run of markers is one stretch where the threshold stays crossed, so count the runs, not the markers.
- At default settings the chart is nearly empty: on the SPY sample buy never fired and sell marked one dip.
What it outputs
- Buy
- On every bar whose close is more than up above the lowest close of the last k bars, held for confirm_days bars. A bounce off a recent low, not a reversal call.
- Sell
- On every bar whose close is more than down below the highest close of the last k bars, held for confirm_days bars. A pullback from a recent high, not a short call.
When it fires
Buy fires on each bar the close is more than up above the lowest close of the last k bars: price has bounced off a recent low. Sell fires on each bar the close is more than down below the highest close: a pullback off a recent high. Neither is a reversal call.
Settings
- k
- Bars the low and high are taken over, the current bar included. A longer window reaches a further low and high, so more bars sit far enough from them to mark. At 1 neither output fires while up and down are 0 or more.
- up
- Required rise above the lowest close, as a fraction (0.01 is 1%). Lowering it makes buy fire more: 0.002 marks about 9% of bars on the SPY sample, 0 about 92%. Below 0 buy is always on.
- down
- Required drop below the highest close, as a fraction (0.01 is 1%). Lowering it makes sell fire more: 0.002 marks about 8% of bars on the SPY sample. Below 0 sell is always on.
- confirm_days
- Consecutive bars the condition must hold before a marker. At 1 every bar that meets it marks. At 2 or more only the bar that completes the run marks, one pulse per run, so markers are fewer and later. It counts one-minute bars, not days.
Pitfalls
- Rare at defaults: on the September 2026 SPY sample buy never fired and sell marked one dip of about 23 bars. Use a try preset or lower up or down to see markers.
- Not reversal calls: buy means price is already above its recent low and sell means it is already below its recent high. Both describe where price stands in its range, not where it goes next.
- The name confirm_days counts one-minute bars, not days, and at 2 or more the output is a one-bar pulse, so it cannot be read like the level at 1.