Tradelyze

Guide

Strategy optimization

Last reviewed: 16 September 2026·Tradelyze

Strategy optimization is backtesting the same trading strategy many times with different input settings, then keeping the settings whose results look best. Each backtest is called a trial. The more trials a search runs, the more likely its best result fits luck in past prices rather than an edge that will repeat.

In plain English

Changing an RSI length from 14 to 20 in TradingView and re-reading the Strategy Tester is optimization by hand. An optimizer runs those trials automatically and keeps the best. Because the winners were picked on the same prices they are scored on, they must still prove themselves on new prices.

New to this? Start with in-sample vs out-of-sample.

What is trading strategy optimization?

Trading strategy optimization is a search for the best settings of a strategy whose rules stay the same. In Pine Script those settings are the strategy's inputs, such as an RSI length or a stop-loss percentage. In TradingView they appear on the Inputs tab of the strategy's settings. Commission, slippage and order size are different. They are strategy properties, set in the script's strategy() declaration or on the Properties tab, and TradingView strategy properties explains them.

One backtest with one combination of inputs is a trial. The number used to judge each trial is the objective, such as net profit or maximum drawdown. Maximum drawdown is the largest fall from an account peak to a later low. Every combination the optimizer is allowed to try makes up the search space.

A constructed example shows how quickly a search space grows. Suppose three inputs may each take a handful of values:

Testing every combination takes:

combinations = 11 × 5 × 5 = 275 trials

Adding a fourth input with 10 values turns 275 trials into 2,750. These figures are arithmetic on invented ranges, not measured data.

Optimization matters for your money because the best trial is chosen on the same price history it is scored on. Its backtest is an in-sample result, measured on the same data used to pick the settings. That makes it the most flattering number the whole search produced. It says little about future trading until the settings are tested on out-of-sample data, meaning prices the search never used.

Why does optimizing a trading strategy lead to overfitting?

Optimizing a trading strategy leads to overfitting because the optimizer keeps whichever settings scored best on one stretch of past prices. Part of every backtest score is luck. Overfitting, also called curve fitting, means settings that describe the random noise in that history rather than behavior that repeats. A setting can look excellent simply because its entries happened to line up with a few price swings that will not come again.

The more settings a search tries, the more chances some get to line up with noise. The search always reports the luckiest one. As a constructed example, suppose 100 settings of a strategy have no real edge and each has an even chance of a profitable backtest. On average about 50 of them would still show a profit, and the best of the 100 could look impressive. That arithmetic is invented to show the effect, not measured data. For a prop firm challenge, it means paying the fee on the strength of a number that was partly luck.

Three signs point to an overfit winner:

How many trials should an optimizer run, and why do more trials raise the bar?

No published source gives a correct trial count for a trading strategy; the right number balances two opposite risks. With too few trials, a genetic search, one that breeds new settings from the best previous ones, never gets past its first random guesses. With too many, the best trial becomes more likely to be a lucky fit to past prices.

Traders tend to underrate the second risk. Bailey, Borwein, López de Prado and Zhu studied it in a May 2014 paper in Notices of the American Mathematical Society. The abstract posted with that paper states that the higher the number of configurations tried, the greater is the probability that the backtest is overfit.

Each extra trial is another chance for a setting to match noise. The same Sharpe ratio is therefore weaker evidence as the best of 300 trials than as the best of 30. Overfitting and sample size explains why the trial count, more than the number of inputs, sets that risk.

In Tradelyze, the Optimization trials setting sits in the Walk-Forward & Robustness step of the Run Optimization window. The same panel appears when you submit a new strategy. It can be Automatic or Custom. Automatic sizes the budget from how many inputs your strategy searches, and never runs fewer than 60 trials. Custom takes a number within the range printed under the box. A separate Walk-forward trials setting sets how many trials run inside each walk-forward window.

Two account conditions change what that setting does. If walk-forward and robustness settings are not enabled for your account, the form is read-only and runs use the platform defaults. If you have never saved the settings, runs use the server's configured values until you do. That server trial count can be smaller than the Automatic budget. Either way, read the trial count in the results card header rather than assuming the form's value ran.

