OPEN-SOURCE SCRIPT

Ensemble Alerts

█ OVERVIEW


This indicator creates highly customizable alert conditions and messages by combining several technical conditions into groups, which users can specify directly from the "Settings/Inputs" tab. It offers a flexible framework for building and testing complex alert conditions without requiring code modifications for each adjustment.



█ CONCEPTS


Ensemble analysis

Ensemble analysis is a form of data analysis that combines several "weaker" models to produce a potentially more robust model. In a trading context, one of the most prevalent forms of ensemble analysis is the aggregation (grouping) of several indicators to derive market insights and reinforce trading decisions. With this analysis, traders typically inspect multiple indicators, signaling trade actions when specific conditions or groups of conditions align.


Simplifying ensemble creation

Combining indicators into one or more ensembles can be challenging, especially for users without programming knowledge. It usually involves writing custom scripts to aggregate the indicators and trigger trading alerts based on the confluence of specific conditions. Making such scripts customizable via inputs poses an additional challenge, as it often involves complicated input menus and conditional logic.

This indicator addresses these challenges by providing a simple, flexible input menu where users can easily define alert criteria by listing groups of conditions from various technical indicators in simple text boxes. With this script, you can create complex alert conditions intuitively from the "Settings/Inputs" tab without ever writing or modifying a single line of code. This framework makes advanced alert setups more accessible to non-coders. Additionally, it can help Pine programmers save time and effort when testing various condition combinations.



█ FEATURES


Configurable alert direction

The "Direction" dropdown at the top of the "Settings/Inputs" tab specifies the allowed direction for the alert conditions. There are four possible options:

 • Up only: The indicator only evaluates upward conditions.
 • Down only: The indicator only evaluates downward conditions.
 • Up and down (default): The indicator evaluates upward and downward conditions, creating alert triggers for both.
 • Alternating: The indicator prevents alert triggers for consecutive conditions in the same direction. An upward condition must be the first occurrence after a downward condition to trigger an alert, and vice versa for downward conditions.


Flexible condition groups

This script features six text inputs where users can define distinct condition groups (ensembles) for their alerts. An alert trigger occurs if all the conditions in at least one group occur.

Each input accepts a comma-separated list of numbers with optional spaces (e.g., "1, 4, 8"). Each listed number, from 1 to 35, corresponds to a specific individual condition. Below are the conditions that the numbers represent:

 1 — RSI above/below threshold
 2 — RSI below/above threshold
 3 — Stoch above/below threshold
 4 — Stoch below/above threshold
 5 — Stoch K over/under D
 6 — Stoch K under/over D
 7 — AO above/below threshold
 8 — AO below/above threshold
 9 — AO rising/falling
 10 — AO falling/rising
 11 — Supertrend up/down
 12 — Supertrend down/up
 13 — Close above/below MA
 14 — Close below/above MA
 15 — Close above/below open
 16 — Close below/above open
 17 — Close increase/decrease
 18 — Close decrease/increase
 19 — Close near Donchian top/bottom (Close > (Mid + HH) / 2)
 20 — Close near Donchian bottom/top (Close < (Mid + LL) / 2)
 21 — New Donchian high/low
 22 — New Donchian low/high
 23 — Rising volume
 24 — Falling volume
 25 — Volume above average (Volume > SMA(Volume, 20))
 26 — Volume below average (Volume < SMA(Volume, 20))
 27 — High body to range ratio (Abs(Close - Open) / (High - Low) > 0.5)
 28 — Low body to range ratio (Abs(Close - Open) / (High - Low) < 0.5)
 29 — High relative volatility (ATR(7) > ATR(40))
 30 — Low relative volatility (ATR(7) < ATR(40))
 31 — External condition 1
 32 — External condition 2
 33 — External condition 3
 34 — External condition 4
 35 — External condition 5

These constituent conditions fall into three distinct categories:

 • Directional pairs: The numbers 1-22 correspond to pairs of opposing upward and downward conditions. For example, if one of the inputs includes "1" in the comma-separated list, that group uses the "RSI above/below threshold" condition pair. In this case, the RSI must be above a high threshold for the group to trigger an upward alert, and the RSI must be below a defined low threshold to trigger a downward alert.

 • Non-directional filters: The numbers 23-30 correspond to conditions that do not represent directional information. These conditions act as filters for both upward and downward alerts. Traders often use non-directional conditions to refine trending or mean reversion signals. For instance, if one of the input lists includes "30", that group uses the "Low relative volatility" condition. The group can trigger an upward or downward alert only if the 7-period Average True Range (ATR) is below the 40-period ATR.

 • External conditions: The numbers 31-35 correspond to external conditions based on the plots from other indicators on the chart. To set these conditions, use the source inputs in the "External conditions" section near the bottom of the "Settings/Inputs" tab. The external value can represent an upward, downward, or non-directional condition based on the following logic:
 ▫ Any value above 0 represents an upward condition.
 ▫ Any value below 0 represents a downward condition.
 ▫ If the checkbox next to the source input is selected, the condition becomes non-directional. Any group that uses the condition can trigger upward or downward alerts only if the source value is not 0.

