Skip to content

automated trading

Pine Script alert() Function: Automate Strategy Signals

If a Pine Script produces signals but no MetaTrader order follows, check the complete alert path. An alert() call is one way to produce an event; order-fill alerts and named conditions can be alternatives. This guide illustrates the editable-script path, with demo verification required before relying on it.


What the alert() Function Actually Does

An alert() call can generate a realtime alert event when the script executes that call under its frequency setting. You must also create the TradingView alert. With a configured webhook, TradingView sends its message to the specified receiver; PineConnector processes the instruction and the EA requests the broker action. A triggered alert is not proof of a fill.

The basic syntax is:

alert('LicenseID,buy,EURUSD,vol_lots=0.01', alert.freq_once_per_bar_close)

Two arguments matter here. The first is the message string, which PineConnector reads to know what trade to place. The second is the frequency setting. Using alert.freq_once_per_bar_close is important because it fires only after the candle closes, which reduces the risk of acting on signals that repaint during the live bar.

vol_lots=0.01 sends a fixed position size, 0.01 lots here, regardless of your account balance or any stop distance. PineConnector's syntax documentation also supports sizing by a cash amount you're willing to lose (vol_dollar=) or a percentage of balance or equity (vol_pct_bal_loss=, vol_pct_eq_loss=); those methods require a stop loss in the same message so PineConnector can size the trade from it. This guide uses vol_lots= throughout to keep the walkthrough focused on wiring up the alert, not choosing a sizing method; for that choice, and for matching a stop or target to how your script actually stores it, see Choosing Position Size, Stop Loss and Take Profit. Some of PineConnector's own reference material elsewhere still shows an older risk= parameter for opening a position; its meaning depends on your EA's Volume Type setting (Lots by default) rather than always meaning a fixed lot size. For existing risk= messages, verify the receiving EA’s Volume Type and parameter source before changing the syntax. This is only about which parameter new examples should use.


Do You Have Code Access? Start Here

The approach you take depends on whether you can open the script in Pine Editor.

If you can open and edit the script, follow PineConnector's Add alerts to your script guide, which this post is based on. It covers both strategy and indicator scripts with step-by-step code examples.

If the script belongs to someone else and the code is locked, check PineConnector's Connect your strategy guide first. That guide walks through three feasibility tests: checking whether the script uses strategy(), whether it exposes alert() via a License ID input, and whether it surfaces alertcondition() options in the alert dialog.


Step 1: Confirm Your Script Version

Before writing any code, open Pine Editor and check the first line. It should read:

//@version=5

PineConnector's low-code documentation is written for Pine Script v5. If your script is on v4 or lower, use TradingView's own v4-to-v5 migration guide to convert it before proceeding. The syntax differences are significant enough that mixing versions will break your alerts.


Step 2: Identify Your Script Type

Your script will start with either strategy(...) or indicator(...). The implementation steps differ between the two.

For strategy scripts, your entry conditions are tied to strategy.entry() calls. Search for those lines using CTRL+F (Windows) or CMD+F (Mac). The condition sitting after the if on each row is what you need. For example:

if ta.change(direction) < 0
    strategy.entry('My Long Entry Id', strategy.long)

Here, ta.change(direction) < 0 is your long entry condition.

For indicator scripts, entry conditions are typically declared as boolean variables near the bottom of the script. A standard EMA crossover example looks like this:

long = ta.crossover(ema20, ema50) and close > ema20
short = ta.crossunder(ema20, ema50) and close < ema20

Step 3: Add Visual Confirmation with plotshape

Before writing any alert code, add plotshape() calls so you can visually verify that your entry conditions are correct on the chart. This prevents you from wiring up alerts to the wrong logic.

Place these lines at the bottom of your script:

plotshape(LongEntryCondition, style=shape.arrowup, location=location.belowbar, color=color.blue)
plotshape(ShortEntryCondition, style=shape.arrowdown, location=location.abovebar, color=color.blue)

Replace LongEntryCondition and ShortEntryCondition with your actual conditions. Save the script and click "Add to chart". Blue arrows should appear at your expected entry points. If they do not, your condition variables need adjusting before you move forward.

Under the strategy’s default calculation and broker-emulator settings, a market order generated at a bar close is generally eligible to fill on the next available tick, often the next bar’s open. Different strategy settings and order types can change that timing. A plotted condition, an alert event and a simulated fill are separate events.