Tradelyze shows a warning for two kinds of Custom budget that quietly weaken a run:

A check that does not run shows NOT RUN on the robustness card. The robustness verdict can then be ACCEPTABLE at best; see parameter sensitivity.

A practical order of work helps. Search fewer inputs before adding trials, and fix the inputs you would never change. Write down how many trials produced the result you are about to trade.

What should an optimizer maximize?

An objective is the number an optimizer uses to judge each trial, such as net profit. No primary source names one correct objective for a trading optimizer, but single objectives fail in predictable ways. An optimizer rewards exactly what it is told to reward, so each objective's blind spot becomes the winning trial's weakness.

What an optimizer tends to select when told to maximize a single number
ObjectiveWhat the winning trial tends to look likeSource
Net profitLarge position risk and deep drawdowns, because nothing penalizes the path taken to the profitNo primary source; follows from the objective.
Profit factorSettings that barely trade, because two winning trades and no losers outscore hundreds of ordinary trades; see why optimizing for profit factor breaksNo primary source.
Win rateSmall profit targets with wide stops, where a few large losses can outweigh many small wins; see win rate and expectancyNo primary source.
Sharpe ratioSettings with few trades can score well, because a short run of steady winners shows little variationNo primary source.

Scoring every trial on several objectives at once shows the trade-off instead of hiding it. This is called a multi-objective search. A minimum trade count also stops the search from crowning a two-trade fluke. Tradelyze's optimizer searches on profit, Sharpe ratio and maximum drawdown together; profit factor and win rate appear only as results.

For a prop firm challenge, give drawdown the most attention. The firm ends the account at a fixed loss, however profitable the strategy was. Prop firm rules and backtest metrics covers which numbers predict a breach.

What is multi-objective optimization and a Pareto front?

Multi-objective optimization judges each trial on two or more objectives at once instead of one. A trader usually wants higher profit and a smaller maximum drawdown, and those two goals pull against each other. Rather than forcing them into a single number, a multi-objective optimizer keeps every trade-off that is not clearly worse than another.

One trial dominates another when it is at least as good on every objective and better on at least one. The Pareto front is the set of trials that no other trial dominates.

Take three constructed trials. Trial A made 18% profit with a 12% drawdown. Trial B made 11% with a 5% drawdown, and trial C made 10% with a 9% drawdown. B dominates C, because B made more profit with a smaller drawdown. A and B do not dominate each other, because A made more money and B risked less. Both sit on the Pareto front. Choosing between them depends on how much drawdown you can accept.

A Pareto front of profit against maximum drawdown for twelve constructed trials Constructed illustration, not measured data. A scatter plot of twelve optimization trials, with maximum drawdown from 0% to 20% on the horizontal axis, where lower is better, and profit from 0% to 25% on the vertical axis, where higher is better. Five green points form the Pareto front and are joined by a dashed line: 3% drawdown with 6% profit; 5% drawdown with 11% profit, labeled B; 8% drawdown with 15% profit; 12% drawdown with 18% profit, labeled A; and 17% drawdown with 20% profit. Seven blue points are dominated, because at least one green point has both more profit and less drawdown: 6% drawdown with 4% profit; 7% with 7%; 9% with 10%, labeled C; 11% with 12%; 13% with 16%; 14% with 14%; and 16% with 9%. Trial B dominates trial C, while trials A and B are both on the front. Constructed illustration, not measured data: twelve trials 0% 5% 10% 15% 20% 25% 0% 5% 10% 15% 20% Maximum drawdown (lower is better) Profit (higher is better) B A C On the Pareto front Dominated: a green trial has more profit and less drawdown
Constructed illustration, not measured data. Each green trial is a different trade-off between profit and drawdown. Each blue trial is beaten on both measures by at least one green trial, so it is never the better choice on these two objectives.

A Pareto front is useful to a prop firm trader because the firm closes the account at a fixed loss. A trial with less profit and a much smaller drawdown can be the better choice for a challenge. A ranking on profit alone would still put it lower.

How does Tradelyze's optimizer search?

