Feature request: custom optimization/loss functions for ProBacktest

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #262048 quote
    Daniel Klauser
    Participant
    Junior

    Hello everyone,

    I would like to suggest an improvement for the ProBacktest optimization module.

    At the moment, optimization is mainly based on predefined performance criteria such as total gain, win rate, max drawdown, max run-up, etc. These are useful, but they do not always describe what a trader really wants to optimize. ProBacktest already supports coded trading systems and variable optimization, but the optimization target itself seems limited to fixed metrics. (ProRealCode)

    It would be extremely useful if ProRealTime allowed users to define their own optimization or loss function directly in the strategy code.

    For example, instead of optimizing only for maximum profit, I might want to optimize for a combination of:

    net profit
    minus drawdown penalty
    minus volatility of the equity curve
    minus penalty for too few trades
    plus reward for smooth/linear equity growth
    

    A possible implementation could be something like:

    myLossFunction = StrategyProfit - 2 * MaxDrawdown + 1000 * LinearityScore
    OPTIMIZEON myLossFunction
    

    Or, if fully custom loss functions are too complex, a simpler first step could be to add a linearity coefficient between 0 and 1.

    The idea would be:

    1. Draw a straight reference line between the equity value after the first trade and the equity value after the last trade.
    2. Compare the actual equity curve to this line.
    3. Calculate a correlation or fit score between 0 and 1.
    4. Allow this value to be used as an optimization criterion.

    This would help identify strategies with smoother and more stable equity curves, instead of strategies that only show high final profit because of one or two lucky trades. In practice, many traders prefer a strategy with slightly lower profit but a much more regular equity curve, because it is often easier to trust and manage in live trading.

    This feature would also help reduce over-optimization based only on profit, win rate, or drawdown. A custom objective function would allow each trader to define what “good performance” means for their own risk profile and trading style.

    So my suggestion is either:

    Option 1: Allow a user-defined optimization/loss function in ProBacktest code.

    Option 2: Add a built-in “linearity” optimization metric.

    I think this would be a very powerful addition to ProBacktest and ProOrder development, especially for users who care about robustness and consistency, not only maximum backtest profit.

    What do you think? Would anyone else find this useful?

    GraHal thanked this post
    #262049 quote
    Nicolas
    Keymaster
    Legend

    In 2019, we had an interesting discussion on this topic: https://www.prorealcode.com/topic/backtest-sorting-by-lowest-drawdown/

    The general idea was to bypass certain strategies in the final optimization report simply by “quitting” (using the QUIT command) a backtest as soon as one of the criteria wasn’t favorable (for example, the maximum drawdown). We could also try other filter calculations to exclude certain results. Of course, this isn’t ideal compared to your idea (which I appreciate), but it could greatly help filter out some results deemed unacceptable. That said, even if we discard some backtests, the final result will still rank the remaining ones according to their maximum profit.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Feature request: custom optimization/loss functions for ProBacktest


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Nicolas
2 days ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/17/2026
Status: Active
Attachments: No files
Logo Logo
Loading...