TP SL backtest

The Take Profit / Stop Loss (TP/SL) strategy is one of the most popular trading approaches in Profitsla. This guide covers all three TP/SL strategy variants and how to backtest them effectively.

TP/SL Strategy Types

TP/SL Long

  • Direction: Long positions only

  • Entry: Buy at market price

  • Exit: Take profit or stop loss triggers

  • Use Case: Bullish market conditions

TP/SL Short

  • Direction: Short positions only

  • Entry: Sell at market price

  • Exit: Take profit or stop loss triggers

  • Use Case: Bearish market conditions

TP/SL Hedge

  • Direction: Simultaneous long and short positions

  • Entry: Both long and short at market price

  • Exit: Independent TP/SL for each position

  • Use Case: Volatile or sideways markets

Parameter Details

Strategy Selection

  • TP_SL Long: Long-only strategy

  • TP_SL Short: Short-only strategy

  • TP_SL Hedge: Hedge strategy with both positions

Investment Parameters

  • investment_long: Capital allocated to long positions (USDT)

  • investment_short: Capital allocated to short positions (USDT)

  • Range: 1.0 to 100,000.0 USDT

Profit/Loss Parameters

  • take_profit_long/short: Profit target percentage (%)

  • stop_loss_long/short: Maximum loss percentage (%)

  • Range: 0.1% to 50.0%

Hedge-Specific Parameters

  • new_sl: Stop loss adjustment method

    • "triggered_price": Adjust to triggered price

    • "entry_price": Keep original entry price

Market Parameters

  • leverage: Position leverage (1x to 20x)

  • fee_rate: Trading fee rate (default: 0.0005 = 0.05%)

  • timeframe: Data interval (1h, 6h, 12h, 1d)

Validation Rules

Date Validation

  • Start date cannot be in the future

  • End date cannot be in the future

  • Start date must be before end date

  • Minimum range: 2 days

  • Maximum range: 60 days

Parameter Validation

  • Investment amounts must be > 0

  • Take profit percentages must be > 0

  • Stop loss percentages must be > 0

  • Leverage must be between 1 and 20

  • Fee rate must be between 0 and 1%

Error Handling

Common Errors

Error Categories

  • Data Errors: No price data, symbol not found

  • Parameter Errors: Invalid parameters, missing required fields

  • Date Errors: Invalid date range, future dates

  • Network Errors: Exchange API issues, rate limits

Performance Optimization Tips

Parameter Selection

  • Conservative TP/SL: Start with 3-5% TP, 1-2% SL

  • Risk-Reward Ratio: Maintain at least 2:1 TP to SL ratio

  • Leverage Usage: Use lower leverage for beginners (1x-3x)

  • Fee Consideration: Account for trading fees in profit calculations

Market Analysis

  • Trend Following: Use long strategies in uptrends

  • Mean Reversion: Use hedge strategies in ranging markets

  • Volatility Adjustment: Adjust TP/SL based on market volatility

  • Multiple Timeframes: Test across different timeframes

Ready to explore the Liquidation strategy? Continue to Liquidation Strategy Backtest.

Last updated

Was this helpful?