Tradelyze searches with NSGA-II, a search that breeds new settings from the best previous ones. It uses the version built into Optuna, an open-source optimization library. Every trial is a full backtest of your Pine Script, and NSGA-II scores each one on three separate objectives rather than on a single blended number:

Before a trial's profit and Sharpe reach those objectives, Tradelyze scales both down when the trial took more than one trade per ten bars, so a setting that trades far more often than the data can support cannot win on volume alone. Drawdown is passed through unchanged.

A generation is one batch of trials. The search starts with a generation of randomly chosen settings. It only begins breeding new settings from the best ones once that first generation has run. In Tradelyze's implementation, the size of a generation depends on how many inputs are searched. The Automatic trial budget buys three whole generations: one random batch, then two rounds of breeding.

Generation size and Automatic trial budget by number of inputs searched
Inputs searchedTrials per generationAutomatic budgetSource
1 to 52060Tradelyze implementation (see Sources)
6 to 153090Tradelyze implementation (see Sources)
16 to 3040120Tradelyze implementation (see Sources)
More than 3050150Tradelyze implementation (see Sources)

Tradelyze's Automatic budget is never fewer than 60 trials. A Custom budget no larger than one generation never breeds a single new setting. Its result is then the best of a batch of random draws. How grid search and random search compare, and how NSGA-II sorts trials into fronts, is covered under Going deeper.

Tradelyze's recommended settings are chosen from every completed trial, not only from the Pareto front. After the search has finished, Tradelyze orders the completed trials with one combined ranking of the same three numbers: profit, the Sharpe (Bar) figure and maximum drawdown. That combined ranking is not a fourth objective and the search never optimizes it — NSGA-II optimizes the three separately, and the ranking exists only to put the finished trials in order, pick the recommendation and fill the Top Trials table. In the ranking, profit and Sharpe count for less when few trades support them. Trials with fewer than 5 trades are left out unless no trial reached 5.

For each prop firm you select, the recommendation is the highest-ranked trial that passes all of that firm's checked rules. When none passes, the highest-ranked remaining trial is shown as the closest attempt rather than a pass. When no prop firm rule set applies, the recommendation is simply the highest-ranked trial.

The combined ranking only puts trials in order. Tradelyze does not display it, and its size is not a quality score. A profitable strategy tested on a handful of trades can rank first with a score close to zero. Judge a trial by its own metrics, its trade count and the out-of-sample checks that follow the search, such as walk-forward analysis.

The trial count of a Tradelyze run depends on how many inputs are searched and on the Optimization trials setting. The number that actually ran is printed in the header of the optimization results card, in the form N trials (M feasible).

How should I set Fixed, Min, Max and Step values and ordering constraints?

Set each range to values you would genuinely trade. Use steps large enough that neighboring values behave differently. Fix every input you do not need to search. In Tradelyze these controls are in Step 1: Configure Parameters of the Run Optimization window.

That editor appears when the strategy has no optimization trials yet. It lists every input the search can change.

The columns of Tradelyze's Configure Parameters editor
ColumnWhat it doesHow to use it
OnA ticked input is searched; unticking it fixes the input at one valueUntick inputs you would never change, which shrinks the search
Parameter, Type, DefaultThe input's name, its kind (int, float, bool or categorical) and the value in your scriptUse Default as the starting point for a sensible range
Min and MaxThe lowest and highest value a searched number may takeStay within values you would really trade; the form rejects a Min larger than Max
StepThe gap between the values triedMust be positive and no larger than the range; a very small step adds near-identical trials
FixedThe value used for an input that is switched offStarts at the script default; change it only to hold the input at a different value

For true-or-false and list inputs, click the values the search may use instead of typing a range. A constructed example: an RSI length with a script default of 14, set to Min 8, Max 30 and Step 2, gives 12 values. The same range with Step 1 gives 23 values, nearly doubling that input's share of the search with lengths only one bar apart.

An ordering constraint keeps one input smaller than another, such as a fast moving-average length smaller than a slow one. In Step 2: Ordering Constraints, a rule reads left < right or left ≤ right. Tradelyze suggests a rule when two input names form a known pair. The pairs are fast and slow, short and long, min and max, low and high, entry and exit, and oversold and overbought.

A suggested rule can be switched off but not deleted, and a rule you add yourself can be removed. The form rejects a rule that compares an input with itself, and two rules that contradict each other.

When a proposed trial breaks an ordering constraint, the optimizer moves one of the two values. It usually raises the right-hand value, so the pair is back in order inside its ranges. An input you fixed is never moved to satisfy a rule. If the Min and Max values make the order impossible, the trial runs as proposed and the rule is not enforced. Check that the two ranges can actually be put in order.

How do I read the Top Trials table?

The Top Trials table lists up to five of the best-ranked trials from the search. It lets you compare the recommended settings with their closest alternatives. Tradelyze ranks them the same way it makes its recommendation, combining profit, Sharpe ratio and drawdown. Profit and Sharpe are weighted by how many trades support them. A losing result is never discounted that way.

Trials with fewer than 5 trades are left out unless no trial in the search reached 5, and identical settings appear only once. If the recommended settings are not among the five, Tradelyze adds them as an extra row at the bottom. The table appears even when no trial passed your firm's rules, so you can see the closest attempts. Clicking a column heading re-sorts the rows; the # column keeps each trial's rank.

What each column of the Top Trials table shows
ColumnWhat it shows
#The trial's position in the combined ranking
TrialThe trial's number in the order the search ran it
FeasibleYES or NO against the selected prop firm's rules; see what Feasible YES or NO means
Profit %Profit in account currency, with the percentage of starting capital beneath it
SharpeThe same bar-by-bar Sharpe ratio as the Sharpe (Bar) tile on the Best Metrics card
Max DD %The largest peak-to-trough fall in account currency, with the percentage beneath it
TradesThe number of closed trades
Win Rate %The share of trades that made money
PFProfit factor: gross profit divided by gross loss
First TradeWhen that trial's settings placed their first trade
TV Comparable FromThe first time from which the figures can be compared with TradingView's own; before it, indicators are still filling their history. See what TV Comparable From means

In the Top Trials table, a PF of 0.00 can mean no winning trades or no losing trades. A trial with no losses has no defined profit factor. Read the Win Rate % beside it, which will normally be 0% or 100% in those two cases.

Clicking a row opens that trial's full settings and four tools. Copy Pine Defaults copies the settings as Pine Script input lines. Download Trades saves the trial's trades as a CSV file. Verify Trial prepares a TradingView re-run. The TradingView Verification panel compares an uploaded TradingView trade list with the trial's backtest trades. Download Trades and the comparison panel need a trade list that was kept for that trial.

Constructed illustration, not measured data: why a smaller profit can rank higher
TrialProfit %Max DD %TradesHow the ranking treats it
Trial 4114.2%6.5%212Normally ranks higher: a solid result supported by many trades
Trial 8831.0%18.0%9Normally ranks lower: more profit, but nine trades earn little weight and the drawdown is large

Both rows are invented to show the ranking logic and do not come from a real run. For a prop firm trader, trial 41's 6.5% drawdown also leaves more room than trial 88's 18.0% under a firm's loss limit.

What does Feasible YES or NO mean in Top Trials?

Feasible YES means every rule of the selected prop firm's rule set was checked against that trial's trades and passed. Feasible NO means at least one rule failed, or at least one rule could not be checked. A rule normally cannot be checked when that trial's trade list was not kept. The table shows both cases as NO.

Every row normally reads NO when the run had no prop firm rule set to check. A column of NO values is therefore not proof that every trial broke a rule. When you select several firms, the results page still shows one Top Trials table. Its Feasible column follows one firm's rule set, normally the first you selected. Each firm's own card and its Rule Results table show which limit failed; what Qualifies and Not Feasible mean covers that card.

Feasible answers the firm's rules and nothing else. The feasible count in the card header also leaves out trials with fewer than 5 trades. A YES row can therefore be missing from that count. Neither covers evaluation time limits, news-trading restrictions or weekend-holding rules, which Tradelyze does not check. Both are also measured on the same in-sample data the search tuned on.

What does Verify Trial do?

