admin

Guideline to setup Incoming Webhook Signal with TradingView

How it work


We are excited to announce the release of our latest feature - Webhook signal trading!

_meta_


Now, you can trigger your ALGOGENE strategies based on TradingView alerts! This means a new world of possibilities such as:

  • various indicators in TradingView can now be used to automate your trading without coding
  • you can create multiple signals on TradingView and execute on a single broker account that is connected on ALGOGENE
  • a single alert from TradingView can be executed to multiple broker accounts connected on ALGOGENE
  • distribute your real-time signals to ALGOGENE marketplace to showcase your trading performance and attract investment

collaborate

This article goes through the steps to apply ALGOGENE webhook on your TradingView account. The overall workflow is summarized in this diagram.


workflow

What is Webhook?

A Webhook lets you send a POST request to a specific URL when an alert is triggered. This feature can be enabled when creating or editing an alert on TradingView (or other third party platform). Add the URL given by ALGOGENE, it allows you to link TradingView signals to any brokers/exchanges supported by ALGOGENE such as Interactive Brokers, Binance, etc. TradingView will send a request as soon as an alert is triggered, with the request body containing the alert message. If the alert is activated, TradingView will send the request to ALGOGENE which will then automatically create a trade on your connected broker accounts.


How to Use Webhook Signal Trading?

Using Webhook Signal Trading is as simple as 3 steps:

  1. Run a strategy on TradingView (or other third party platform)
  2. Create a webhook on ALGOGENE
  3. Activate the webhook on TradingView to start receiving signals

Prerequisite

Please take note of the following before starting Webhook signal trading with TradingView (or other third party platforms)

  • The webhooks feature may not be available for free users. For TradingView, you need to subscribe for Pro/Pro+/Premium plan to enable webhooks.
  • Keep your webhook URL confidential and avoid sharing it with others to prevent receiving fake incoming signals and unauthorized orders
  • All third party (eg. TradingView) alerts are sent based on your own settings, and you should be responsible to test it completely before using it in a real account
  • There may be risks of signal loss or delay, as the triggering of signals relies on a third-party platform.

How to create Webhook on ALGOGENE?

  • Login ALGOGENE Portal, go to [Settings]
  • manual

  • Go to [Live Demo] or [Real Trade] depending on whether you want to connect the signal to a paper or real trading account
  • Mouse hover to your subaccount, then click "Webhook Setup"
  • subaccount

  • Click to "Set" webhook key
  • For better account security, you can also white-list the IP that our system will accept the signal messages sent from
  • setup key

  • Copy this webhook key

