Indicator · Pine Script v4 · On the chart

Multiple Alerts

by RobACurtis· code credited to pAulseperformance

A learning example that sends alerts for three user-selected symbols from one script, avoiding a separate alert per symbol.

View on GitHub

GitHub stars1on the repository
Pine versionv4older, still runs
Lines of code140
Settings3inputs
LicenceNone statedfile: MPL-2.0
Last update2 years ago20 Jan 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

140 lines of Pine Script v4 from course_examples/alerts.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

alerts.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © pAulseperformance
// The purpose of this script is to create alerts for multiple ticker feeds. By default Tradingview makes us have to create a separate alert for each ticker/timefram. So if 
// We had a watch list of 10 different tickers we would need to create 10 different alerts.
// The aim of this script is to reduce the amount of alert creation, by creating variable alerts.


//@version=4
study("Multiple Alerts", overlay=true)
i_T1 = input('BTCUSD', type=input.symbol)
i_T2 = input('AUDUSD', type=input.symbol)
i_T3 = input('AMC', type=input.symbol)






f_strategy() =>
    smaFast = sma(close, 50)
    smaSlow = sma(close, 200)
    goLong  = crossover(smaFast, smaSlow)
    goShort = crossunder(smaFast, smaSlow)
    goLong := true
    signal = goLong ? 1 : goShort ? -1 : 0
    

f_screener(_ticker) =>
    message = ''
    
    [signal, _tickerClose, _OP, _hi] = security(_ticker, timeframe.period, [f_strategy(), close, open, high])
    
    if signal == 1 
        message := "Buy " + _ticker + "@" + tostring(_tickerClose)
    else if signal == -1
        message := "Sell " + _ticker + "@" + tostring(_tickerClose)
    
    if signal == 1 or signal == -1
        alert(message, alert.freq_once_per_bar_close)
    signal
        


t1_signal = f_screener(i_T1)
plot(t1_signal, title="T1 Signal")

t2_signal = f_screener(i_T2)
plot(t2_signal, title="T2 Signal")
t3_signal = f_screener(i_T3)
plot(t3_signal, title="T3 Signal")


plot(sma(close, 50), color=color.red)
plot(sma(close, 200), color=color.green)







// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © pAulseperformance

//@version=4
study("Alerts Study")

// 3 types of alerts.
// alertcondition()
// alert()
// strategy alerts 



// Method 1
// alertcondition()

// Syntax:
//     alertcondition(condition, title, message) → void

// args:
//    condition - Required - Type: series 
//    title     - Optional - Type: const string
//    message   - Optional - Type: const string
// 
// Remarks:
//     Take up an additional plot output.
//     Must be global.


// alertcondition(true, title="alertcondition1", message="Always True") 
// alertcondition(true, title=input("alertcondition1"), message="Always True")   // Cant do this
// alertcondition(true, title="alertcondition2", message="Always True")

















// Method 2
// alert()
// alerts() are brand new in version 4. They allow us to use series strings.
// series strings are also brand new in version 4.

// Syntax:
//     alert(message, freq) → void

// args:
//    message - Required - Type: series[string] 
//    freq    - Optional - Type: input string
condition = true

// if condition
    // alert("alert() freq_all", alert.freq_all)
    
// alert("Alert freq_once_per_bar", alert.freq_once_per_bar)
// alert("Alert freq_once_per_bar_close", alert.freq_once_per_bar_close)



// Notes:
// alert("Close: {{close}}") // This doesn't work.
alert("Close: " + tostring(close)) // Do this instead





plot(na)

Overview

Each symbol is checked with a 50 and 200 period moving average cross function through request.security, and an alert fires once per bar close with the symbol name and close price. In the code the long condition is forced true, so it always reports a buy. A second study demonstrates alert syntax.

Details

Published by

RobACurtis on GitHub

Code credit

pAulseperformance, as written in the script's header

Type

Indicator, Pine Script v4

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

pinescripttradingtradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
i_T1symbolBTCUSDi_T1
i_T2symbolAUDUSDi_T2
i_T3symbolAMCi_T3
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

This overlay indicator plots a Supertrend from an ATR length and factor, four exponential moving averages, and a selectable VWAP or TWAP taken from a chosen timeframe on the price chart. It also shows MACD and stochastic with adjustable lengths, smoothing, ver

Indicator v5 Oscillators & momentumMoving averages
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup: Vijay Thakare Option Buying Scalping Setup
257 stars

This indicator plots a 200-period weighted moving average (WMA) on the main chart and monitors price deviations across multiple timeframes. It retrieves daily, 15-minute, 5-minute, and 2-minute price data to track distance from the 200 WMA relative to key sess

Indicator v5 Moving averagesSessions & time Repaints
Updated 7 weeks ago · None stated GitHub repository of Donald SPX - Options Trading
228 stars

TradersPost Trading Checklist is an overlay indicator that evaluates a suite of popular technical conditions for long and short trade setups. It checks session-anchored VWAP, fast and slow EMA alignments and crosses, 200 SMA, RSI overbought or oversold conditi

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of TradersPost Trading Checklist

8zz反指標v2

by hansai-art
121 stars

The 8zz Contrarian Indicator plots reverse sentiment trading signals directly on the price chart based on tracked retail post activity. It generates bullish signals during retail panic and bearish signals during market euphoria. The indicator features adjustab

Indicator v6 Moving averagesOscillators & momentum
Updated 3 months ago · None stated GitHub repository of 8zz反指標v2
92 stars

This indicator plots five moving averages of a chosen source on the price chart, defaulting to EMA lengths 10, 20, 30, 40 and 50. The user can switch the average type to SMA, WMA or HMA and recolor each line. Wide translucent glows sit under the lines, and sof

Indicator v5 TrendMoving averages
Updated 2 months ago · Custom licence GitHub repository of Moon Dev Rainbow MA Ribbon 10-50

Price vs MA

by be-thomas
65 stars

This indicator builds a table of simple moving averages and places it on the price chart. It calculates a user-chosen number of SMAs whose periods start at a base length and increase by a fixed step. On the last bar it lists each period and its SMA value, colo

Indicator v4 Moving averagesScreeners & dashboards
Updated 6 days ago · GPL-3.0 GitHub repository of Price vs MA

More Moving averages scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers