# Alerts Source: https://docs.luxalgo.com/docs/ai-backtesting/backtesters/alerts ## Backtester Alerts | Buy Alerts | Sell Alerts | | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | | | | Users can get alerted for any action executed by a strategy, from opening positions to closing them. The way alerts work is the same across all the Backtester scripts. The message field in the **Alert Messages** setting section of each Backtester allows for the strategy to send a custom alert message depending on the action taken by the strategy, if no messages are set the strategy will send default messages. In order for alerts to return custom user set messages the `{{strategy.order.alert_message}}` should be set on the message field of the Tradingview alert menu. Backtester (PAC) does not have Exit Long/Short TP/SL alerts, instead only having Exit Long/Short ## Alerts Placeholders Users can use placeholders in the messages set from the **Alert Messages** setting section to return market data, take profit/stop losses values, chart ticker and timeframe...etc. | Placeholder | Description | | :----------------------------------------------------: | :------------------------------------------------------------------------------------------------------------: | |
`{open}`
|
Current opening price
| |
`{high}`
|
Current high price
| |
`{low}`
|
Current low price
| |
`{close}`
|
Current closing price
| |
`{volume}`
|
Current volume
| |
`{time}`
|
UNIX timestamp (in milliseconds) of the bar opening time
| |
`{timenow}`
|
UNIX timestamp (in milliseconds) of the current bar time
| |
`{ticker}`
|
Chart ticker (e.g: for BINANCE:BTCUSDT the ticker name is BTCUSDT)
| |
`{prefix}`
|
Ticker prefix (e.g: for BINANCE:BTCUSDT the ticker prefix is BINANCE)
| |
`{timeframe}`
|
Chart timeframe
| |
`{tp}`
|
Take profit value
| |
`{sl}`
|
Stop loss value
| In order to function properly, `{timenow}` requires the strategy to recalculate on everytick. This can be enabled from the strategy settings -> Properties -> RECALCULATE If not enabled `{timenow}` will act like `{time}`. Example: New long entry generated at `{time}` and price `{close}` on `{ticker}{timeframe}` with take profit `{tp}` and stop loss `{sl}` # Forecasting Source: https://docs.luxalgo.com/docs/ai-backtesting/backtesters/forecasting Being able to anticipate where price might evolve after a trade can be useful to plan potential exit points, set take profits/stop loss as well as knowing when user set ones might get hit...etc. All Backtesters include a forecasting tool able to provide forecasts from the most recent trade executed by the backtester. ## Using Forecasts Forecasts can be enabled from the "FORECAST" settings group by enabling the "Show Forecast" toggle. Each forecast is influenced by the price evolution made during previous respective long and short trades, as such forecasts for long positions are different from the ones of short positions. Users can select the maximum length of forecast using the "Forecasting Length" setting. Because of the forecasting algorithm used, forecasts can have a lower length than the one selected by the user depending on the average bars in trade. Very frequent trades will generally return short price forecasts due to the lack of available data. ### Forecasting Area By default, forecasts are displayed alongside an area, indicating where future prices might evolve. The area extremities can help users potentially determines exit points with there interaction with the price, but can also help reference the performance of a current trade relative to past trades. Areas extremities are representative of past trades performances. For example: * For long positions: A lower extremity not significantly going below the entry price can indicate good past performance for long positions. * For short positions: An upper extremity not significantly going above the entry price can indicate good past performance for short positions. If an area is no longer visible in a point in time of the forecast it means that there is not enough data for that point in time. ### Forecasting Memory Users can control the influence older trades have on the forecast using the "Maximum Forecast Memory" setting, with lower values using a shorter term memory, discarding older information more quickly. Low values of this setting allow obtaining more diverse forecasts for new trades, while higher values will return forecasts less subject to change over time. ### Take Profits Levels From Forecast When forecasts are displayed, users can set take profits using the **nth** percentile of a returned forecast. This can be done from the "TPS & SLS" settings, by selecting "Forecast" in the "Long TP" and/or "Short TP". The numerical setting selected at the right of the drop-down menus determines the percentile used, and should be set within the range \[0, 100] in order to work. Percentiles values can affect the returned levels as follows: * In case of a long trade, a lower set percentile will return take profits closer to the entry price, potentially triggering sooner. * In case of a short trade, a lower set percentile will return take profits further away from the entry price, potentially triggering later. Do note that because forecasts are based on the strategy entries, take profits levels based on it can be subject to repainting, except when using a backtesting window based on a date. # Entry Rules Source: https://docs.luxalgo.com/docs/ai-backtesting/backtesters/osc/entry Backtester (OSC) allows users to set their own long/short entry rules from features of the Oscillator Matrix® as well as external indicators. Entry rules can be created separately for both long and short entries, and can be set using up to 8 different user set conditions. Each can be enabled by toggling them on using the toggle input on the left of each condition, if the enabled conditions are valid, the strategy will open a corresponding market order. ## Oscillator Matrix® Conditions Conditions for 6 features of the Oscillator Matrix® are included. These include: * Money Flow conditions * OverFlow conditions * HyperWave conditions * Reversal conditions * Divergences conditions * Confluence conditions The first dropdown determines the specific condition used for that feature, these can include generic conditional operators such as `Greater Than` or `Crossing`, or conditions proper to certain features such as `Any Bullish` in the HyperWave conditions. The second input setting allows the user to enter a numerical values, which is used when `Greater Than`, `Lower Than`, `Equal`, `Crossing Over`, `Crossing Under`, or `Crossing` are used. For example, if the user wants to go **Long** when the HyperWave oscillator crosses over 80, the following settings would be used: ## External Conditions Users can use the output of external indicators on the chart as input to set entry conditions. The second dropdown of external condition settings determines which conditional operator to use on both external outputs. These include: * Greater Than * Lower Than * Equal * Crossing Over * Crossing Under * Crossing The third external condition works similarly, but instead of comparing two external outputs, the condition will compare an external output specified in the condition first dropdown with a user set value in the third dropdown using a conditional operator set on the second dropdown. This last condition is particularly useful for oscillators. Here is an example of the third external condition being set for an RSI crossing over 50. ## Using Conditions Together More complex entry rules can be created by using multiple conditions together, this is done thanks to the **Step** dropdown setting on the right of each condition (below each condition for conditions 4 and 5). The *Step* setting is directly related to the Step & Match algorithm and work in two ways: * When two or more conditions have the same step number, both conditions are evaluated. Used to test matching conditions. * When two or more conditions have different step numbers, each conditions will be evaluated in order, testing for the first step and switching to the next step once the previous one is true. When the final step is true, the strategy will open a market order. Used to create a sequence of conditions. This operation is complementary, as you can create a sequence of conditions with one step consisting of two or more matching conditions as long as they have the same step number. A user wanting to go long when a bullish divergence occurs after any bullish reversal while money flow was bullish (over 50) could do it as follows: ### Invalidate Step The "Invalidate" step allows setting a condition as an "invalidation condition". When this condition is triggered while a sequence of conditions is incomplete, the sequence will restart at step 1. If multiple steps are set as "Invalidate" any of the conditions being true will reset the sequence of conditions, as such not all of them are required to be true for the sequence of conditions to reset. Let's take an example where we use 2 regular steps and one "Invalidate" step. The position will be opened when step 2 trigger after step 1 has been triggered. Step 1 condition trigger, we will now evaluate step 2 from now on. Invalidation step condition trigger, we reset the sequence and evaluate step 1 just after. ### Invalidation Behaviors Invalidation behaviors allow adding more restrictions to a sequence of conditions; users can use two different invalidation behaviors described below: #### Invalidate On Step 1 The "Invalidate On Step 1" behavior allows resetting an incomplete sequence of conditions when the condition on step 1 triggers. This prevents the first step condition from happening in between other steps of the condition sequence. This behavior is useful when the first step of our sequence of conditions needs to never be repeated during the sequence. Let's take an example where we use 3 regular steps. Step 1 condition trigger, we will now evaluate step 2 from now on. Step 2 condition trigger, we will now evaluate step 3 from now on. Step 1 condition trigger, we start evaluating step 2 from now. #### Invalidate On Any Repeated Step The "Invalidate On Any Repeated Step" behavior allows to reset an incomplete sequence of conditions when a step is triggered such that it does not respect the set order of conditions. This behavior is useful when we want a perfectly ordered sequence of conditions to complete, without any step repeating itself. Let's take an example where we use 3 regular steps. Step 1 condition trigger, we will now evaluate step 2 from now on. Step 2 condition trigger, we will now evaluate step 3 from now on. Step 1 or 2 conditions trigger, we start evaluating step 1 from now. ## No Existing Positions Requirement Users can enable the **Don't Allow Trades Until Closed** setting in order to only open trade when no existing positions are open. This setting allows waiting for a position to be closed before one can be opened. Enabling **Don't Allow Trades Until Closed** for long positions will prevent opening shorts as long as a long position is opened. If this same setting is not enabled for short conditions then shorts can effectively be closed by new long positions. # Exit Conditions Source: https://docs.luxalgo.com/docs/ai-backtesting/backtesters/osc/exits Users can close any position on a profit or loss using specific crossing conditions obtained from external sources. Exits conditions can be enabled in the **EXIT CONDITIONS** settings section. Oscillators are intended to be used as external source when it comes to TP/SL conditions, but users can directly create scripts returning scaled outputs from overlay indicators. ### Exit Take Profit Long/Short take profits exits conditions will exit a long or short position when a set condition is met such that the position exit on a profit. Take profits conditions are triggered if they are toggled on for a specific order (Long/Short) and if the selected external source is either **Crossing**, **Crossing Up**, or **Crossing Down**, **Greater Than**, **Lower Than**, or **Equal** to the numerical value specified by the user. ### Exit Stop Losses Long/Short stop losses exits conditions will exit a long or short order when a set condition is met such that the position exit on a loss. Stop losses conditions are triggered if they are toggled on for a specific order (Long/Short) and if the selected external source is either **Crossing**, **Crossing Up**, or **Crossing Down**, **Greater Than**, **Lower Than**, or **Equal** to the numerical value specified by the user. ### Time Exits Time exits allow users to exit trade from a specific time of the day. Note that trades are still exited at the opening of the next bar. The timezone is the same as the one of the chart symbol. ### Placeholders Exit Long Take Profit when closing price cross the upper Bollinger band extremity Users who do not wish to use a numerical value to evaluate a condition with an external source may use a placeholder instead, which allows using prices. The following placeholders are supported: * `open` : Opening price * `high` : High price * `low` : Low price * `close` : Closing price * `hl2` : Median price * `ohlc4` : Average price * `hlc3` : Typical price * `hlcc4` : Weighted price ## Exit on Entry Enabling the **Exit On Entry** setting will close any existing position when an entry condition leading to a new opposite position is met. ## Partial Exits Users can exit a percentage of an existing position by specifying a percentage lower than 100%. This can lead to sequential exit, with reduced exposure each time an exit is triggered. ## Only Exit On A Profit Enabling "Only Exit On A Profit" allows only triggering an exit if this exit leads to a profit, effectively preventing any exit that would lead to a loss. This can be useful to increase winrates of strategies. Enabling this setting alongside "Dont allow trades until closed" can prevent any losing trade from being exited, leading to a theoretical 100% winrate without a stop-loss. Do note however that a unprofitable trade can be held for an unlimited amount of time, leading to unrealistic scenarios. # Introduction Source: https://docs.luxalgo.com/docs/ai-backtesting/backtesters/osc/introduction Backtester (OSC) is a script that allows users to perform backtests using features from our [Oscillator Matrix®](/docs/algos/oscillator-matrix/introduction) toolkit. Users can create their own entry & exit conditions as well as control take-profit and stop-loss placement. Each core component of the backtester are described in the following pages: # Backtest Parameters The Backtester (OSC) use the following default properties: | Property | Default | Description | | ------------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Backtesting Window | Bars | Determines how the backtesting interval is set. If `Bars` is selected the most recent specified amount (in `Window (Bars)`) will be used to backtest the strategy. If `Date` is selected the interval will be set using the specified starting and ending dates, while using "Entire History" will use all the available historical data | | Window (Bars) | 2000 | Amount of the most recent bars used to backtest the strategy if `Bars` is selected in `Backtesting Window` | | Window Start | 2024-01-01 00:00 | Starting date of the backtesting strategy if `Date` is selected in `Backtesting Window` | | Window End | 2024-01-01 00:00 | Ending date of the backtesting strategy if `Date` is selected in `Backtesting Window` and if the `Window End` toggle is enabled | | Initial Capital | 10 000 | Initial amount of funds available at the start of the backtest | | Base Currency | Default | Currency used for performing the backtest, backtest statistics will be expressed using this curreny. If `Default` is selected the symbol currency is used | | Order Size | 1 Contract | Determines the amount of contracts/currency to buy or sell, can be expressed in contracts, currency, or percent of equity | | Commission | 0% | Fees paid per clotured trades, can be expressed as currency per contracts, currency per order, or % of the total transation value | | Margin for long position | 0% | Equity percentage required to fund a position | | Margin for short position | 0% | Equity percentage required to fund a position | These should be adjusted to return more precise and accurate results of the real performance of a trading strategy. # Disclaimer Backtests are not indicative of future results. Backtesting strategies on synthetic data does not return representative results of a strategy. Backtests should be performed on charts returning real closing prices. See [here](https://www.tradingview.com/script/q9laJNG9-Backtesting-on-Non-Standard-Charts-Caution-PineCoders-FAQ/) for more information. *CFTC Rule 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.* # Take Profit & Stop Loss Source: https://docs.luxalgo.com/docs/ai-backtesting/backtesters/osc/tpsl Users can set take profits and stop losses orders allowing a certain degree of money management in the backtest. Take profits and stop loss orders can be enabled and adjusted from the **FIXED TPS & SLS** settings section. Take profits and stop losses orders are placed relative to the price preceding a trade, and might not be filled at the exact price set by the user. ## TP/SL Options Take profits and stop losses for specific orders can be enabled from the toggles present in their settings section. Take profits and stop losses can be set using various methods described below: | Option | Description | | :-----------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | | Price |
Set the take profit/stop loss orders at the specified price.
| | Currency |
Set the take profit/stop loss orders a specified amount of currency away from the closing price preceding the entry of a long/short order.
| | Ticks |
Set the take profit/stop loss orders a specified amount of ticks away from the closing price preceding the entry of a long/short order.
| | % |
Set the take profit/stop loss orders a specified percentage away from the closing price preceding the entry of a long/short order.
| | ATR |
Set the take profit/stop loss orders *N* average true ranges away from the closing price preceding the entry of a long/short order, where *N* is a specified multiplier.
| | Forecast |
(Only available for take profits orders) Use a percentile of a returned forecast to set take profits. Forecasts must be enabled in order for this to work.
| | Trailing Stop |
(Only available for stop loss orders) Enable a percentage based trailing stop. A position will be exited if price reach the trailing stop.
| The average true range used to set take profits/stop losses orders make use of a period of 200 bars. ### Trailing Stop Users can use a percentage based trailing stop to exit positions. The trailing stop will move in the direction of interest if its distance with the low price(in case of long positions) or high price (in case of short positions) is greater than the specified percentage. ### Take Profits Levels From Forecast When forecasts are displayed, users can set take profits using the **nth** percentile of a returned forecast. This can be done from the "TPS & SLS" settings, by selecting "Forecast" in the "Long TP" and/or "Short TP". The numerical setting selected at the right of the drop-down menus determines the percentile used, and should be set within the range \[0, 100] in order to work. Percentiles values can affect the returned levels as follows: * In case of a long trade, a lower set percentile will return take profits closer to the entry price, potentially triggering sooner. * In case of a short trade, a lower set percentile will return take profits further away from the entry price, potentially triggering later. Do note that because forecasts are based on the strategy entries, take profits levels based on it can be subject to repainting, except when using a backtesting window based on a date. # Entry Rules Source: https://docs.luxalgo.com/docs/ai-backtesting/backtesters/pac/entry Backtester (PAC) allows users to set their own long/short entry rules from price action related concepts as well as external indicators. Entry rules can be built as sequences of conditions, matching conditions, or a mix of both. More details are provided in the section below. Entry rules can be created separately for both long and short entries, and can be set using up to 6 different user set conditions. Each can enabled by toggling them on using the toggle input on the left of each condition, if the enabled conditions are valid, the strategy will open a corresponding market order. Three types of distinct conditions are available, each described in the sections below. ## Price Action Conditions Conditions 1, 2, and 3 work the same way, and allow using conditions from market structures, volumetric order blocks, imbalances, and liquidity grabs. The first dropdown includes options: *Bullish* and *Bearish*, and determines the origin of the selected condition in the second dropdown. The second dropdown includes the list of price action related conditions, these include: | Condition | Description | | :-----------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------: | | CHoCH or BOS | Triggered on a change of character or break of structure | | CHoCH | Triggered on a change of character | | BOS | Triggered on a break of structure | | OB Mitigated | Triggered once price mitigates an order block | | OB Within | Triggered if price is within the area of an order block | | OB Entered | Triggered once price enters the area of an order block | | OB Exited | Triggered once price exits the area of an order block | | Imbalance Entered | Triggered once price enters the area of an imbalance | | Imbalance Within | Triggered if price is within the area of an imbalance | | Imbalance Mitigated | Triggered once price mitigates an imbalance | | Imbalance Exited | Triggered once price exits an imbalance | | Liquidity Grab | Triggered once a liquidity grab is detected | | Trendline Break | Triggered once a trendline is broken. Note that a bullish trendlinereffers to an uptrending trendline, while Bearish reffers to a downtrending trendline. | For example, if the user wants to go **Long** when a new **Bullish** **CHoCH** the following settings would be used: User can change the settings of each price action concept by scrolling down the settings, each concept has its own setting group. To learn more about each concept see: [Market Structures](/docs/algos/price-action-concepts/market-structures) [Order Blocks](/docs/algos/price-action-concepts/order-blocks) [Imbalances](/docs/algos/price-action-concepts/imbalances) [Liquidity Grabs](/docs/algos/price-action-concepts/liquidity) ## External Conditions Users can use the output of external indicators on the chart as input to set entry conditions. The second dropdown of external condition settings determines which conditional operator to use on both external outputs. These include: * Greater Than * Lower Than * Equal * Crossing Over * Crossing Under * Crossing The third external condition works similarly but instead of comparing two external outputs the condition will compare an external output specified in the condition first dropdown with a user set value in the third dropdown using a conditional operator set on the second dropdown. This last condition is particularly useful for oscillators. Here is an example of the third external condition being set for price crossing over a simple moving average. ## Session Condition Condition 6 is a session condition, with an active status if current time is within the specified session interval. Session timezone is the same as the one of the chart symbol exchange (UTC for cryptocurrencies) ## Using Conditions Together More complex entry rules can be created by using multiple conditions together, this is done thanks to the **Step** dropdown setting on the right of each condition (below each condition for conditions 4 and 5). The *Step* setting is directly related to the Step & Match algorithm and work in two ways: * When two or more conditions have the same step number, both conditions are evaluated. Used to test matching conditions. * When two or more conditions have different step numbers, each conditions will be evaluated in order, testing for the first step and switching to the next step once the previous one is true. When the final step is true the strategy will open a market order. Used to create sequence of conditions. This operation is complementary, as you can create a sequence of conditions with one step consisting of two or more matching conditions as long as they have the same step number. A user wanting to go long when a bullish break of structure occurs after price mitigated a bearish order block while price was above its 20 period moving average could do it as follows: ### Invalidate Step The "Invalidate" step allows to set a condition as an "invalidation condition". When this condition is triggered while a sequence of conditions is incomplete, the sequence will restart at step 1. If multiple steps are set as "Invalidate" any of the conditions being true will reset the sequence of conditions, as such not all of them are required to be true for the sequence of conditions to reset. Let's take an example where we use 2 regular steps and one "Invalidate" step. The position will be opened when step 2 trigger after step 1 has been triggered. Step 1 condition trigger, we will now evaluate step 2 from now on. Invalidation step condition trigger, we reset the sequence and evaluate step 1 just after. ### Invalidation Behaviors Invalidation behaviors allows adding more restrictions to a sequence of conditions, users can use two different invalidation behaviors described below: #### Invalidate On Step 1 The "Invalidate On Step 1" behavior allows to reset an incomplete sequence of conditions when the condition on step 1 trigger. This prevents the first step condition from happening in between other steps of the condition sequence. This behavior is useful when the first step of our sequence of conditions needs to never be repeated during the sequence. Let's take an example where we use 3 regular steps. Step 1 condition trigger, we will now evaluate step 2 from now on. Step 2 condition trigger, we will now evaluate step 3 from now on. Step 1 condition trigger, we start evaluating step 2 from now. #### Invalidate On Any Repeated Step The "Invalidate On Any Repeated Step" behavior allows to reset an incomplete sequence of conditions when a step is triggered such that it does not respect the set order of conditions. This behavior is useful when we want a perfectly ordered sequence of conditions to complete, without any step repeating itself. Let's take an example where we use 3 regular steps. Step 1 condition trigger, we will now evaluate step 2 from now on. Step 2 condition trigger, we will now evaluate step 3 from now on. Step 1 or 2 conditions trigger, we start evaluating step 1 from now. ## No Existing Positions Requirement Users can enable the **Don't Allow Trades Until Closed** setting in order to only open trade when no existing positions are open. This setting allows waiting for a position to be closed before one can be opened. Enabling **Don't Allow Trades Until Closed** for long positions will prevent opening shorts as long as a long position is opened. If this same setting is not enabled for short conditions then shorts can effectively be closed by new long positions. # Exit Rules Source: https://docs.luxalgo.com/docs/ai-backtesting/backtesters/pac/exits The strategy can include custom long/short orders exits rules. These can be created in a similar way than entry rules by using two available conditions, and can evaluate price action features as well as the output of external indicators on your chart. ## Price Action Conditions Conditions *Exit Long 1* and *Exit Short 1* allow using conditions from market structures, volumetric order blocks, and imbalances. The first dropdown includes options: *Bullish* and *Bearish* and determines the origin of the selected condition in the second dropdown. The second dropdown includes the list of price action related conditions, these include: | Condition | Description | | :-----------------: | :------------------------------------------------------: | | CHoCH or BOS | Triggered on a change of character or break of structure | | CHoCH | Triggered on a change of character | | BOS | Triggered on a break of structure | | Mitigated OB | Triggered once price mitigates an order block | | Within OB | Triggered if price is within the area of an order block | | Entered OB | Triggered once price enters the area of an order block | | Entered Imbalance | Triggered once price enters the area of an imbalance | | Within Imbalance | Triggered if price is within the area of an imbalance | | Mitigated Imbalance | Triggered once price mitigates an imbalance | ## External Conditions Conditions *Exit Long 2* and *Exit Short 2* allow the user to use the output of external indicators on the chart as input for setting exit conditions. These allow setting a condition based on two different external indicators output, with The first and third dropdowns determining which external output to use. The second dropdown determines which conditional operator to use on both external outputs. These include: * Greater Than * Lower Than * Equal * Crossing Over * Crossing Under * Crossing ## Using Conditions Together More complex exit rules can be created by using multiple conditions together, this is done thanks to the **Step** dropdown setting on the right of each condition (below each condition for *Exit Long 2* and *Exit Short 2*). The *Step* setting is directly related to the Step & Match algorithm and works in two ways: * When two or more conditions have the same step number, both conditions are evaluated. Used to test matching conditions. * When two or more conditions have different step numbers, each condition will be evaluated in order, testing for the first step and switching to the next step once the previous one is true. When the final step is true the strategy will open a market order. Used to create sequence of conditions. This operation is complementary, as you can create a sequence of conditions with one step consisting of two or more matching conditions as long as they have the same step number. ## Time Exits Time exits allow users to exit trade from a specific time of the day. Note that trades are still exited at the opening of the next bar. The timezone is the same as the one of the chart symbol. ## Exit on Entry Enabling the **Exit On Entry** setting will close any existing position when an entry condition leading to a new opposite position is met. ## Partial Exits Users can exit a percentage of an existing position by specifying a percentage lower than 100%. This can lead to sequential exit, with reduced exposure each time an exit is triggered. ## Only Exit On A Profit Enabling "Only Exit On A Profit" allows only triggering an exit if this exit leads to a profit, effectively preventing any exit that would lead to a loss. This can be useful to increase winrates of strategies. Enabling this setting alongside "Dont allow trades until closed" can prevent any losing trade from being exited, leading to a theoretical 100% winrate without a stop-loss. Do note however that a unprofitable trade can be held for an unlimited amount of time, leading to unrealistic scenarios. # Introduction Source: https://docs.luxalgo.com/docs/ai-backtesting/backtesters/pac/introduction Backtester (PAC) is a script that allows users to perform advanced backtests on all features from our [Price Action Concepts®](../../docs/algos/price-action-concepts/introduction) toolkit. Users can create their own entry & exit conditions as well as control take-profit & stop-loss placement. Each core components of the system is described on the following pages: # Backtest Parameters The Backtester (PAC) uses the following default properties: | Property | Default | Description | | ------------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Backtesting Window | Bars | Determines how the backtesting interval is set. If `Bars` is selected the most recent specified amount (in `Window (Bars)`) will be used to backtest the strategy. If `Date` is selected the interval will be set using the specified starting and ending dates, while using "Entire History" will use all the available historical data | | Window (Bars) | 2000 | Amount of the most recent bars used to backtest the strategy if `Bars` is selected in `Backtesting Window` | | Window Start | 2024-01-01 00:00 | Starting date of the backtesting strategy if `Date` is selected in `Backtesting Window` | | Window End | 2024-01-01 00:00 | Ending date of the backtesting strategy if `Date` is selected in `Backtesting Window` and if the `Window End` toggle is enabled | | Initial Capital | 10 000 | Initital amount of funds available at the start of the backtest | | Base Currency | Default | Currency used for performing the backtest, backtest statistics will be expressed using this curreny. If `Default` is selected the symbol currency is used | | Order Size | 1 Contract | Determines the amount of contracts/currency to buy or sell, can be expressed in contracts, currency, or percent of equity | | Commission | 0% | Fees paid per clotured trades, can be expressed as currency per contracts, currency per order, or % of the total transaction value | | Margin for long position | 0% | Equity percentage required to fund a position | | Margin for short position | 0% | Equity percentage required to fund a position | These should be adjusted to return more precise and accurate results of the real performance of a trading strategy. # Disclaimer Backtests are not indicative of future results. Backtesting strategies on synthetic data does not return representative results of a strategy. Backtests should be performed on charts returning real closing prices. See [here](https://www.tradingview.com/script/q9laJNG9-Backtesting-on-Non-Standard-Charts-Caution-PineCoders-FAQ/) for more information. *CFTC Rule 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.* # Take Profit & Stop Loss Source: https://docs.luxalgo.com/docs/ai-backtesting/backtesters/pac/tpsl Users can set take profits and stop losses orders allowing a certain degree of money management in the backtest. Take profits and stop loss orders can be enabled and adjusted from the **FIXED TPS & SLS** settings section. Take profits and stop losses orders are placed relative to the price preceding a trade, and might not be filled at the exact price set by the user. ## TP/SL Options Take profits and stop losses for specific orders can be enabled from the toggles present in their settings section. Take profits and stop losses can be set using various methods described below: | Option | Description | | :-----------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | | Price |
Set the take profit/stop loss orders at the specified price.
| | Currency |
Set the take profit/stop loss orders a specified amount of currency away from the closing price preceding the entry of a long/short order.
| | Ticks |
Set the take profit/stop loss orders a specified amount of ticks away from the closing price preceding the entry of a long/short order.
| | % |
Set the take profit/stop loss orders a specified percentage away from the closing price preceding the entry of a long/short order.
| | ATR |
Set the take profit/stop loss orders *N* average true ranges away from the closing price preceding the entry of a long/short order, where *N* is a specified multiplier.
| | Forecast |
(Only available for take profits orders) Use a percentile of a returned forecast to set take profits. Forecasts must be enabled in order for this to work.
| | Trailing Stop |
(Only available for stop loss orders) Enable a percentage based trailing stop. A position will be exited if price reach the trailing stop.
| The average true range used to set take profits/stop losses orders make use of a period of 200 bars. ### Trailing Stop Users can use a percentage based trailing stop to exit positions. The trailing stop will move in the direction of interest if its distance with the low price(in case of long positions) or high price (in case of short positions) is greater than the specified percentage. ### Take Profits Levels From Forecast When forecasts are displayed, users can set take profits using the **nth** percentile of a returned forecast. This can be done from the "TPS & SLS" settings, by selecting "Forecast" in the "Long TP" and/or "Short TP". The numerical setting selected at the right of the drop-down menus determines the percentile used, and should be set within the range \[0, 100] in order to work. Percentiles values can affect the returned levels as follows: * In case of a long trade, a lower set percentile will return take profits closer to the entry price, potentially triggering sooner. * In case of a short trade, a lower set percentile will return take profits further away from the entry price, potentially triggering later. Do note that because forecasts are based on the strategy entries, take profits levels based on it can be subject to repainting, except when using a backtesting window based on a date. # Entry Rules Source: https://docs.luxalgo.com/docs/ai-backtesting/backtesters/s-o/entry Backtester (S\&O) makes use of various features within the Signals & Overlays® toolkit such as [Confirmation and Contrarian Signals](/docs/algos/signals-overlays/signals) or [Overlays indicators](/docs/algos/signals-overlays/indicator-overlay) to specify entry rules for the strategy. More information regarding signal settings can be found [here](/docs/algos/signals-overlays/signal-settings) By default, backtesting is performed using the most recent 2000 bars, this value can be changed from the **Backtest Window (Bars)** setting, the user can also perform a backtest between two specified dates using the "Date" options in "Backtesting Window", or using all the available chart history by using "Entire History" (note that this will not allow the optimizer to run). ## Long/Short Entry Conditions Users can specify their strategy respective long/short entry rules from the **LONG CONDITIONS** and **SHORT CONDITIONS** settings sections, using the following available options: | Condition | Options | Options (2) | Description | | :------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | | Signal Type | | |
Enter a position on the occurrence of the user specified signal. Users can select between the Confirmation and Contrarian signals algorithm (Long/Short conditions can use different algorithms), these are affected by the selected Sensitivity and Autopilot frequency settings.