How to activate Webhook on TradingView?

  • Login TradingView, then go to "Chart" (https://www.tradingview.com/chart/)
  • Create your strategy on TradingView. Here we use "MA Cross" as an example.
    • Click "Indicators"
    • Search and add "MA Cross" strategy
    alert

  • Click "Alert"
  • alert

  • Go to [Settings], paste the following in message
  • alert

    1
    2
    3
    4
    5
    6
    7
    {
        "instrument": "{{ticker}}",
        "price": "{{close}}",
        "ordertype": "LMT",
        "buysell": "{{strategy.order.action}}",
        "volume": "{{strategy.order.contracts}}"
    }
    

  • Go to [Notifications], enable webhook URL and input

  • https://algogene.com/rest/v1/webhook/USER_ID/WEBHOOK_KEY/trade

    alert

  • Click "Create"

Reference: https://www.tradingview.com/support/solutions/43000529348-about-webhooks/


Message Specification

Here is all available attributes that can be included in TradingView message.


Attribute Description Optional Example
instrument the trading instrument. Make sure the instument name aligns with ALGOGENE's symbols https://algogene.com/community/post/48 No BTCUSD
buysell
  • the buy/sell direction
  • 'BUY' for buy direction, 'SELL' for sell direction
No BUY
volume the order quantity, unit in number of shares No 100
ordertype
  • the order type
  • 'MKT' for market order, 'LMT' for limit order, 'STOP' for stop order
No LMT
price
  • Only required when ordertype = 'LMT' or 'STOP'
  • refer to limit price for limit order, stop price for stop order
Yes 15000
timeinforce For limit/stop order, specify the maximum number of seconds to wait before auto-cancelling the order if not filled Yes 86400
takeProfitLevel the take profit level after the order has been opened Yes 20000
stopLossLevel the stop loss level after the order has been opened Yes 10000
holdtime the holding time (in seconds) if the order has been opened Yes 86400
openclose 'open' to open a new order, 'close' to close an outstanding order. If not speciified, assume to be 'open' Yes open
orderRef your reference message attached to this order. for openclose='close', it will close all outstanding trades with this reference Yes test


Demo Video



This new feature unlocks a world of opportunities. Start automating your trading journey with Webhook Signal today!


 
Henry Tsai
Can I connect TradingView with my MT5?
 
admin
Original Posted by - b'Henry Tsai': Can I connect TradingView with my MT5?
Currently it supports receiving signals from TradingView, then execute on MT5. 
 
小霸王
Hi, how to implement a round order strategy? 
eg. open a long position, then close it later

from your example, what to add the open/close condition in tradingview?

{
    "instrument": "{{ticker}}",
    "price": "{{close}}",
    "ordertype": "LMT",
    "buysell": "{{strategy.order.action}}",
    "volume": "{{strategy.order.contracts}}"
}
 
admin
Original Posted by - b'\xe5\xb0\x8f\xe9\x9c\xb8\xe7\x8e\x8b': Hi, how to implement a round order strategy? 
eg. open a long position, then close it later

from your example, what to add the open/close condition in tradingview?

{
    "instrument": "{{ticker}}",
    "price": "{{close}}",
    "ordertype": "LMT",
    "buysell": "{{strategy.order.action}}",
    "volume": "{{strategy.order.contracts}}"
}

According to TradingView (https://www.tradingview.com/support/solutions/43000481368-strategy-alerts/), strategy alert currently doesn't provide information about open/close and transaction number. As a workaround, you can put those information in pine script's comment.

For example, we have 2 strategies in TradingView using '123' and '124' to distinguish them. For entry order, we put 'open' in the comment; while putting 'close' for exit order.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
// pine script

if entryCondition1
    strategy.entry("buy", strategy.long, qty=10, comment="open 123")

if entryCondition2
    strategy.entry("sell", strategy.short, qty=20, comment="open 124")

if exitCondition1
    strategy.exit("sell", strategy.short, qty=10, comment="close 123")

if exitCondition2
    strategy.exit("buy", strategy.long, qty=10, comment="close 124")


Then copy this to TradingView's alert setting.

1
2
3
4
5
6
7
8
{
    "instrument": "{{ticker}}",
    "price": "{{close}}",
    "ordertype": "LMT",
    "buysell": "{{strategy.order.action}}",
    "volume": "{{strategy.order.contracts}}",
    "comment": "{{strategy.order.comment}}"
}

alert

 
user
Original Posted by - b'admin':

According to TradingView (https://www.tradingview.com/support/solutions/43000481368-strategy-alerts/), strategy alert currently doesn't provide information about open/close and transaction number. As a workaround, you can put those information in pine script's comment.

For example, we have 2 strategies in TradingView using '123' and '124' to distinguish them. For entry order, we put 'open' in the comment; while putting 'close' for exit order.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
// pine script

if entryCondition1
    strategy.entry("buy", strategy.long, qty=10, comment="open 123")

if entryCondition2
    strategy.entry("sell", strategy.short, qty=20, comment="open 124")

if exitCondition1
    strategy.exit("sell", strategy.short, qty=10, comment="close 123")

if exitCondition2
    strategy.exit("buy", strategy.long, qty=10, comment="close 124")


Then copy this to TradingView's alert setting.

1
2
3
4
5
6
7
8
{
    "instrument": "{{ticker}}",
    "price": "{{close}}",
    "ordertype": "LMT",
    "buysell": "{{strategy.order.action}}",
    "volume": "{{strategy.order.contracts}}",
    "comment": "{{strategy.order.comment}}"
}

alert

Hello What of {{strategy.position_size}} how can I use this placeholder in algogene?
 
admin
Original Posted by - b'user': Hello What of {{strategy.position_size}} how can I use this placeholder in algogene?

"{{strategy.position_size}}" is currently not supported on our system. It needs to specify the details (eg. buy/sell direction, volume, order type, etc) for each trade instruction.

You can refer to below RSI example. It will close all outstanding trades when there is new signal.



//@version=5
strategy("RSI Strategy", shorttitle="RSI Strategy", overlay=true)

// INPUT VARIABLES
trade_qty = 1 
RSIlength = input(14,title="RSI Period Length") 
RSIoverSold = 30
RSIoverBought = 70
price = close

// RSI Strategy
vrsi = ta.rsi(price, RSIlength)
BUY = ta.crossover(vrsi, RSIoverSold)
SELL = ta.crossunder(vrsi, RSIoverBought)

if (not na(vrsi))
    if (BUY)
        if (strategy.position_size<0)
            strategy.close("RSI_S", comment="[{'orderRef':'RSI_S','openclose':'close'},{'orderRef':'RSI_S','openclose':'cancel'}]")
        strategy.entry("RSI_L", strategy.long, qty=trade_qty, comment="{'orderRef':'RSI_L','openclose':'open','ordertype':'MKT','volume':"+str.tostring(trade_qty)+",'price':"+str.tostring(price)+"}"  )

    if (SELL)
        if (strategy.position_size>0)
            strategy.close("RSI_L", comment="[{'orderRef':'RSI_L','openclose':'close'},{'orderRef':'RSI_L','openclose':'cancel'}]")
        strategy.entry("RSI_S", strategy.short, qty=trade_qty, comment="{'orderRef':'RSI_S','openclose':'open','ordertype':'STOP','volume':"+str.tostring(trade_qty)+",'price':"+str.tostring(price)+"}")