# Backtest - Strategy Builder

### 1. Overview

The Strategy Builder is a powerful tool for backtesting custom trading strategies on TradingView without writing any code. It allows you to connect signals from other indicators, build sequential entry and exit rules, and simulate trades with realistic leverage and risk management.

### 2. Core Concepts

The backtester operates on a simple but flexible logic system:

* **External Signals:** These are the inputs for your strategy. They are plots or values from other indicators on your chart (e.g., a moving average, RSI value, or a custom signal line).
* **Conditions:** A condition is a true/false check that compares an External Signal to a value (e.g., `Price` `Greater than` `Moving Average`).
* **Sequential Steps:** You can assign conditions to **Steps (1-5)**. The strategy must satisfy all conditions in Step 1 before it evaluates Step 2, creating a logical funnel for entries and exits.
* **Logic Gates (`AND`/`OR`):** Combine multiple conditions within the same step. `AND` requires all conditions to be true; `OR` requires at least one to be true.

<figure><img src="/files/YyPchvWip7cISbvliUVg" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}

#### **Hint: How the Alert Logic Works (Similar to Alerts Engine)**

The alert system evaluates conditions for any given step in a specific order. Understanding this is key to building complex alerts correctly.

* **Hierarchy is by Number:** The system processes conditions based on their input number (Condition 1, then Condition 2, then 3, and so on), not the order you enable them.
* **Boolean Chaining:** The `AND`/`OR` boolean operator for a condition connects it to the logical expression that comes *before* it in the sequence.
* **First Boolean is Ignored:** Because of this chaining, the boolean setting for the **very first enabled condition** in any step's sequence is **always ignored**, as there is no expression before it to connect to (this is why Condition 1 has no boolean input option).

**Example:**\
Imagine for Step 1 you enable:

* `Condition 2` (set to **OR**)
* `Condition 4` (set to **AND**)
* `Condition 5` (set to **OR**)

The final logic will be evaluated as: **(Condition 2) AND (Condition 4) OR (Condition 5)**.

The `OR` from Condition 2 was ignored. The logic used the `AND` from Condition 4 and the `OR` from Condition 5.
{% endhint %}

* **Leverage & Sizing:** The system simulates margin trading by calculating position sizes based on your chosen leverage and allocation method, including simulated liquidation prices.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://algoalpha.gitbook.io/algoalpha-user-manual/premium-indicators/backtest-strategy-builder.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