To learn more about using plotted values from other indicators, see this article in our Help Center and the Source input section of our Pine Script™ User Manual.


Group markers

Each comma-separated list represents a distinct group, where all the listed conditions must occur to trigger an alert. This script assigns preset markers (names) to each condition group to make the active ensembles easily identifiable in the generated alert messages and labels. The markers assigned to each group use the format "M<x>", where "M" is short for "Marker" and "x" is the group number. The titles of the inputs at the top of the "Settings/Inputs" tab show these markers for convenience.

For upward conditions, the labels and alert messages show group markers with upward triangles (e.g., "M1▲"). For downward conditions, they show markers with downward triangles (e.g., "M1▼").

NOTE: By default, this script populates the "M1" field with a pre-configured list for a mean reversion group ("2,18,24,28"). The other fields are empty. If any "M*" input does not contain a value, the indicator ignores it in the alert calculations.


Custom alert messages

By default, the indicator's alert message text contains the activated markers and their direction as a comma-separated list. Users can override this message for upward or downward alerts with the two text fields at the bottom of the "Settings/Inputs" tab. When the fields are not empty, the alerts use that text instead of the default marker list.

NOTE: This script generates alert triggers, not the alerts themselves. To set up an alert based on this script's conditions, open the "Create Alert" dialog box, then select the "Ensemble Alerts" and "Any alert() function call" options in the "Condition" tabs. See the Alerts FAQ in our Pine Script™ User Manual for more information.


Condition visualization

This script offers organized visualizations of its conditions, allowing users to inspect the behaviors of each condition alongside the specified groups. The key visual features include:

1) Conditional plots
 • The indicator plots the history of each individual condition, excluding the external conditions, as circles at different levels. Opposite conditions appear at positive and negative levels with the same absolute value. The plots for each condition show values only on the bars where they occur.
 • Each condition's plot is color-coded based on its type. Aqua and orange plots represent opposing directional conditions, and purple plots represent non-directional conditions. The titles of the plots also contain the condition numbers to which they apply.
 • The plots in the separate pane can be turned on or off with the "Show plots in pane" checkbox near the top of the "Settings/Inputs" tab. This input only toggles the color-coded circles, which reduces the graphical load. If you deactivate these visuals, you can still inspect each condition from the script's status line and the Data Window.
 • As a bonus, the indicator includes "Up alert" and "Down alert" plots in the Data Window, representing the combined upward and downward ensemble alert conditions. These plots are also usable in additional indicator-on-indicator calculations.

2) Dynamic labels
 • The indicator draws a label on the main chart pane displaying the activated group markers (e.g., "M1▲") each time an alert condition occurs.
 • The labels for upward alerts appear below chart bars. The labels for downward alerts appear above the bars.

 NOTE: This indicator can display up to 500 labels because that is the maximum allowed for a single Pine script.

3) Background highlighting
 • The indicator can highlight the main chart's background on bars where upward or downward condition groups activate. Use the "Highlight background" inputs in the "Settings/Inputs" tab to enable these highlights and customize their colors.
 • Unlike the dynamic labels, these background highlights are available for all chart bars, irrespective of the number of condition occurrences.



█ NOTES

• This script uses Pine Script™ v6, the latest version of TradingView's programming language. See the Release notes and Migration guide to learn what's new in v6 and how to convert your scripts to this version.
• This script imports our new Alerts library, which features functions that provide high-level simplicity for working with complex compound conditions and alerts. We used the library's `compoundAlertMessage()` function in this indicator. It evaluates items from "bool" arrays in groups specified by an array of strings containing comma-separated index lists, returning a tuple of "string" values containing the marker of each activated group.
• The script imports the latest version of the ta library to calculate several technical indicators not included in the built-in `ta.*` namespace, including Double Exponential Moving Average (DEMA), Triple Exponential Moving Average (TEMA), Fractal Adaptive Moving Average (FRAMA), Tilson T3, Awesome Oscillator (AO), Full Stochastic (%K and %D), SuperTrend, and Donchian Channels.
• The script uses the `force_overlay` parameter in the label.new() and bgcolor() calls to display the drawings and background colors in the main chart pane.
• The plots and hlines use the available `display.*` constants to determine whether the visuals appear in the separate pane.



Look first. Then leap.


alertsignalsBands and ChannelsBESTcombinationconditionsMoving AveragesOscillatorsstrategydevelopmentstrategytestingtesting

Script open-source

In pieno spirito TradingView, l'autore di questo script lo ha pubblicato open-source, in modo che i trader possano comprenderlo e verificarlo. Un saluto all'autore! È possibile utilizzarlo gratuitamente, ma il riutilizzo di questo codice in una pubblicazione è regolato dal nostro Regolamento. Per aggiungerlo al grafico, mettilo tra i preferiti.

Vuoi usare questo script sui tuoi grafici?


Tools and ideas for all Pine coders: pinecoders.com
Our Pine FAQ & Code: pinecoders.com/faq_and_code/
Pine news broadcasts: t.me/PineCodersSquawkBox or twitter.com/PineCoders
Anche su:

Declinazione di responsabilità