-
Notifications
You must be signed in to change notification settings - Fork 0
03 Modules Risk Management
Łukasz Rafał Czarnacki edited this page Mar 9, 2026
·
1 revision
Source package: src/trade_lab/risk_management
TradeLab separates risk policies from strategy generation. Strategies attach risk objects as plain attributes, and BacktestEngine consumes them when positions are opened and updated.
base.pytake_profit.pystop_loss.pytrailing_stop.py
BaseTakeProfit.compute(entry_price, direction, signal_strength, bar) -> float | NoneBaseStopLoss.compute(entry_price, direction, signal_strength, bar) -> float | NoneBaseTrailingStop.compute_initial(...) -> float | NoneBaseTrailingStop.update(current_stop, direction, signal_strength, bar) -> float
Trailing stops also share step_points, which prevents tiny stop updates unless the new stop improves by at least that amount.
-
FixedTP(base_points): fixed offset from entry -
SignalStrengthTP(base_points): offset scales withabs(signal_strength)
-
FixedSL(base_points): fixed offset from entry -
SignalStrengthSL(base_points): offset scales withabs(signal_strength) -
MovingAverageSL(column): uses an existing DataFrame column on the current bar -
ParabolicSARSL(...): usesbar["sar"]if available, otherwise seeds a SAR-like level from the current bar
FixedTS(base_points, step_points=10.0)SignalStrengthTS(base_points, step_points=10.0)MovingAverageTS(column, step_points=10.0)ParabolicSARTS(af_start=0.02, af_step=0.02, af_max=0.2, step_points=10.0)
- TP, SL, and TS exits are evaluated before threshold-based signal exits.
- For a long trade, the effective stop is the tighter of stop-loss and trailing-stop.
- For a short trade, the effective stop is the tighter upper bound.
-
trade_log.exit_reasonrecordstp,sl,ts, orsignal.
from trade_lab.risk_management import FixedSL, FixedTP, SignalStrengthTS
strategy.take_profit = FixedTP(base_points=8.0)
strategy.stop_loss = FixedSL(base_points=5.0)
strategy.trailing_stop = SignalStrengthTS(base_points=6.0, step_points=1.0)- Directly exportable:
FixedTP,SignalStrengthTP,FixedSL,SignalStrengthSL,FixedTS,SignalStrengthTS - Warning-only/manual mapping:
MovingAverageSL,MovingAverageTS,ParabolicSARSL,ParabolicSARTS
See MQL5 Export.
- Section Home
- Signals
- Signals Module
- Signals Usage Examples
- Indicators
- Indicators: Base API
- Indicators: Moving Averages
- Indicators: Oscillators
- Indicators: Volume
- Indicators: Trend/Volatility
- Indicators: Statistical/Kernels
- Strategies
- Risk Management
- Position Sizing
- Machine Learning