Articles on: Signals and Automation

Webhook and Trading View signals

A set of updated and comprehensive articles is now available. Start here: Webhook and Trading View SIgnals: Overview
The article below is only needed for Pine Script

Altrady's webhook signals can be used to send a signal from outside Altrady (from trading View or your own code for example) to create a new position or close an existing position using an Altrady Signal Bot.
In Trading View, an alert from an indicator or Pine Script can be used to create a webhook signal.


Trading View setup
TV Alert
Accepted values for exchange
Accepted value for symbol
Including TPs, DCAs or SL in the signal
Short or Sell Signals
Close Signal
Pine Script

In order to use the Signal Bot with custom signals, you will have to create a new Signal Bot and configure it with Webhook support.
An existing Signal bot cannot be Duplicated for your Webhook bot.

Please check the video about the Signal Bot Webhook setup (0:55 to 1:27).
The rest of the Signal Bot set up for webhooks is the same as for Signals.

For people with a developer background, you can reference the following API documentation for the Webhook.

Trading View setup

If you want to use Trading View for sending signals, you have 2 options.
You can set up an Alert or you can use a custom Pine Script to create a signal.

TV Alert

For the webhook URL, use:

And for testing the message you use:

  "test": true,
  "api_key": "YOUR_ALTRADY_API_KEY",
  "api_secret": "YOUR_ALTRADY_API_SECRET", 
  "side": "long",
  "exchange": "binance",
  "symbol": "BINA_USDT_BTC"

To make a short signal change the side line to "short" in the quotes.

Customising your code

To edit the JSON code, use a text editor, not a word processing app

With "test": true, your webhook signal in combination with your bot, should create Pending orders that you can see on the chart and in My Orders.
Once you are ready to send live signals, use:
"test": false,

Setup alert

Change the API Key and Secret to match your Altrady Signal Bot. Also make sure you set the correct exchange and symbol.

Accepted values for Exchange

Spot exchanges:
Bittrex or BTRX
Binance or BINA
Binance US or BIUS
ByBit or BYBI
Bitvavo or BVVO or CRO or GATE
Coinbase Pro or GDAX
Huobi or HUBI
Kucoin or KUCN
Kraken or KRKN
Poloniex or PLNX

Futures exchanges:
Binance Futures or BIFU
Bybit Futures or BYBIF
Kucoin Futures or KUCNF

Accepted values for Symbol