On a liquid symbol with no gap between candles, that next-bar-open price is often close to the prior bar’s close. But the two are not always equal, and neither one is what your live alert produces. alert() does not place an order in TradingView’s simulator at all. It fires a webhook to PineConnector, which sends the instruction to your broker. The price you are filled at is whatever your broker quotes at that moment, subject to its own spread and slippage and to how long the alert took to arrive. Treat the backtest’s fill assumption and your live broker’s fill as two separate facts, and confirm the second one with a demo trade rather than reading it off the chart.


Step 4: Add the alert() Function

This is where your signals get converted into trade instructions.

For strategy scripts, place the alert call directly after each strategy.entry() line:

if ta.change(direction) < 0
    strategy.entry('My Long Entry Id', strategy.long)
    alert('LicenseID,buy,EURUSD,vol_lots=0.01', alert.freq_once_per_bar_close)

if ta.change(direction) > 0
    strategy.entry('My Short Entry Id', strategy.short)
    alert('LicenseID,sell,EURUSD,vol_lots=0.01', alert.freq_once_per_bar_close)

For indicator scripts, wrap the alert call in an if block using your entry condition:

if LongEntryCondition
    alert('LicenseID,buy,EURUSD,vol_lots=0.01', alert.freq_once_per_bar_close)

if ShortEntryCondition
    alert('LicenseID,sell,EURUSD,vol_lots=0.01', alert.freq_once_per_bar_close)

Replace LicenseID with the complete value copied from Portal → Connections. Current IDs are normally 13–14 digits, with legacy exceptions. Do not add a prefix, shorten the value or guess its first digits. Verify every account attached to that ID before sending a demo message. License ID reference.

The examples request opposing entries; those calls alone do not establish an always-in-market strategy or a completed reversal. The self-hosted EA’s Close on Reverse and Pyramiding settings affect processing. On Edge, the same settings are in Portal → Edge → EA Settings; applying a change restarts the terminal for about a minute, so confirm the tab says your saved settings are running before you test. Verify any close and replacement entry separately on demo. EA settings reference.


Making Your Alerts Dynamic

A static message states one intended symbol and size. Whether the broker accepts it depends on the receiving setup and symbol rules. If values change with the strategy, define their units and verify each substitution.

Dynamic Symbol

Instead of hardcoding the ticker, pull it from the chart:

alert('LicenseID,buy,' +syminfo.ticker+ ',vol_lots=0.01', alert.freq_once_per_bar_close)

syminfo.ticker uses the TradingView symbol, not the broker’s exact symbol. A chart change does not prove the receiving broker accepts that name. Supply or map the exact receiving symbol and verify it on demo; the following is an illustrative one-symbol mapping only.

symbol = syminfo.ticker

if syminfo.ticker == "US100"
    symbol := "NAS100"

if LongEntryCondition
    alert('LicenseID,buy,' +symbol+ ',vol_lots=0.01', alert.freq_once_per_bar_close)

That is a script-side remap for one symbol. PineConnector also documents Symbol Mapping for Plus and Pro. A mapped name does not bypass the broker’s volume, price or stop constraints.

Dynamic Stop Loss and Take Profit

To use chart-based stop loss and take profit values, store them as variables and convert to strings inside the alert:

LongSL = low[1]
LongTP = ta.ema(close, 50)
validLongLevels = LongSL < close and LongTP > close

if LongEntryCondition and validLongLevels
    alert('LicenseID,buy,' +syminfo.ticker+ ',sl_price=' +str.tostring(LongSL, format.mintick)+ ',tp_price=' +str.tostring(LongTP, format.mintick)+ ',vol_lots=0.01', alert.freq_once_per_bar_close)

The chart-derived values are prices, so they belong in sl_price= and tp_price=. The preliminary chart check does not validate the broker’s current entry reference, tick size or minimum stop distance. The current Syntax reference requires those checks. Inspect Portal → Bridge / Signals log, the EA request and the broker result; a valid chart-side comparison does not prove acceptance.

Legacy bare sl=/tp= still work; their meaning follows your EA's Target Type setting (Pips by default) rather than the message itself, which is why this guide uses the explicit _pips/_price/_pct suffixes instead, not because the bare form has stopped being supported. sl=0 is a separate, still-current special case that specifically requests moving the stop to breakeven.