Verify Trial checks whether a trial's result reproduces in TradingView before you rely on it. Tradelyze makes a copy of your Pine Script with that trial's settings written in as the input defaults. It then opens a new strategy draft, named after the trial, with the modified script attached.

You run that script in TradingView, export its trade list, and upload it with matching market data. Submitting the draft costs 1 credit and starts a normal run, beginning with Baseline Matching. Baseline Matching compares Tradelyze's backtest with your TradingView trades.

Before exporting, check that every input on the TradingView Inputs tab shows the value listed in the Verify Trial window. An input written in an unusual form in the script may keep its old default. For a quick comparison without a new submission, expand the trial's row and use Upload TV CSV in the TradingView Verification panel.

A trial that reproduces in TradingView has shown that the backtest is faithful, not that the settings will keep working. The settings are still in-sample, so the next evidence to read is walk-forward analysis on data the search did not use. If a later check fails, what to do when a strategy fails validation covers what to change and what to leave alone.

Check it on your own strategy

In a Tradelyze report, the optimizer's output is Best Metrics, Recommended Parameters, the Parameter Search Space table and Top Trials. The optimization card header shows how many trials ran. How Tradelyze validates a strategy walks through every card. To judge the whole report, not one tile, use the pre-trade checklist. Tradelyze re-runs an uploaded TradingView Pine Script strategy from your exported trade list and price data. It then runs parameter optimization, walk-forward analysis, a five-check robustness score and prop firm rule checks. It does not place trades, give financial advice or guarantee a challenge pass, and it is in beta.

Create an account. Already a user? Open your strategies.

Going deeper

The sections below go deeper: how grid search, random search and genetic algorithms choose which settings to test, and how NSGA-II sorts trials into Pareto fronts. You can skip them and still read your own report.

How do grid search, random search and genetic algorithms differ?

Grid search, random search and genetic algorithms differ in how they pick the next combination of settings to test. None of them changes the fact that the winner is chosen on past data, so none of them protects against overfitting on its own.

How three common search methods choose which settings to test
MethodHow it chooses settingsStrengthWeaknessSource
Grid searchTests every combination on a fixed grid of valuesNothing on the grid is missedCost multiplies with each added input: 275 trials become 2,750No primary source; arithmetic.
Random searchDraws combinations at random from the allowed rangesTries more distinct values of each input for the same number of trialsCan miss a narrow region of good settings by chanceBergstra and Bengio, Journal of Machine Learning Research 13, 2012
Genetic algorithmStarts from a random population of settings, keeps the better ones, then breeds and mutates them into new candidatesSpends later trials near settings that already did wellNeeds several generations of trials, and chases whatever the backtest rewards, lucky or notDeb, Pratap, Agarwal and Meyarivan, IEEE Transactions on Evolutionary Computation 6(2), 2002, for NSGA-II

Bergstra and Bengio's paper, Random Search for Hyper-Parameter Optimization, reports that randomly chosen trials were more efficient than trials on a grid. They tested machine-learning models, not trading strategies, so read the result as evidence about search efficiency rather than about finding a trading edge.

A genetic algorithm borrows the idea of natural selection. Each round of candidate settings is a generation, and each new generation is bred from the better members of the one before it, with small random changes mixed in.

NSGA-II, short for Nondominated Sorting Genetic Algorithm II, is a genetic algorithm built around the Pareto front. Deb, Pratap, Agarwal and Meyarivan introduced it in IEEE Transactions on Evolutionary Computation in April 2002. It sorts each generation into fronts: first the trials no other trial dominates, then the trials dominated only by those, and so on. It keeps the trials on the best fronts, and favors trials spread out along a front so the search does not crowd into a single trade-off.

Stage 3 · step 10 of 18. Next in the learning path: Overfitting and sample size

Frequently asked questions about strategy optimization

What is strategy optimization?

Strategy optimization is backtesting the same trading strategy many times with different input settings, then keeping the settings whose results look best. Each backtest is a trial, and the number used to judge trials, such as profit or drawdown, is the objective. Because the winner is chosen on the same history it is scored on, its backtest is the most flattering result of the search and needs testing on unseen data.

What optimization method does Tradelyze use?

