Dev.to
7/21/2026

The original title is "Position Sizing and ATR-Based Stops for Algorithmic Trading Bots"
Original: The Matrix: Mastering Position Sizing & Stops in Algorithmic Trading
Short summary
A practical guide to position sizing and stop-loss design for algorithmic trading bots, contrasting a naive fixed-risk approach with a volatility-aware upgrade using ATR-based stops. Includes Python code for both versions using pandas and ta libraries. The core insight: position size should scale with account equity and instrument volatility, keeping dollar risk constant regardless of market conditions.
- •Naive fixed-percentage risk fails when volatility spikes; ATR-based stops adapt automatically
- •Position size = risk_per_trade / (stop_distance * pip_value), with stop distance from ATR
- •Includes before-and-after Python code for both naive and risk-aware execution
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