The str.tostring() wrapper is necessary because alert() only accepts strings, not float values. Its second argument, format.mintick, rounds the price to TradingView's own understanding of the symbol's minimum tick, which avoids sending floating-point noise like 1.0976000000000001. It does not confirm your broker will accept that exact price: TradingView's tick size for a symbol comes from its own data feed and may not match your broker's price precision for the same symbol. Check Portal → Bridge / Signals log and the broker records for the price actually used.

Adding a Comment for Trade Identification

To label trades in your broker terminal:

alert('LicenseID,buy,' +syminfo.ticker+ ',sl_price=' +str.tostring(LongSL, format.mintick)+ ',tp_price=' +str.tostring(LongTP, format.mintick)+ ',vol_lots=0.01,comment=Strategy 1', alert.freq_once_per_bar_close)

Note the quoting: the single quotes above are Pine Script's own string delimiter for the whole message and are not sent to PineConnector. comment= itself takes plain text up to the next comma, up to 20 characters. Don't wrap the label in quote marks of any kind, or those quote characters become part of the comment PineConnector receives.

Multiple License IDs

If accounts need different instructions, use the intended License IDs and verify their complete recipient lists. Use separate configured alerts when distinct destinations must each produce an event; do not assume several alert() calls under one frequency setting will all fire.

Illustrative specification: record each destination License ID, its attached accounts and the independent alert event intended for that destination. Verify each receiving demo account.

Verify each alert’s event record and each receiving account. TradingView’s trigger limits still apply; an intended message in source code is not evidence that the alert fired.


Step 5: Create the Alert in TradingView

Adding alert() to your code does not activate anything on its own. You must create an alert for each symbol and timeframe you want to trade.

Press Alt+A (Windows) or Option+A (Mac) to open the alert dialog. Configure it as follows:

Setting Value
Condition Your script name, then "alert() function calls only"
Webhook URL https://webhook.pineconnector.com

After creating the alert, inspect the TradingView alert log for an event, PineConnector for receipt/processing, and the broker account for the actual result. A blue chart marker alone does not confirm any later stage.

One important note: if you update your script code after creating alerts, the existing alerts will not pick up the changes. They were saved against the original version of the code. Delete the old alerts and create new ones every time you modify your script. For the full mechanism behind this and a five-step procedure for switching over without doubling up your orders, see I Changed My Pine Script, but the Alert Still Uses the Old Settings.


Automating Strategies without Code Access

If the script you want to automate is published by someone else and you cannot edit it, you have three options before giving up.

First, check the strategy’s alert menu for “Order fills only”. Its presence establishes an event source, not that every fill should become a new entry. The illustrative message below is applicable only after verifying the meaning of each event and the exact broker symbol; the next paragraph states the limits.

LicenseID,{{strategy.order.action}},{{ticker}},vol_lots=0.01

Give this a fixed size such as vol_lots=0.01, not {{strategy.order.contracts}}. That placeholder is the quantity from TradingView's own simulated order, which the script's author may have set in shares, contracts, or a percentage of equity; it is not automatically a MetaTrader lot size, a cash amount, or a risk percentage, and PineConnector's own no-code documentation warns against treating it as one. This only applies when every fill from the script is meant as a fresh buy or sell entry; a strategy whose sell fill actually closes a long rather than opening a short would send the wrong instruction if you treat it as a new entry, so check the strategy's own logic (or ask its author) before relying on this option.

The second option is a script with PineConnector-ready inputs. A License ID field alone does not establish its alert messages or exit meanings. Review its instructions, set the intended values, create the appropriate webhook alert and verify the actual message and demo outcome.

The third option is checking for alertcondition(). Create an alert, select the script under Condition, and look for options like "Going Long" or "Going Short" above the Crossing field. If those exist, select the appropriate direction, write your PineConnector message in the alert body, and set the webhook URL. Use "Once Per Bar Close" as the trigger option to minimize repainting.

If none of the documented alert options is exposed, the guide does not establish a no-code route for that script. Alert support or an editable implementation may be needed; a chart arrow alone cannot supply an alert event.


What Repainting Means for Your Alerts

