INVITE-ONLY SCRIPT
已更新

Backtest - Strategy Builder [AlgoAlpha]

3 051
🟠OVERVIEW
This script by AlgoAlpha is a modular Strategy Builder designed to let traders test custom trade entry and exit logic on TradingView without writing their own Pine code. It acts as a framework where users can connect multiple external signals, chain them in sequences, and run backtests with built-in leverage, margin, and risk controls. Its main strength is flexibility—you can define up to five sequential steps for entry and exit conditions on both long and short sides, with logic connectors (AND/OR) controlling how conditions combine. This lets you test complex multi-step confirmation workflows in a controlled, visual backtesting environment.

🟠CONCEPTS
The system works by linking external signals—these can be values from other indicators, and/or custom sources—to conditional checks like “greater than,” “less than,” or “crossover.” You can stack these checks into steps, where all conditions in a step must pass before the sequence moves to the next. This creates a chain of logic that must be completed before a trade triggers. On execution, the strategy sizes positions according to your chosen leverage mode (Cross or Isolated) and allocation method (Percent of equity or absolute USD value]). Liquidation prices are simulated for both modes, allowing realistic margin behaviour in testing. The script also tracks performance metrics like Sharpe, Sortino, profit factor, drawdown, and win rate in real time.

🟠FEATURES
  1. Up to 5 sequential steps for both long and short entries, each with multiple conditions linked by AND/OR logic.
    快照
  2. Two leverage modes (Cross and Isolated) with independent long/short leverage multipliers.
  3. Separate multi-step exit triggers for longs and shorts, with optional TP/SL levels or opposite-side triggers for flipping positions.
  4. Position sizing by equity percent or fixed USD amount, applied before leverage.
  5. Realistic liquidation price simulation for margin testing.
  6. Built-in trade gating and validation—prevents trades if configuration rules aren’t met (e.g., no exit defined for an active side).
  7. Full performance dashboard table showing live strategy status, warnings, and metrics.
  8. Configurable bar coloring based on position side and TP/SL level drawing on chart.
  9. Integration with TradingView's strategy backtester, allowing users to view more detailed metrics and test the strategy over custom time horizons.


🟠USAGE
Add the strategy to your chart. In the settings, under Master Settings, enable longs/shorts, select leverage mode, set leverage multipliers, and define position sizing. Then, configure your Long Trigger and Short Trigger groups: turn on conditions, pick which external signal they reference, choose the comparison type, and assign them to a sequence step. For exits, use the corresponding Exit Long Trigger and Exit Short Trigger groups, with the option to link exits to opposite-side entries for auto-flips. You can also enable TP and/or SL exits with custom sources for the TP/SL levels. Once set, the strategy will simulate trades, show performance stats in the on-chart table, and highlight any configuration issues before execution. This makes it suitable for testing both simple single-signal systems and complex, multi-filtered strategies under realistic leverage and margin constraints.

🟠EXAMPLE
The backtester on its own does not contain any indicator calculation; it requires input from external indicators to function. In this example, we'll be using AlgoAlpha's Smart Signals Assistant indicator to demonstrate how to build a strategy using this script.

We first define the conditions beforehand:
Entry:
  • Longs – SSA Bullish signal (strong OR weak)
  • Shorts – SSA Bearish signal (strong OR weak)

Exit
  • Longs/Shorts: (TP/SL hit OR opposing signal fires)

Other Parameters (⚠️Example only, tune this based on proper risk management and settings)
  • Long Leverage: default (3x)
  • Short Leverage: default (3x)
  • Position Size: default (10% of equity)

Steps
  1. Load up the required indicators (in this example, the Smart Signals Assistant).
  2. Ensure the required plots are being output by the indicator properly (signals and TP/SL levels are being plotted).
    快照
  3. Open the Strategy Builder settings and scroll down to "CONDITION SETUP"; input the signals from the external indicator.
    快照快照
  4. Configure the exit conditions, add in the TP/SL levels from the external indicator, and add an additional exit condition → {{Opposite Direction}} Entry Trigger.
    快照
  5. After configuring the entry and exit conditions, the strategy should now be running. You can view information on the strategy in TradingView's backtesting report and also in the Strategy Builder's information table (default top right corner).
    快照


It is important to note that the strategy provided above is just an example, and the complexity of possible strategies stretches beyond what was shown in this short demonstration. Always incorporate proper risk management and ensure thorough testing before trading with live capital.
發行說明
- Added step based condition invalidation options

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。