# CONDITION MANAGER

{% hint style="success" %}
**CONDITION MANAGER** is a key module of the complex, which allows you to skillfully combine various external indicators to form trading signals or calculate constants. Thanks to its power, you can build most of your trading strategies using just **CONDITION MANAGER**" as if it's your Swiss Army knife in the world of trading.<br>

***Blocks of the module:***

* [*RULE*](#id-1.-rule)
* [*GROUP*](#id-2.-group)
* [*Logical Union of GROUPS*](#id-3.-logical-union-of-groups)
* [*Constants*](#id-4.-constants)
* [*Alerts*](#id-5.-alerts)
* [*Backtesting Line*](#id-6.-backtesting-line)
* [*Output data*](#id-7.-output-data)
  {% endhint %}

{% hint style="info" %}
**Association**

This module implements your ideas, displays signals on the history, and organizes algo-trading.
{% endhint %}

### General description of the indicator

**CONDITION MANAGER** is a real helper for traders who want to independently manage their trading strategies. It allows you to select the necessary data for analysis, such as stock prices, trading volumes, or indicators from other indicators. Based on these data, you can create rules (**RULE**) that will be the basis of the strategy.

Each rule can be configured using mathematical calculations, logical conditions, and special functions for data processing. This allows for precise market analysis and informed decision-making.

For more complex strategies, rules can be grouped (**GROUP**). There are four groups, each of which can contain a set of rules combined with logical "**AND**" or "**OR**" operators. Groups can also be interconnected by the same principles, creating complex combinations of conditions.

When all conditions are checked and they meet the set criteria, the indicator can send a signal to an external system. Such a signal can contain a text message, which is formed from standard TradingView variables and special variables created on values from rules and constants.

As for constants (**CONSTANT**), the indicator provides four special variables with numerical values that can be used to pass parameters into the strategy or as variables in alerts. These constants can have a constant value or a dynamic one that changes over time, making them useful for adapting the strategy to market changes, for example, when the price reaches the upper boundary of the Bollinger Bands.

As a result, this indicator allows traders to create individual trading strategies of any complexity, using a variety of data and conditions, and easily integrate them with external automated trading systems.

{% hint style="info" %}
**Hint**\
In each indicator at the top, there is a **DESCRIPTION** field where you can write any text that will help to label this indicator on the *TradingView* chart.
{% endhint %}

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

### 1. RULE

This block helps traders to choose different types of trading data, such as stock prices, sales volume, or indicators from other indicators. Based on these data, you can create special rules (**RULE**) that will manage your trading strategy.&#x20;

In each such rule, you can apply mathematical calculations, use logical conditions, and combine data using aggregator functions for more precise analysis and decision-making in trading.

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

#### Field descriptions:

<table><thead><tr><th width="70.33333333333331">N</th><th width="243" align="center">Name</th><th align="center">Action</th></tr></thead><tbody><tr><td>1</td><td align="center">Switch</td><td align="center">Turns this rule on and off.</td></tr><tr><td>2</td><td align="center">Group selection</td><td align="center">The group of rules to which this particular rule belongs.</td></tr><tr><td>3</td><td align="center">Data source 1: S1_1</td><td align="center">Where to get the data from to generate the condition.</td></tr><tr><td>4</td><td align="center">Source pointer or aggregator function</td><td align="center">Indicates which source we take to analyze without modification (S1_1 or S1_2), or which function we will perform to modify source S1_1.</td></tr><tr><td>5</td><td align="center">Manual input or parameter for a function: S1_2</td><td align="center">You can enter a value with which other sources in the rule will be compared, or set parameters for the selected function in step 4.</td></tr><tr><td>6</td><td align="center">Condition</td><td align="center">An operation to equalize two data sources.</td></tr><tr><td>7</td><td align="center">Data source 2: S2_1</td><td align="center">Where to get the data from to generate the condition.</td></tr><tr><td>8</td><td align="center">Source pointer or aggregator function</td><td align="center">Indicates which source we take to analyze without modification (S2_1 or S2_2), or which function we will perform to modify source S2_1.</td></tr><tr><td>9</td><td align="center">Manual input or parameter for a function: S2_2</td><td align="center">You can enter a value with which other sources in the rule will be compared, or set the parameters for the selected function in step 8.</td></tr></tbody></table>

#### Data sourc&#x65;**:**

This is a field for selecting the data source that will be used in the rule. It can be any price or indicator.

<figure><img src="/files/U9nfnBt1Q7rWVQuSHnJy" alt="" width="278"><figcaption></figcaption></figure>

If you turn on the switch next to the picture icon, you can draw a graph of the data source on the price chart (for example, draw the EMA line).

<figure><img src="/files/bnwe7IEzVE8IMKMC7HOt" alt="" width="244"><figcaption></figcaption></figure>

#### Source Pointer or Aggregator Function:

This field indicates which of the data fields needs to be used for the next step of the rule, or which aggregator function needs to be performed on **S1\_1** / **S2\_1** with parameters **S1\_2** / **S2\_2**.

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

<table><thead><tr><th width="213">Selection</th><th>Description</th></tr></thead><tbody><tr><td>📈</td><td>Get the value of the selected source S1_1 or S2_1 <strong>without processing</strong> (from the left field)</td></tr><tr><td>                        ✒️</td><td>Get the <strong>value entered by the use</strong>r (from the right field)</td></tr><tr><td>✒️ <strong>BAR_VALUE</strong></td><td><p>Get the <strong>previous value</strong>:</p><p>Select a source, such as S1_1 or S2_1, in the left field, and enter the number of bars back, in the right field.</p><p>If you select "close" and enter "1", you will get the closing price of one bar backwards</p></td></tr><tr><td>✒️ <strong>MAX_BARS</strong></td><td><p>To get the <strong>maximum value in the past</strong>:</p><p>Select the source, for example, S1_1 or S2_1, in the left field, and specify the number of bars back in the right field.</p><p>To find the highest price for a certain period, select the source, for example, "high", and the number of past bars, say "5". Thus, you will see the highest price for the last 5 bars (excluding the current one).</p></td></tr><tr><td>✒️ <strong>MIN_BARS</strong></td><td><p>To get the <strong>minimum value in the past</strong>:</p><p>Select the source, for example, S1_1 or S1_2, in the left field, and specify the number of bars back in the right field.</p><p>To find the lowest price for a certain period, select the source, for example, "low", and the number of past bars, say "20". Thus, you will see the lowest price for the last 20 bars (excluding the current one).</p></td></tr><tr><td>✒️ <strong>SUM_BARS</strong></td><td><p>To get the <strong>sum of values in the past</strong>:</p><p>Select the source, for example, S1_1 or S2_1, in the left field, and specify the number of bars back in the right field.</p><p>To find the total volume for a certain period, select the source, for example, "volume", and the number of past bars, say "24". Thus, you will see the total volume for the last 24 bars (excluding the current one).</p></td></tr></tbody></table>

<table data-header-hidden><thead><tr><th width="212"></th><th></th></tr></thead><tbody><tr><td>✒️ <strong>AVG_BARS</strong></td><td>Get the <strong>average value in the past</strong>: Select a source, such as S1_1 or S2_1, in the left box and enter the number of bars back in the right box. To find the average over a certain period, select a source, such as "volume", and the number of bars that have passed, say "24". This will show you the total volume for the last 24 bars (excluding the current one).</td></tr><tr><td>✒️ <strong>SMA</strong></td><td><strong>Simple Moving Average</strong> (SMA) <a href="https://www.investopedia.com/terms/s/sma.asp">https://www.investopedia.com/terms/s/sma.asp</a></td></tr><tr><td>✒️ <strong>EMA</strong></td><td><strong>Exponential Moving Average</strong> (EMA) <a href="https://www.investopedia.com/terms/e/ema.asp">https://www.investopedia.com/terms/e/ema.asp</a></td></tr><tr><td>✒️ <strong>HMA</strong></td><td><strong>Hull Moving Average</strong> (HMA) <a href="https://www.technicalindicators.net/indicators-technical-analysis/143-hma-hull-moving-average">https://www.technicalindicators.net/indicators-technical-analysis/143-hma-hull-moving-average</a></td></tr><tr><td>✒️ <strong>RMA</strong></td><td><strong>Relative Moving Average</strong> (RMA) <a href="https://www.tradingcode.net/tradingview/relative-moving-average/">https://www.tradingcode.net/tradingview/relative-moving-average/</a></td></tr><tr><td>✒️ <strong>SSMA</strong></td><td>Smoothed moving average (SSMA)<br><a href="https://devexperts.com/dxcharts/kb/docs/smoothed-simple-moving-average">https://devexperts.com/dxcharts/kb/docs/smoothed-simple-moving-average</a></td></tr><tr><td>✒️ <strong>ATR</strong></td><td><strong>Average True Range</strong> (ATR) <a href="https://www.investopedia.com/terms/a/atr.asp">https://www.investopedia.com/terms/a/atr.asp</a></td></tr><tr><td>✒️ <strong>NATR</strong></td><td><strong>Normalized Average True Range</strong> (NATR) as a percentage. This is a normalized ATR, which means that it displays the ATR as a percentage rather than an absolute price. For example, a value of 1 indicates a true range of 1% for a given period. This indicator creates a moving average of the product's volatility over the period.</td></tr><tr><td>✒️ <strong>RSI</strong></td><td><strong>Relative Strength Index</strong> (RSI) <a href="https://www.investopedia.com/terms/r/rsi.asp">https://www.investopedia.com/terms/r/rsi.asp</a></td></tr><tr><td>✒️ <strong>STOCH</strong></td><td><strong>Stochastic Oscillator</strong> (STOCH) <a href="https://www.investopedia.com/terms/s/stochasticoscillator.asp">https://www.investopedia.com/terms/s/stochasticoscillator.asp</a></td></tr><tr><td>✒️ <strong>PRICE_ANGLE</strong></td><td>Calculation of <strong>% price change for the period</strong> in bars. It is calculated as a % deviation from the Low price at the beginning of the period and the High price at the end of the period.</td></tr><tr><td>✒️ <strong>Z-SCORE</strong></td><td><strong>Z-Score</strong> shows the relative deviation of a price from its mean.</td></tr><tr><td>✒️ <strong>HURST</strong></td><td><p><strong>HURST</strong> - Simple Hurst exponent.<br></p><p>Helps to detect trend/market reversal. Values from 0.5 to 1 - the market is in trend Values from 0 to 0.5 - the market is prone to mean reversion (flat).</p></td></tr><tr><td><p>⤴️ <strong>CONSTANT_1</strong> ⤴️</p><p> ... </p><p>⤴️ <strong>CONSTANT_6</strong> ⤴️</p></td><td><strong>Special placeholder variables</strong> that carry the value that was calculated in the corresponding <a href="#id-4.-constants"><strong>CONSTANT</strong></a> block. They allow you to set conditions based on the calculated constants of the same module.</td></tr></tbody></table>

Thus, after performing these actions, we will get the initial value for checking the rule condition (**the upper value - S1 and the lower value S2**).

#### Condition:

This field sets the condition or action by which we will determine the fulfillment of the rule.

<figure><img src="/files/HPBzgxTgOdDM2ckPsoJZ" alt="" width="320"><figcaption></figcaption></figure>

<table><thead><tr><th width="197" align="center">Condition</th><th align="center">Description</th></tr></thead><tbody><tr><td align="center"><strong>LOWER</strong></td><td align="center"><strong>S1</strong> is less than <strong>S2</strong></td></tr><tr><td align="center"><strong>GREATER</strong></td><td align="center"><strong>S1</strong> is larger than <strong>S2</strong></td></tr><tr><td align="center"><strong>EQUAL</strong></td><td align="center"><strong>S1</strong> equals <strong>S2</strong></td></tr><tr><td align="center"><strong>NOT</strong> <strong>EQUAL</strong></td><td align="center"><strong>S1</strong> is not equal to <strong>S2</strong></td></tr><tr><td align="center"><strong>CROSSING</strong></td><td align="center"><strong>S1</strong> crossed <strong>S2</strong></td></tr><tr><td align="center"><strong>CROSSING</strong> <strong>OVER</strong></td><td align="center"><strong>S1</strong> crosses <strong>S2</strong> from above when its current value becomes above <strong>S2</strong> after previously being below or equal to <strong>S2</strong>.</td></tr><tr><td align="center"><strong>CROSSING UNDER</strong></td><td align="center"><strong>S1</strong> crosses <strong>S2</strong> from below when its current value becomes less than <strong>S2</strong> after previously being above or equal to <strong>S2</strong>.</td></tr></tbody></table>

### 2. GROUP

A rule group (**GROUP**) is like a list of instructions for a program, telling it what to do in certain situations. These instructions can be as simple as "buy when the price is above the previous high," or as complex with many details. The user has the option to select four such rule groups: **G1**, **G2**, **G3**, **G4**.

Imagine you're preparing a meal and you have recipes (rules) for a salad and a soup. If you use "**AND**," you need to prepare both the salad and soup for the meal to be complete. But if you use "**OR**," preparing just one of them is sufficient.

The same applies in trading: if you want the conditions to work together ("**AND**"), all of them must occur to execute the action. If you set "**OR**," then it is sufficient for at least one condition to occur for the system to act.

This gives traders the ability to create strategies with various "scenarios," experimenting with different sets of rules to see which ones work best.

The program has a special place where you can configure how the rules in the group will interact with each other:

<figure><img src="/files/6sDbeqMLHt47RO4COuAX" alt="" width="281"><figcaption></figcaption></figure>

### 3. Logical Union of GROUPS

**Rule groups** (*G1*, *G2*, *G3*, *G4*) can be combined with each other using the same logic as the rules within a group (**AND** or **OR**).

<figure><img src="/files/MA8AjKdJayWlnIoDpquL" alt="" width="416"><figcaption></figcaption></figure>

Imagine the rule groups as separate teams in a large football league. Each team has its own strategy and tactics, but when it comes to the championship, they unite using "**AND**" or "**OR**" to achieve a common goal - victory in the market.

If you use the "**AND**" operator to combine groups, it means that the conditions of all groups must be met simultaneously to activate the signal. It's as if all teams must win their matches for the trade to be executed. A high strategic game where everything must come together perfectly!

But if you combine groups through "**OR**," fulfilling the conditions of at least one group of rules is enough to activate the signal. That is, if even one team wins, you get the green light for the trade. This adds flexibility, as it allows for quicker responses to changing market conditions.

This approach allows for more flexible and adaptive strategies that can respond to various market behavior scenarios, using combinations of different rule groups. It's like having not one, but several coaches, each offering their game plan, and you choose the best option for attacking or defending your investments.

### 4. Constants

{% hint style="danger" %}
**IMPORTANT**

In the constants block, all calculations are performed sequentially, one after the other, starting from the top and moving downwards. Regardless of whether it's multiplication or division - there are no "priority" operations, everything goes in order, like in a shopping list: first, we buy bread, then milk, and only after that - chocolate.
{% endhint %}

{% hint style="info" %}
**Clarification**:

*`TakeProfit`:* \
`close + 1.5 * ATR`

you need to calculate in this way:

`ATR * 1.5 + close`

First, the multiplication is carried out and the closing price is added to the result.
{% endhint %}

{% hint style="info" %}
**Clarification**:

*`StopLoss`:*&#x20;

`low - 1.5 * ATR`

you need to calculate in this way:&#x20;

`ATR * (-1.5) + low`

First, multiplication is performed to obtain a negative value, and then the minimum price is added to the result.
{% endhint %}

A **constant** is like a calculator that allows you to combine various data, such as prices and indicator values, and perform simple mathematical operations with them, such as addition or multiplication. You can use a constant to automatically calculate important trading parameters, such as the price for taking profit (*TakeProfit*) or setting a stop loss (*StopLoss*).

The constant (***as shown below***) has 3 blocks of data sources (or user input values) that have the same logic as in the rule block (**RULE**) and can also be turned on and off (block <mark style="color:red;">**1**</mark>). Between these blocks, you can perform mathematical operations: addition (✚), subtraction (➖), modulo subtraction  (**\[**➖**]**), multiplication (✖️), and division (➗) (blocks <mark style="color:red;">**2**</mark>, <mark style="color:red;">**3**</mark>). An additional '**NONE**' mode indicates that the next data source should not be included in the calculation chain. Continuing our culinary analogy, it's like deciding not to add salt to a dish - we simply ignore this ingredient.

<figure><img src="/files/b1y9nLXqxa5JiwQxUcbh" alt="" width="114"><figcaption></figcaption></figure>

Imagine that you want to set the *TakeProfit* price based on the current closing price plus one and a half times the value of *ATR* (Average True Range). To do this, you simply need to take the last closing price (<mark style="color:blue;">**S3**</mark>), add to it the result of multiplying the *ATR* (<mark style="color:blue;">**S1**</mark>) by *1.5* (<mark style="color:blue;">**S2**</mark>), and you get your *TakeProfit* price: **close** (<mark style="color:blue;">**S3**</mark>) ✚ **ATR** (<mark style="color:blue;">**S1**</mark>) ✖️**1.5** (<mark style="color:blue;">**S2**</mark>).

<figure><img src="/files/2cX2sq85Jsn2ugAuzolC" alt=""><figcaption></figcaption></figure>

### 5. Alerts

**Alerts** are a built-in feature of *TradingView* that we enhance with additional functionality.

{% hint style="info" %}
[***TradingView alerts***](https://www.tradingview.com/support/solutions/43000520149-about-tradingview-alerts/) are instant notifications you receive when the market situation matches the conditions you have set. For example, "*Apple's stock price has risen above $150*". All users can receive pop-up notifications, sound signals, email-to-SMS, and push notifications sent to their phone. Users with *TradingView Essential, Plus, and Premium subscriptions* can also receive *Webbhook* notifications when alerts are triggered.
{% endhint %}

In the **ALERT** block, you need to set the text of the alert template to be sent and the frequency of its sending.

<figure><img src="/files/GKIsOubBxx5dDa8MENPJ" alt="" width="563"><figcaption></figcaption></figure>

<table><thead><tr><th width="242">When to send an alert</th><th align="center">Description</th></tr></thead><tbody><tr><td><strong>ALL</strong></td><td align="center">Send notifications <strong>every time they are activated</strong>, but be careful. If this happens too often, TradingView may disable your notifications.</td></tr><tr><td><strong>ONCE_PER_BAR</strong></td><td align="center">Send the notification only <strong>once for each bar</strong> when the condition is first met. If the notification has already been sent, a new one will appear only on the next bar.</td></tr><tr><td><strong>ONCE_PER_CLOSE_BAR</strong></td><td align="center">Send alerts only <strong>at the close of the bar</strong>, regardless of the number of times conditions are met during that bar.</td></tr></tbody></table>

You can supplement the standard variables for messages on *TradingView* with your own, which you create in the "Rules" (**RULE**) and "Constants" (**CONSTANT**) blocks.

<figure><img src="/files/RHOsIjY839N3efB4UiHn" alt="" width="563"><figcaption></figcaption></figure>

<table><thead><tr><th width="289" align="center">Variable</th><th align="center">Description</th></tr></thead><tbody><tr><td align="center"><strong>{{RULE_1_VALUE_SOURCE_1}}</strong><br>...<br><strong>{{RULE_8_VALUE_SOURCE_1}}</strong></td><td align="center">Value from the data source in the condition (RULE) above</td></tr><tr><td align="center"><strong>{{RULE_1_VALUE_SOURCE_2}}</strong><br>...<br><strong>{{RULE_8_VALUE_SOURCE_2}}</strong></td><td align="center">Value from the data source in the condition (RULE) below</td></tr><tr><td align="center"><strong>{{CONSTANT_1}}</strong><br>...<br><strong>{{CONSTANT_4}}</strong></td><td align="center">Constant value</td></tr></tbody></table>

<figure><img src="/files/C6hm7jcxnnsnDCeD8Nae" alt="" width="375"><figcaption></figcaption></figure>

<figure><img src="/files/gG3lEWkyA58CFTmZgoba" alt="" width="375"><figcaption></figcaption></figure>

{% hint style="warning" %}
**Setting up an alert**

*You can read about how to set up alert sending on the TradingView website:*

* <https://www.tradingview.com/support/solutions/43000595315-how-to-set-up-alerts/>
* <https://www.tradingview.com/support/solutions/43000595311-manage-alerts/>
* <https://www.tradingview.com/support/solutions/43000474415-differences-between-alert-frequencies/>
* <https://www.tradingview.com/support/solutions/43000531021-how-to-use-a-variable-value-in-alert/>
* <https://www.tradingview.com/support/solutions/43000529348-about-webhooks/>

*How to connect sending to various trading systems:*

* &#x20;3Commas: <https://3commas.io/trading-view>
* Finandy: <https://docs.finandy.com/algo-trading/signals/connection-and-configuration/indicator-strategy-connection>
* Alertatron: <https://alertatron.com/docs/getting-alerts-from-tradingview>
* Binance: <https://www.binance.com/en/support/faq/how-to-set-up-signal-trading-with-tradingview-3f57291b56474f5e900cc4b754f61ff3>
* aleeert: <https://aleeert.com/docs/>
  {% endhint %}

{% hint style="info" %}
**Hint**

Please note that alerts can also be sent from the [**CONDITION MANAGER STRATEGY**](/code-zero-visual-trading_en/cdzv-toolkit/strategies/condition-manager-strategy.md) module.
{% endhint %}

### 6. Backtesting Line

The visual back-testing system **CONDITION MANAGER** allows you to test strategies on historical data. This is an additional testing system that complements, rather than replaces, the historical data strategy back-testing system of the *TradingView* platform.

On the chart, this appears as a line of gray squares on each bar, and when your strategy indicates that a condition is met, the squares turn blue. This helps you understand when the strategy is working and to quickly make changes if needed.

These blue squares are your benchmarks on the path to a profitable strategy. They help you identify the points in time when your approach was effective and, conversely, when it's necessary to stop and rethink your tactics.

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

For convenience, this back-testing line can be displayed at the top, bottom, or turned off.

<figure><img src="/files/7sS3WxFiyc0ggypE23DE" alt="" width="335"><figcaption></figcaption></figure>

### 7. Output data

The indicator on the output has many values. The first output is information about whether the conditions are met, and the other outputs are values of constants and condition sources (the outputs are activated depending on whether the constant is enabled: **CONSTANT\_1**, **CONSTANT\_2**, **CONSTANT\_3**, **CONSTANT\_4, CONSTANT\_5, CONSTANT\_6**.

<figure><img src="/files/C4EKk8dkS5EErXsYHcNh" alt="" width="563"><figcaption></figcaption></figure>


---

# 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://docs.cdzv.com/code-zero-visual-trading_en/cdzv-toolkit/indicators/condition-manager.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.