You can use the symbol format as used by the exchange API (e.g. BTCUSDT, BTC-USDT. This must be the format used by the exchange in their API calls, so if you don't know for sure, use the next option)
You can use the symbol in the format of <Exchange Code>_<QuoteCurrency>_<BaseCurrency> e.g. BINA_USDT_BTC. This will work for any exchange.
The Exchange codes are listed above.

Your payload can be checked for syntax here.

For testing your syntax using the above link, you will need to make sure "test": true or else the bot will open a position. Also, you will need to replace {{ close }} with a valid number e.g. "signal_price": 5

Optional Settings

"signal_price": "{{close}}" will use TV's close price for the candle.
If omitted from the alert, Altrady will place a Limit Buy or Sell order at the Current Price.
Note. To enter at Market, a positive Entry Price deviaiton can be used in the Signal Bot Settings, to adjust the entry price.
"signal_ID": "string"
Only include a Signal ID if you want to be able to Close the specific position using a Close webhook signal,
If used, the Signal ID must be unique for the bot, i.e. Signal IDs for the same bot cannot be reused.
One way to ensure this is to use or include the TV parameter {{ time }} in the signal ID e.g.
"signal_ID": "{{time}}"
This will insert the current timestamp measured in seconds.

Including TPs, DCAs or SL in the signal

DCAs, TP/s and SL for your signals can either be:
included in your entry signal
included your Bot Settings, or
added manually to your positions once they have opened.

If the DCAs, TPs, and SL will not vary with each signal, then it is simplest to specify them in the Signal Bot settings.
To specify different DCAs, TPs or SL depending on the signal, then the JSON code can include these.

This is the general format of the full JSON code, including DCAs, TPs and SL:
  "test": true,
  "api_key": "string",
  "api_secret": "string",
  "side": "long",
  "exchange": "string",
  "symbol": "string",
  "signal_price": 0,
  "take_profit": [
      "price_percentage": 0,
      "position_percentage": 0
  "dca_orders": [
      "price_percentage": 0,
      "quantity_percentage": 0
    "stop_percentage": 0,
    "cool_down_amount": 0,
    "cool_down_time_frame": "minute"

The cool_down_time_frame can be:

The TP, DCA and SL sections can be replaced and duplicated as needed:

"take_profit": [
      "price_percentage": 2,
      "position_percentage": 35
      "price_percentage": 4,
      "position_percentage": 65
  "dca_orders": [
      "price_percentage": 5,
      "quantity_percentage": 100
      "price_percentage": 12,
      "quantity_percentage": 200
    "stop_percentage": 25,
    "cool_down_amount": 1,
    "cool_down_time_frame": "hour"

The Signal Bot must also be configured to accept the DCAs, TPs, and/or SL from the Signal.
Turn on the relevant section, and Select the Signal option.

To use the values sent in the Signal, turn on the section in the Signal Bot and select &quot;Signal&quot;

Short or Sell Signals

Altrady's webhook can also be used to send a sell signal for coins already owned, or a to create a short (spot) position for coins already owned.
If you already have a Long position opened by a signal bot and want to close it, use the Close Signal instead, on the same bot.

To sell coins already owned:
create a new Signal Bot to receive the signal.
The signal bot uses the quote currency of the market
There are two ways to specify the entry size, and their use depends on whther the bot is for Futures or Spot:
% Total Balance% of the available balance of the quote currency to receivel% of the available balance of the base currency defined by it's value in quote currency to sell.
Fixed Amountthe amount of quote currency to receivethe amount of quote currency to receive. Specify 20 as the Fixed amount, the bot will sell ~20 USDT worth of the base currency, and receive ~ 20 USDT.

Note that, although it is possible to short on spot markets with our bots, they are primarilly designed for Long positions on Spot markets. When using a % balance for entry, the Estimated position size cannot be accurately calculated, as the bot does not know which base currency nor the balance.
For example, if you are trading ADA/USDT, the quote currency will be USDT, and the base currency is ADA.
If a percentage is specified, the bot will multiply that by the available balance at the time the signal is received.

For Spot accounts, the coins must already be owned to use a short signal to sell them. Altrady does not support margin trading yet).

You can use an Entry Price Deviation to increase the chance of the order filling quickly.
To create a short position with a Sell entry and optional DCAs, Buy TPs and SL, you can either include these in the Signal Bot or in the webhook, as for a Long/Buy position.
A single Signal Bot can be used for Long and Short positions, if you are satisifed with the entry amount and other settings being the same in both cases. Otherwise use a second Signal Bot for Short Positions.

The JSON code:
The JSON code is identical to that for a Long webhook position. However Long is the default, so either:
"side": "long",
"side": "short",
or add "side": "short", to your code
In Trading View, create your alert Sell signal using a Sell trigger.

Close Signal

Close a specific bot position, or all bot positions for a single market, using the Close action.

The Close action can only close positions created by the signal bot that opened them.

 "api_key": "YOUR_ALTRADY_API_KEY",
 "api_secret": "YOUR_ALTRADY_API_SECRET",
 "action": "close",
 "exchange": "BINA",
 "symbol": "BINA_USDT_BTC",
 "order_type": "limit",
 "signal_price": "{{close}}",
 "side": "long"

order_type is required for a Close signal. The options are:
If limit is used, then a valid signal price is also required (see the example in the above code. {{close}} is a Trading View value and will substitute the Close price for the current timeframe.

side should be the side of the original position.

Closing one specific position

"signal_id": "abc123456"
To close a specific position only, include the original signal ID for that position.
If the Signal ID is not included, all positions opened by the signal bot on the same market will be Closed.

How to use the Close Action

Choose the indicator in Trading View that you wish to use for closing your position/s.
In the same way that a TV alert is created to Open a Position, create a TV alert that will be triggered when the conditions for closing occur.
Often this will use the same indicator, but a different condition.
For example, if your position opens when RSI crosses 50 from below, you might create an alert when RSI crosses 90 (as a Take Profit) and another one if it crosses 40 (for Stop Loss).
Each of those alerts will need the JSON specified above, modified for your bot and market.
Some custom indicators include a specific Buy and Sell alert condition that can be used for opening and closing positions.

Pine Script

To simply set up the creation of an order by price crossing or by crossing a trend line as above does not require any programming skills, but if you need to connect an indicator or a strategy, you will need basic knowledge of creating a signal in Pine Script. There is a lot of information on the web about how to generate a signal in Pine.
You can also search on, and ask for advice from, the Pine Scripters Telegram User Group.
For the webhook URL you use

indicator("Altrady webhook signal")

test = input.bool(true, "Test signal")
api_key = input.string("", "Api key")
secret = input.string("", "Secret")
signal_name = input.string("", "Signal name")
side = input.string("", "Side")
exchange = input.string("", "Exchange name")
symbol = input.string("", "Symbol")
signal_price = close

alert('{"test": '+ str.tostring(test) +', "api_key": "'+api_key+'","api_secret": "'+secret+'","signal_id": "'+ signal_name + str.tostring(time)+'","side": "'+ side +'","exchange": "'+ exchange +'", "symbol": "'+ symbol +'","signal_price": "' + str.tostring(signal_price) +'"}')

With "test": true, your webhook signal in combination with your bot, should create Pending orders that you can see on the chart and in My Orders.
Once you are ready to send live signals, change the first line to:
test = input.bool(false, "Test signal")

Pine script

Please change the API Key and Secret and also make sure you set the correct exchange and symbol
Please ensure the Signal ID is unique per bot. Using the {{ time }} will ensure a unique signal ID each second

Webhook and Trading View SIgnals: Overview
Webhook: Setting up the Signal Bot
Webhook Signals: start or stop a Signal Bot
Webhook Signals: Open, Close, Increase or Reverse a Position
[[Valid values for Exchange and Symbol](/en/article/webhook-valid-values-for-exchange-and-symbol-1xrzfap/)](/en/article/valid-values-for-exchange-and-symbol-1xrzfap/)
Webhook Signals: Trading View Setup
Webhook Signal: Testing and Errors

Updated on: 24/04/2024

Was this article helpful?

Share your feedback


Thank you!