Selecting "Bullish Classifier" or "Bearish Classifier" will open positions on the occurence of a signal with the same classification as the one specified by the user on the rightmost input.
| | Reversal Zones | Cross Over R3, Cross Over R2, Cross Over R1, Cross Under S1, Cross Under S2, Cross Under S3, Above R3, Within \[R3-R2], Within \[R2-R1], Within \[R1-S1], Within \[S1-S2], Within \[S2-S3], Under S3 |
Enter a position if price is above/under or within the specified extremities.
| | | Smart Trail | | |
Enter a position if the Smart Trail switch bullish/bearish or if it is currently bullish or bearish.
| | Trend Tracer | | |
Enter a position if the Trend Tracer switch bullish/bearish or if it is currently bullish or bearish.
| | Trend Catcher | | |
Enter a position if the Trend Catcher switch bullish/bearish or if it is currently bullish or bearish.
| | Neo Cloud | | |
Enter a position if the Neo Cloud switch bullish/bearish or if it is currently bullish or bearish.
| | Trend Strength | | |
Enter a position if the Trend Strength is greater or lower than the specified value.
| | Session | Session interval | |
Enter a position if it is within the user specified session interval.
| | External Condition 1 | | |
Enter a position if the tested condition between the first specified external source and second one is true.
| | External Condition 2 | | |
Enter a position if the tested condition between the first specified external source and second one is true.
| | External Condition 3 | | |
Enter a position if the tested condition between the first specified external source and second one is true. Users can use price placeholers such as open, high, low, close, hl2, ohlc4, hlc3, and hlcc4 instead of a numerical value in the second source input.
| Multiple conditions can be enabled at the same time, in which case the backtester will require all conditions to be true in order to execute an order. If the **Exit On Signal** setting is enabled, existing positions will be exited on the occurrence of a confirmation/contrarian signal if enabled. ## No Existing Positions Requirement Users can enable the **Don't Allow Trades Until Closed** setting in order to only open trade when no existing positions are open. This setting allows waiting for a position to be closed before one can be opened. Enabling **Don't Allow Trades Until Closed** for long positions will prevent opening shorts as long as a long position is opened. If this same setting is not enabled for short conditions then shorts can effectively be closed by new long positions. # Exit Conditions Source: https://docs.luxalgo.com/docs/ai-backtesting/backtesters/s-o/exits Users can close any position on a profit or loss using specific crossing conditions obtained from a user-selected external source and/or by using our builtins exits. Exit conditions can be enabled in the **EXIT CONDITIONS** settings section. ## External Exits ### Exit Take Profit Long/Short take profits exit conditions will exit a long or short position when a set condition is met such that the position exits on a profit. Take profits conditions are triggered if they are toggled on for a specific order (Long/Short) and if the selected external source is either **Crossing**, **Crossing Up**, or **Crossing Down**, **Greater Than**, **Lower Than**, or **Equal** to the numerical value specified by the user. ### Exit Stop Losses Long/Short stop-losses exit conditions will exit a long or short order when a set condition is met such that the position exits on a loss. Stop losses conditions are triggered if they are toggled on for a specific order (Long/Short) and if the selected external source is either **Crossing**, **Crossing Up**, or **Crossing Down**, **Greater Than**, **Lower Than**, or **Equal** to the numerical value specified by the user. ### Placeholders Exit Long Take Profit when closing price cross the upper Bollinger band extremity Users who do not wish to use a numerical value to evaluate a condition with an external source may use a placeholder instead, which allows price data to be used. The following placeholders are supported: * `open` : Opening price * `high` : High price * `low` : Low price * `close` : Closing price * `hl2` : Median price * `ohlc4` : Average price * `hlc3` : Typical price * `hlcc4` : Weighted price ## Builtins Exits Built-in exits are included for the selected signal algorithm, these are the same as the ones present in the Signals & Overlays® toolkit and can be used in the Backtester to exit positions. Built-in exits will always exit a position on a profit. ## Time Exits Time exits allow users to exit trade at a specific time of the day. Note that trades are still exited at the opening of the next bar. The timezone is the same as the one on the chart symbol. ## Exit On Signal Enabling the **Exit On Signal** setting will close any position once a new confirmation or contrarian signal is generated (if enabled). ## Exit on Entry Enabling the **Exit On Entry** setting will close any existing position when an entry condition leading to a new opposite position is met. ## Partial Exits Users can exit a percentage of an existing position by specifying a percentage lower than 100%. This can lead to sequential exits, with reduced exposure each time an exit is triggered. # Introduction Source: https://docs.luxalgo.com/docs/ai-backtesting/backtesters/s-o/introduction