Since Tradingview made it really easy to connect their alert system to 3rd party applications, it has become more important than ever to really understand how what happens when we connect to a service for automation, the limitations that come with it and how to make sure your strategies stay in sync!
As good as webhooks and email alerts are, they have one significant limitation which can make it really easy for your strategy to lose sync with the real world. They are push notifications, a form”one-way” communication. In other words, Tradingview can talk to the 3rd party service and send it information but the service cannot talk back to Tradingview. This means that you cannot update your strategy according to what is happening in the real world and therefore potentially lose sync with your position.
Don’t let the previous paragraph put you off using webhooks though. There are things we can do to mitigate that risk and as long as you understand the risks, you are able to make an informed decision whether to push ahead.
Let’s start by taking a look at some of the ways Tradingview may think you are in a position when you are not or vice versa.
The spread is the hidden killer in the room. It is the difference between the best price someone is willing to pay for an asset and the best price someone is willing to sell the asset for. These buy and sell prices are otherwise known as the
You might notice that Tradingview does not provides
askquotes (at the time of writing!), instead, it provides a single price for the
close data taking the average between the
bid and the
ask. This is generally known as the
This becomes easy to see when you look at a real order book on an exchange. The image below is a snapshot of an order book on Radar Relay.
The image shows the
WETH/DAI spread. Here you can see that the best price we can buy
WETH for now is 142.6
DAI. Similarly, the best price we can sell
WETH for right now is 141.3
DAI. This creates a spread of 0.44%. Quite large for those of you who rely on strategies that try to make lots of small profits!
mid price for this asset is approximately 142. Now with this in mind, imagine you created a limit order to buy at 142 in your strategy. The strategy would see that 142 has been hit, fill the order and now think you are in a position. However, in the real world, you would not be because there is no one willing to sell at 142 (only 142.6). So instead, your order would sit at the top of the order book. Now you are out of sync!
Remember the spread also can (and will) widen at any time!
The next big synchronization killer is the lack of order notifications. Orders can be rejected by your broker for a whole number of reasons. Some examples include;
- You do not have enough cash to fill the order
- The order might be placed too close to the market price
- It was sent at a level which does not conform to the instruments minimum tick
If an order is rejected or not filled, Tradingview will just assume it was filled and now you are out of sync again.
For those who like to trade on margin, your position could be liquidated if you fall below your maintenance margin. When this happens losing sync with Tradingview is the least of your worries though!
Stay in Sync
When a request to convert a strategy into a study for automation comes into the development service inbox, two workarounds are usually proposed.
- Only use market orders.
- Only use Tradingview for signals. I.e Ignore all position management, entry orders, stop losses etc. Blindly fire signals whenever they are generated and then handle everything else in the 3rd party service.
As you might guess, each of these “workarounds” has pros and cons.
Market orders will allow Tradingview to be in complete control all the time. A position can only be opened or closed when Tradingview fires an alert to do so. As such, Tradingview is much less likely to lose sync with the broker.
Another advantage is that using market orders allows you to translate a Tradingview strategy into an automated strategy without developing parts of it in another framework. (Which would be required for the signals only workaround)
Having said that, Market orders will not help with order rejection issues and on some exchanges (We are looking at you, Crypto) the fees are higher for market orders.
Using Tradingview to generate signals only is the other option. When doing this, you fire every single long/short signal regardless of whether you are in a position or not. You then use another framework to manage the signals coming in, ignore them or make a trading decision and then manage the position until the exit.
The advantage of this method is that you are unlikely to ever lose sync with the real world.
The downside is that there are not as many 3rd party services that allow a deep level of position management and the ability to manage incoming signals. A lot of services will blindly relay every alert to the broker.
Then of course, as mentioned above, you will need to learn another framework
So what about tv2bt?
Regular readers will know that we have a 3rd party open-source tool which can utilize Tradingview webhooks, connect to Backtrader and manage positions/signals.
The limitations of
tv2btare no different from any other 3rd party service. The same limitations noted above apply. As such, a clear understanding of the limitations should be understood before risking your hard-earned money automating a strategy!
Find This Post Useful?
If this post saved you time and effort, please consider support the site! There are many ways to support us and some won’t even cost you a penny.
Backtest Rookies is a registered with Brave publisher!
Brave users can drop us a tip.
Alternatively, support us by switching to Brave using this referral link and we will receive some BAT!
Enjoying the content and thinking of subscribing to Tradingview? Support this site by clicking the referral link before you sign up!