Tradelyze uses NSGA-II, a search that breeds new settings from the best previous ones, as built into the open-source Optuna library. Deb, Pratap, Agarwal and Meyarivan published NSGA-II in 2002. Each trial is a full backtest of your Pine Script, scored on three separate objectives: maximize profit, maximize the bar-by-bar Sharpe (Bar) figure, minimize maximum drawdown. With Optimization trials set to Automatic, it runs three batches of trials, called generations, and never fewer than 60.

What is a Pareto front in trading strategy optimization?

A Pareto front is the set of trials that no other trial beats on every objective at once. With profit and drawdown as the objectives, a trial making 11% with a 5% drawdown beats one making 10% with a 9% drawdown, but not one making 18% with a 12% drawdown. The front shows the real trade-offs, so a trader can pick the risk level a prop firm allows.

Is Tradelyze's recommended trial always on the Pareto front?

No. Tradelyze chooses from every completed trial, not only the Pareto front. After the search ends it ranks trials with at least 5 trades, unless none reached 5, by one combined measure of profit, Sharpe (Bar) and drawdown that weights profit and Sharpe by trade count. That combined measure is never a search objective. For each selected prop firm, the recommendation is the highest-ranked trial that passes that firm's checked rules.

How many optimization trials should I run?

No published source gives a correct number for trading strategies. Tradelyze's Automatic setting runs at least 60 trials, enough for three rounds of its search. Fewer than 50 trials stops the parameter-sensitivity check from running. More trials raise the chance that the best result is a lucky fit. Search fewer inputs, record the trial count, and judge the winner on out-of-sample tests.

Why do more trials increase overfitting risk?

Every extra trial is another chance for some setting to fit random noise in past prices. In the abstract posted with their 2014 paper on backtest overfitting, Bailey, Borwein, López de Prado and Zhu state that the higher the number of configurations tried, the greater is the probability that the backtest is overfit. The same Sharpe ratio is therefore weaker evidence when it is the best of many trials than when it is the best of a few.

Is random search better than grid search for trading strategies?

Random search usually tries more distinct values of each input for the same trial budget. Bergstra and Bengio reported in the Journal of Machine Learning Research in 2012 that randomly chosen trials were more efficient than trials on a grid, though they studied machine-learning models rather than trading strategies. Neither method protects against overfitting, because both pick a winner on the same data they score it on.

Why does Tradelyze leave trials with fewer than 5 trades out of Top Trials?

A handful of trades can produce a spectacular profit or Sharpe ratio by luck alone. Tradelyze leaves trials with fewer than 5 trades out of the Top Trials ranking unless no trial in the search reached 5, and it weights profit and Sharpe by trade count, so a striking result on a few trades counts for little next to a good result on many.

What does Feasible NO mean in Tradelyze's Top Trials table?

Feasible NO means the trial failed at least one rule of the selected prop firm's rule set, or at least one rule could not be checked for that trial, usually because its trade list was not kept. The table shows both cases as NO, and every row normally reads NO when no prop-firm rule set applied. Each firm's own card and Rule Results table show which limit failed.

What happens when I click Verify Trial?

Verify Trial creates a copy of your Pine Script with that trial's settings as the input defaults and opens a new strategy draft with the copy attached. You run the script in TradingView, then upload its trade list and matching market data. Submitting the draft costs 1 credit and starts a normal run that checks whether Tradelyze's backtest matches the TradingView trades.

Should I optimize for profit factor or win rate?

Neither works well alone. An optimizer maximizing profit factor tends to pick settings that barely trade, and one maximizing win rate tends to pick small targets with wide stops, where a few large losses outweigh many small wins. No primary source names a single best objective; combining profit with drawdown and requiring a minimum number of trades avoids the worst of both failures.

Are optimized settings ready to trade?

No. Optimized settings are in-sample: they were picked because they did well on the same prices they are scored on. Check the trade count, test the settings on data the search never used with walk-forward analysis, confirm the result reproduces in TradingView, and compare the drawdown with your prop firm's limits before risking money or a challenge fee. Tradelyze does not guarantee that any result will repeat.

Questions about Tradelyze files, credits and accounts are answered in the Learn FAQ.

Sources