Stoch kd cross buy sell
Buy and sell markers where fast %K crosses %D inside the 0.2 or 0.8 zone, a momentum turn from an extreme.
This is a fast stochastic cross. %K is where the close sits in the highest high to lowest low of the last k_window bars, from 0 at the low to 1 at the high, and it is not smoothed. %D is the average of the last d_window %K values. A buy marks the bar %K crosses up through %D while %K is still below low_zone (0.2 by default); a sell marks the bar %K crosses down through %D while %K is above high_zone (0.8 by default).
How to read it
- Markers sit on the candles only. The %K and %D lines are not drawn by this indicator.
- A buy marker means %K has just risen through %D while in the bottom fifth of its recent range; a sell marker means it has just fallen through %D in the top fifth.
- Each marker is one bar. A stretch with no markers means no cross inside a zone, not a trend.
- At defaults on SPY one-minute bars the rule gave about 39 buys and 40 sells a day, so read the markers as a rhythm, not as entries.
What it outputs
- Buy
- True on the one bar %K crosses up through %D while %K is below low_zone. A single-bar event, not a state.
- Sell
- True on the one bar %K crosses down through %D while %K is above high_zone. A single-bar event, not a state.
When it fires
Fires on the bar %K crosses above %D while %K is below low_zone (buy), or crosses below %D while %K is above high_zone (sell). The moment is a momentum turn that starts from an extreme of the recent range. On the SPY sample: 823 buys and 839 sells in 20,160 one-minute bars.
Settings
- k_window
- Bars the high and low range looks back over. Raising it widens the range, so %K moves more slowly, reaches the zones less often and crosses less. Lowering it toward 5 makes %K swing between the ends on small moves, so markers come more often.
- d_window
- Bars %K is averaged over to make %D. Raising it smooths %D and delays its turns, so crosses come later and less often. At 1 %D equals %K and neither marker can ever fire. Lowering it to 2 makes %D track %K closely, so crosses are frequent.
- low_zone
- The buy marker needs %K below this level. Raising it toward 0.5 admits crosses from mid-range, many more markers. Lowering it to 0.05 keeps only deep oversold crosses. At 0 or below no buy fires; at 1 or above the check passes almost always.
- high_zone
- The sell marker needs %K above this level. Lowering it toward 0.5 admits crosses from mid-range, many more markers. Raising it to 0.95 keeps only top-of-range crosses. At 1 or above no sell fires; at 0 or below the check passes almost always.
- confirm_days
- Bars in a row a cross must hold before it marks. At 1 each cross marks. At 2 or more no marker ever fires, because a %K and %D cross lasts one bar. Keep it at 1.
Pitfalls
- confirm_days of 2 or more silences both markers: a %K and %D cross is true on one bar only, so a run of two never forms. Keep it at 1.
- d_window of 1 silences both markers too: %D then equals %K, and a line can never cross above itself.
- Inside a falling trend %K keeps crossing %D near 0, so buy markers repeat while price falls. The zone limits where a cross counts, not whether the trend continues.