Which type of Alert can I produce?

Use our TradingView Json Generator

You can produce these orders to be executed in MT4 or MT5 : BUY/BUY LIMIT/SELL/SELL LIMIT/BUY STOP/SELL STOP/CLOSE

What is signal_id?

Signal_id will allow you to recognize an order in Metatrader 4/5 and DxTrade. For example if you put a BUY order with a signal_id, and then a Close alert is triggered with the same signal_id, it will close the order with this signal_id in Metatrader 4/5 or DxTrade.

Signal_id is required to send orders to DxTrade. it should be different for every order.

Send Alerts Dynamically using Pinescript

To dynamically create an alert in TradingView using Pine Script and send a message through a webhook, you will first need to determine the conditions under which your script will trigger the alert (for example, a specific price action or indicator signal). Since you didn't specify the condition, I'll give you a basic example of how to set up an alert that sends a message through a webhook when the condition is met. This example assumes you want to send an alert when a simple moving average (SMA) crosses over the price.

//@version=5

indicator("Dynamic Webhook Alert", overlay=true)

// Define your SMA length

length = input(14, title="SMA Length")

// Calculate the SMA

smaValue = ta.sma(close, length)

// Define your entry condition, for example, a crossover of the price and the SMA

entryCondition = ta.crossover(close, smaValue)

// Define your entry price as the current price

entryPrice = close

// Define your stop loss and take profit values

stopLoss = "0.5"

takeProfit1 = "1.2"

takeProfit2 = "1.5"

if (entryCondition)

// Construct the message string

      message = '{\n' +

                          '"symbol": "' + syminfo.ticker + '",\n' +

                          '"order_type": "BUY",\n' +

                          '"entry_price": "' + str.tostring(entryPrice) + '",\n' +

                          '"stop_loss" : "' + stopLoss + '",\n' +

                          '"signal_id" : "test",\n' +

                          '"take_profit" : ["' + takeProfit1 + '", "' + takeProfit2 + '"]\n' +

                          '}'

// Trigger the alert with the message

alert(message, alert.freq_once_per_bar)

plot(smaValue, color=color.blue, title="SMA")

The alert() function sends the message through the webhook URL (This url is provided by Copygram, find yours on https://app.copygram.app/connectors) that you must set up in the alert configuration on the TradingView website.

Please note:

  1. You need to configure the webhook URL in the TradingView alert box when you create an alert based on this script.
  2. The stop loss and take profit values are hardcoded in this example. You might want to calculate them dynamically based on your strategy.
  3. The entry_price is set as the current closing price when the condition is met, ensuring the message is dynamically created based on real-time data.

Was this article helpful?

How to connect TradingView alerts to a Copygram Room?