Connecting Tradingview Buy/Sell signals to your Strategy
Last updated February 10, 2024
Overview
In this example, we are going to:
- Setup 2 Webhooks on our Strategy to accept buy and sell alerts from Tradingview.
- Connect them to indicator alerts in Tradingview
- Setup Stories in TradeStory that will execute buy/sell orders on an account when these Webhook alerts are triggered.
1.Setup the webhooks
In a new Strategy in TradeStory, click on Add Webhook to add a new webhook for your Buy signals to be received on.
Enter the name of your webhook endpoint.
Repeat this to create another webhook endpoint to receive the Sell signals.
You will now have 2 webhook endpoints on your strategy - ready to receive signals from Tradingview.
2. Connect these endpoints to Tradingview indicator signals.
Click on the link icon for your Buy Signal webhook to copy the webhook URL for your Buy Signal.
Navigate to your Tradinview indicator. Click on the
icon at the end of your indicator of choice - and select Add Alert.
Select the condition for your Buy signal in the Condition ( in this case the Buy alert is listed as DeLorean Buy ). Select when your alert is triggered - usually this is Once Per Bar Close - to ensure the signal is only sent after the bar is closed and once!. Also set an alert name so you can keep track of it within Tradingview.
Click on the Notifications tab at the top of this alert menu - and paste the URL of your previously created Buy Signal Webhook Endpoint into the Webhook URL field.
Click Create to save your alert.
Repeat this process for your Sell Signal.
You should now see that there are 2 active alerts setup in Tradingview.
3.Setup stories to execute your trades when the webhook alerts are triggered.
Now you have 2 webhooks configured to receive alerts from Tradingview on your Buy and your Sell alerts. Now you have to set up a couple of Stories within TradeStory that will be run when either a Buy or Sell webhook is triggered. These stories will be where you configure your account, trade types and size.
In your TradeStory strategy, click on the Stories Tab and click on Add Story.
Type the name of your first story - in this case we will create a story to execute a Buy (long) signal.
Click on your new Story to edit it.
By default, you will be presented with the default story - which simply logs out a message to your logs when it runs. You can remove this Story Item from your story if you wish, but we will keep it in there so that we can see in our logs later. Let's give it more context:
Click on the green ‘plus’ icon to bring up the Story Item toolbox. Search for the Add New Order item and click on it to add to your Story.
You will see that a New Order Story Item has been added to the bottom of your Story, where you can configure the details of your account, symbol, size etc. (See New Order Story Item for details on how to configure this).
In our example, We will select our account, give it a reference ‘DeloreanLong’ and set up the Symbol ‘US100.cash’ with a volume of 20 contracts. The Type of trade is a BUY MARKET (already selected) so we can leave that as it is. (If we were configuring another type of order, like Sell or Limit etc we can click on the order type and select the type we need).
(We highly recommend, in fact, strongly urge you to use stop loss and take profit targets, which can be configured here also if you wish).
Click on Save Changes button
at the top of the page to save your story.
Repeat the same again for your Sell Story.
You should now have 2 Stories - your Buy (Go Long) and your Sell (Go Short) story:
4.We now need to tell our Webhooks to Run these stories when they are triggered.
Back in our Strategy Webhooks list - click on the Buy Signal Webhook (which brings up the Actions Panel for your webhook), and click on Add Action.
This allows you to assign actions to your webhook. Select Run Story from the dropdown and select your Buy Signal Story.
Story: Go Long
Click Save to add the Story to your webhook.
You will then see that your Go Long story has been added to your webhook actions list.
What this means is that when your Buy Signal Webhook endpoint is triggered, TradeStory will execute your Go Long Story, which performs the magic of making your Buy trade to your connected account.
Repeat this process for your Sell Story->webhook actions.
Congratulations - you have connected your Buy and Sell signals from Tradingview to your TradeStory Webhooks, which in turn now execute your stories and trades automatically.
Progression. (Sending Data within Webhooks)
The above example shows how you can create 2 different Webhooks for Buy and Sell. It is possible to configure a single webhook to receive these buy and sell alerts if you send data about the direction of the trade in the Webhook - See Sending Data in Webhooks .
Eg: Data can be put in the message to your webhooks endpoints.
{
“data”: {
“direction” : ”BUY”
}
}
{
“data”: {
“direction” : ”SELL”
}
}
Then you can check which direction your signal is in your story using Webhook Data Items and Conditionals .
Taking it even further
You can also pass in other information to your webhook (in any shape you wish) - eg Stop Loss and Take Profit.
{
"data": {
"direction": "long",
"my_stop_loss": 1790.25,
"my_take_profit": 1850.00,
"volume": 20
}
}
Adding Dynamic Values from Tradingview Scripts
Just as you can pass in data to webhooks, this can include dynamic fields from Tradingview within the webhook alert message
For example:
{
"data": {
"direction": "{{plot("strategy.direction")}}",
"my_stop_loss": {{plot("stoploss")}},
"my_take_profit": {{plot("takeprofit")}},
"volume": {{plot("contracts")}},
}
}
More detail can be found on the Tradingview docs about dynamic variables in alerts .