All indicators

Backtesting & Trading Engine

Jun 8, 2019

Static chart image
SignalsMoney Management

The Backtesting & Trading Engine indicator provides a comprehensive framework for developing, testing, and executing trading strategies within a single interface. It allows users to run simulations as a study to generate real-time alerts while simultaneously providing detailed backtesting statistics and performance metrics.

Usage

The Usage section describes how the script can be used to model and validate trading systems. Users can leverage over 40 built-in strategies for entries, filters, and exits, or integrate their own custom logic.

  • Study vs. Strategy Mode: The engine is designed as hybrid code. It can run as an indicator (study) to trigger alerts for automated or discretionary trading, or be converted into a strategy to utilize the native TradingView backtesting engine.
  • External Integration: By using the "External Indicator" setting, users can link their own indicators to the engine. The engine will process external signals for entries, exits, or filtering based on a specific protocol (+2/-2 for entries, +3/-3 for exits).
  • Risk Management: The tool emphasizes risk-based position sizing. Users can choose between fixed risk (based on stop-loss distance), a fixed percentage of equity, or a fixed percentage of initial capital.
  • Trade Management: The engine handles complex trade management features, including two-stage trailing stops, pyramiding (scaling into positions), and "Hard Exits" triggered by specific technical events.

Details

The engine calculates performance metrics on a bar-by-bar basis, including P&L, slippage, and commission fees. Unlike standard backtesting tools, it focuses on "X" (units of risk) rather than just currency. This allows traders to evaluate the statistical expectancy (APPT) of their system regardless of account size.

Post-Exit Analysis (PEA) A unique feature of this tool is the PEA module. After a trade is closed, the engine continues to track price action for a user-defined period. This identifies the maximum opportunity and risk that occurred after the exit, helping traders determine if their exit strategies are too conservative or if they are leaving significant profit on the table.

In-Trade Events The script monitors active trades for specific conditions, such as price approaching a stop-loss, potential market tops/bottoms, or significant price movements. these can be configured to trigger visual markers and alerts.

Settings

Display & Entries

  • Show Entry/Exit Markers: Toggles visual signals on the chart for trade executions.
  • Main/Alternate Entry Strat: Selects from built-in logic such as RSI crosses, Ichimoku signals, or Random entries.
  • Trade Direction: Restricts the engine to Longs Only, Shorts Only, or Both.

Filters & Stops

  • Filter Type: Additive filters (e.g., MA direction, Volume, Ichimoku) that must be met for an entry to trigger.
  • Entry Stop Selection: Defines the initial stop-loss method (ATR multiple, Fixed %, or External).
  • In-Trade Stop Selection: Determines the trailing stop logic (Chandelier, Volatility Stop, Donchian, etc.).
  • Kick-In Rules: Defines exactly when a trailing stop should take over from the initial entry stop.

Execution & Simulation

  • Pyramiding: Configures rules for adding to existing positions based on price or X-multiple increments.
  • Slippage & Fees: Allows for realistic performance modeling by deducting customizable transaction costs.
  • Post-Exit Analysis (PEA): Sets the number of bars to track price action after a trade concludes.

FAQ

How do I access the Backtesting & Trading Engine? You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.

Can I use this script for automated trading? Yes, by running the script in "Indicator" mode, you can configure alerts on entries, exits, and in-trade events to interface with third-party execution bots.

Why are results expressed in "X" instead of currency? "X" represents the initial risk taken on the trade. Expressing results in units of risk allows for a more accurate assessment of a strategy’s statistical expectancy and reward-to-risk performance across different instruments.

Free indicator

Get free access to this indicator on the platforms below.

TradingView
NinjaTrader
MetaTrader 4/5

Unlock the entire LuxAlgo Library

Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.