Repainting is worth understanding before you go live. It refers to the difference in how a script behaves during a live bar versus how it looks on historical bars after the bar has closed.

Waiting for a bar close can avoid some changes within the open bar. It does not remove higher-timeframe repainting, future-data leakage, historical relocation of signals or dataset changes. Inspect the script’s data timing and test the rule; an alert-frequency choice alone cannot validate it.


A Full Worked Example: The SuperTrend Strategy

PineConnector’s SuperTrend walkthrough is a learning example. Review its version, message units, symbol handling and execution settings; it is not evidence that an unchanged copy will work on your account. The inherited excerpt below was not compiled or tested in this review.

The SuperTrend script demonstrates exactly how alert() and plotshape() sit alongside strategy.entry() in practice:

if ta.change(direction) < 0
    strategy.entry('Long', strategy.long)
    alert(str.tostring(LicenseID)+',buy,' + syminfo.ticker + ',risk=' + str.tostring(riskvalue), alert.freq_once_per_bar_close)

if ta.change(direction) > 0
    strategy.entry('Short', strategy.short)
    alert(str.tostring(LicenseID)+',sell,' + syminfo.ticker + ',risk=' + str.tostring(riskvalue), alert.freq_once_per_bar_close)

Notice that syminfo.ticker makes the symbol dynamic and str.tostring(riskvalue) pulls from a user-adjustable input rather than a hardcoded number. This is the pattern to follow for any strategy you build from scratch. The guide's own code still sends risk=, so its meaning follows your EA's Volume Type setting rather than a fixed lot size; swap in vol_lots= (or vol_dollar=/vol_pct_bal_loss= with a stop loss) for the explicit behavior used elsewhere in this guide, and remember this is a reversal-style script, so check the Close on Reverse setting described above before trading it live.

Use the separate connection and demo-order checks in Test your setup. A check on a convenient timeframe does not validate the strategy’s intended timeframe. Retain evidence for the actual alert configuration and broker outcome.


Start Automating Your Strategy

Once the alert is configured, the execution path is ready to test, not proven live. Follow Test your setup for the separate messaging check and demo order. Then reconcile the actual request and broker outcome before relying on the strategy.

Reviewed 18 September 2026. Every parameter name and code example above was checked against PineConnector's syntax documentation, its low-code, no-code, EA-settings and SuperTrend-strategy guides, and against TradingView's own Pine Script documentation on repainting and strategy order execution. Before trading on any of it, paste each example into your own Pine Editor to confirm it compiles on your script, and confirm the resulting order on a demo account.


Try Core for 7 days for $7 at PineConnector, with hosted MT5 through Edge included, and connect your first strategy today. After the trial, Core is $59/month unless you cancel.

Corrections reviewed 23 September 2026 against the cited primary documentation accessed on that date; Edge EA Settings updated 6 October 2026. No trading account was tested and no Pine Script or MQL5 code was compiled for this update.

Sources

  1. PineConnector – Frequently Asked Questions, accessed 23 September 2026.
  2. PineConnector – PineConnector Syntax, accessed 23 September 2026.
  3. PineConnector – EA settings reference, accessed 23 September 2026.
  4. PineConnector – Connect your MT5 account, accessed 23 September 2026.
  5. PineConnector – Connect your strategy, accessed 23 September 2026.
  6. PineConnector – Add alerts to your script, accessed 23 September 2026.
  7. PineConnector – Symbol Mapping, accessed 23 September 2026.
  8. PineConnector – Test your setup, accessed 23 September 2026.
  9. TradingView – Pine Script Strategies, accessed 23 September 2026.

PineConnector executes the instructions you send it. It does not select trades, manage money, or hold funds. Trading carries risk, and past performance of any strategy does not indicate future results.


Leave a comment

Back To PiCo Blog

Ready when your strategy is

You bring the strategy.We bring the infrastructure.

Connect TradingView to MetaTrader, choose where MT5 runs and put the full PineConnector workflow through its paces from your first month.

Strategy and trading decisions remain yours. The MT5 environment can be ours.

PineConnector Edge

Run the full PineConnector workflow.

$59/mo at launch

Core plan · 1 connection · 1 hosted MT5 environment

Try Core for $7

7 days of Core for $7, then $59/month at the launch price unless you cancel.