Obv ma cross buy sell
Marks where on-balance volume crosses its own moving average, up for buy and down for sell.
On-balance volume (OBV) is a running total of volume: each bar adds its volume if the close is above the prior close and subtracts it if below. The indicator compares OBV with its own moving average over ma_window bars, exponential by default. A buy marks the bar OBV crosses up through that average, and a sell marks the bar it crosses down. The OBV total starts at zero where the loaded history starts, so its level means nothing; only the crossings do.
How to read it
- Buy and sell are markers on the candles only. The OBV line and its average are not drawn.
- A buy marker means volume pressure has just turned up through its recent average; a sell marker means it turned down through it.
- Each marker is a single bar. A stretch with no markers means no cross, not a trend.
- At default settings the markers come about every 20 minutes on SPY, so read them as a rhythm, not as entries.
What it outputs
- Buy
- True on the one bar where OBV crosses up through its moving average. A single-bar event, not a state.
- Sell
- True on the one bar where OBV crosses down through its moving average. A single-bar event, not a state.
When it fires
Fires on the single bar where OBV crosses above its average (buy) or below it (sell). The same side cannot fire on two bars in a row. A marker means volume pressure just turned, not that a trend is established. On the SPY sample: 1036 buys and 1035 sells in 20,160 one-minute bars.
Settings
- ma_window
- Bars in the average that OBV is crossed against. Lowering it crosses more often (about 108 buys a day at 5 on SPY, 49 at 20); raising it crosses less (about 25 at 60, 12 at 200). At 1 the average is OBV itself, so nothing fires.
- confirm_days
- Raising it to 2 or more silences both outputs: a cross is true on one bar only, so the required run of bars never forms. On the SPY sample 2 and 3 gave zero markers. Keep it at 1.
- ema
- On uses an exponential average, which weights recent bars more. Off uses a plain average over the same window. Off gave about 48 buys a day against 49 with it on, so the choice barely changes the chart.
Pitfalls
- On one-minute bars the markers are mostly noise: about 49 buys and 49 sells a day at default, so flips back and forth are common.
- confirm_days of 2 or more never fires. The name suggests a confirmation filter, but a single-bar cross can never form the required run. This looks broken.
- The signal compares volume pressure with its own average and never checks price, so it can mark a buy while price is still falling.