Back-End

TradingView Bot

My Role
Back-end Developer
Timeline
May-Aug 2021

Webhook TradingView Bot 📈🤖

Trading Bot with Optional Discord Integration

Project Description

This Trading Bot is a sophisticated solution that integrates TradingView alerts with an optional Discord feature. It is designed to enable traders to respond to potential trading signals in a controlled manner, with the flexibility to choose between automated trading or interactive human oversight before the execution of trades.

Technologies Used:

  • Python
  • TradingView
  • Discord API (Optional)
  • Hosting on Repl.it

Screenshots:

Mean Reversion Strategy BTCPERP
Mean Reversion Strategy BTCPERP

Link
Github Repository.

Detailed Explanation

Objective:

The bot is inspired by the need for a more flexible and controlled approach to automated trading. Users can set the bot to execute trades automatically based on TradingView alerts, or they can enable Discord integration for a more interactive and thoughtful trading experience, allowing for group discussions and strategic decision-making based on visual analysis of charts.

Implementation Details:

Automated Trading:
  • Automatically executes trades based on TradingView alerts.
Optional Discord Integration:
  • Communicates TradingView alerts directly to a Discord channel, with URL links to relevant charts.
  • Executes trades through simple Discord commands, with customizable order details.
  • Confirms trade execution and notifies the user of progress and outcomes.
Real-time Logging and Error Monitoring (with Discord Integration):
  • Logs operational messages and error alerts in dedicated Discord channels, if enabled.

Concrete example:

For our example we will use a pinescript strategy focused on mean reversions : if we are above/under the 200 period EMA, RSI is overbought/oversold and we have a bearish/bullish engulfing candle we will either short or long the position trying to come back to the 200 period exponential moving average. For ease of use the stop-losses and take-profits are placed using "random" values of ATR.

Of course it is far from being perfect so don't use it for you own trading since it wasn't written for this purpose and it's a strategy going against the main trend (thus very risky). However we will see how we can improve it and integrate our own choice thanks to the discord bot.

With the discord bot you can filter the trades and add more weight to your decisions if a regular divergence occurs for example, however many mistakes can happen if you try to code it so it might be better if you analyse it by yourself.

At some point the chart looked like this with an alert triggered.

Mean reversion loss
Mean reversion loss

The chart url will thereby be sent to the discord channel so that everyone can debate (ideally directly send an image instead of a link).

Discord chat 1
Discord chat 1

The TradingView alert contains the link toward the chart and a prepared payload anyone can just copy-paste to place an order and may modify it a bit.

Kakkkashi feels good about this trade but Yud_4 suggest him to wait another alert and see if they can notice a divergence in the RSI (Relative Strength Index) and actually after a little while we have one :

Mean Reversion Divergence
Mean Reversion Divergence

You notice that if we have taken the first two trades we would have lost.

As you can see price makes higher highs while RSI is making lower highs (the white line has been manually placed for illustration). An RSI divergence demonstrate that the price is losing its momentum and the trend is slowing down, this can be a "perfect" reversal signal for our mean reversion strategy.

Let's see how the other two react to this one.

Discord chat 2
Discord chat 2

Here after a simple command !payload Yud_4 was able to place the order after making a small modification to the market type (limit -> market). He then received a confirmattion through the bot that everything went accordingly, should an error occur he would also be aware of that and could check the error logs for more information.

Finally they did well selecting that trade as it was a winner.

Mean Reversion Divergence Win
Mean Reversion Divergence Win

* This conversation example has been set up since the alerts occured in the past when this was done.

Feel free to have a look at the project under its GitHub repository.