Adaptive position sizing
A position size that sits on its 0.1 floor at default settings, so on SPY one-minute bars it barely moves.
Sizes a position from two readings: how the current ATR compares with its recent average (higher volatility shrinks the size) and how far price moved over the last five closes or over the whole vol_window, whichever move is larger (a bigger move grows it). The size starts at min_position, is scaled by those readings, then held between min_position and max_position. If an ADX input is connected, the trend reading becomes ADX divided by 50 instead of price moves. On one-minute bars the price moves are too small to lift the size, so the floor almost always wins.
How to read it
- The line sits in its own pane below the price, on the same scale as min_position.
- A flat line on the floor means volatility and trend did not lift the size above its minimum.
- It rises above the floor only when the volatility factor times the trend factor passes 1, which needs ATR well under its recent average and a sizeable move. In the SPY sample at defaults it never did.
- A higher line that stays flat means the floor was raised, not that the market changed.
What it outputs
- Position size
- The position size returned each bar, on the same scale as min_position. Flat at 0.1 on SPY at defaults.
Settings
- min_position
- Sets the floor and the base size. The size never drops below it, so at defaults the flat line sits here; raising it lifts the whole line and lowering it drops it. Above the floor the size is this times the volatility and trend factors.
- max_position
- Caps the size from above. The formula cannot exceed 2.25 times min_position, so the cap only bites when it is set below that; at the default 0.5 it has no effect.
- vol_window
- Length of the ATR average and the close history. Shorter reacts to ATR swings sooner, and below 10 the trend factor freezes at 1 because the trend check needs 10 closes. Longer smooths the volatility baseline and reaches back further for the price trend.
- trend_window
- No visible effect. It sizes an ADX history of which only the latest value is read, and the price trend uses the vol_window lookback, so changing it leaves the chart unchanged.
Pitfalls
- In the SPY sample at defaults the size never left its 0.1 floor, so the line says almost nothing about the market. It is a sizing input, not a signal.
- The first five bars return a hard-coded 0.1 regardless of min_position, so a raised floor shows a dip below it at the start.
- trend_window has no effect on the output, and the volumes input only gates it: a missing volume blanks the bar, but the volume value itself is never used.