Generic Signal Backtesting with Percentage Stops and Risk-Based Sizing
Summary
This script provides a simple framework for backtesting externally supplied long and short signals. It interprets an increase in each input series as a signal, enters only while flat, and attaches percentage-based stop-loss and take-profit orders to open positions. The stop and target are calculated from the average entry price, with mirrored formulas for long and short trades.
Position quantity is intended to scale with a chosen fraction of current equity divided by the monetary loss implied by the stop distance. The strategy also specifies a commission assumption and plots entry markers and active exit levels. The document gives implementation details but no performance evidence. Its position-size calculation references the average price before the entry is established, so sizing behavior should be checked in the platform; signal series must also be encoded appropriately for the change-based trigger. The example does not model slippage or explain how to validate supplied signals.
Key ideas
- The framework accepts separate source series for long and short signals.
- A positive change in either source series triggers an entry when no position is open.
- Stops and profit targets are set as percentages of average entry price.
- Position quantity is intended to tie stop-distance exposure to a selected equity risk fraction.
- The script includes commission settings but provides no backtest results or slippage treatment.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.