When you trade on Margin or Futures, you may want to catch both price rises and drops. With TradingView custom signals and two bots, you can change position from Long to Short or Short to Long:

  • You can do this on something simple like when the price crosses $10000.

  • Use the enormous library of technical indicators, something like when RSI-7 drops below 20.

  • Write custom solutions with Pine Script for conditions on multiple indicators or even private strategies.

The only thing that limits you is the time you want to invest in learning these tools. 

Create two bots - one Short and one Long

Here is the article that explains how to create a DCA bot with the TV custom signals deal start condition.

Some tips:

  • If you don't need additional buys, set the bot's Max safety trades count setting to 0.

  • To prevent the bot from closing deals too early, set take profit to 50% or more of the total volume (learn your exchange's trading limits).

  • There's no need to start anything manually. If a close message comes to the bot while it has no active position, it'll just ignore it.

  • If you disable/turn off the bot, it will still close a deal if the bot receives the "Close Deal" signal.
    NOTE! If the bot was active and received the "Open deal" signal with N seconds delay and then the bot was turned off, the deal would still be opened after N seconds delay has passed.

Let's go step by step again and create the needed alert!

Use Webhook URL, not other options

When creating alerts on Trading View, choose Webhook URL, then paste the link (webhook or hook):

https://3commas.io/trade_signal/trading_view

Create the first alert when you want to go Long

Assume you want to open the Long position when RSI drops below 20 and close the Short position at the same moment:

First, you need to close the Short position before starting the new Long one.

Open the information about your Short bot by clicking its name and find the Message to close order at Market Price, which looks like this:

{
"action": "close_at_market_price",
"message_type": "bot",
"bot_id": 756065,
"email_token": "d98xxxx9-xxx5-xxx2-xxx0-dxxxxxxxxx3b",
"delay_seconds": 0
}

Then open the information about your Long bot and get the Message for deal start signal:

{
"message_type": "bot",
"bot_id": 820763,
"email_token": "d98xxxx9-xxx5-xxx2-xxx0-dxxxxxxxxx3b",
"delay_seconds": 0
}

Important:

Exchanges might take some time to close your previous position. To avoid conflicting with this, use "delay_seconds" with values near 4-10 on the open message. Considering this, the Message for deal start signal for the Long bot will be:

{
"message_type": "bot",
"bot_id": 820763,
"email_token": "d98xxxx9-xxx5-xxx2-xxx0-dxxxxxxxxx3b",
"delay_seconds": 6
}

The final thing you should do with these messages for Short and Long bots is to combine them by enclosing them into square brackets [ ] and separating them with a comma.

Here is what our messages will look like:

[
{
"action": "close_at_market_price",
"message_type": "bot",
"bot_id": 756065,
"email_token": "d98xxxx9-xxx5-xxx2-xxx0-dxxxxxxxxx3b",
"delay_seconds": 0
}
,
{
"message_type": "bot",
"bot_id": 820763,
"email_token": "d98xxxx9-xxx5-xxx2-xxx0-dxxxxxxxxx3b",
"delay_seconds": 6
}
]

Additional new lines and spaces don't matter but make sure all other symbols are in place. Miss one bracket or comma, and it won't work. There's a simple way to validate that your message is correct: https://jsonformatter.curiousconcept.com/. Paste the message, then click Process, and as long as you get the green message VALID, you're fine:

Paste the final combined message into the Message field in your alert. It should look like this:

Create the second alert to switch from Long to Short

All you are left to do is to create similar alert to close the active Long position and open a new Short position. It's almost the same process:

  • Take the Message to close order at Market Price from the Long bot.

  • Take the Message for deal start signal from the Short bot.

  • Set "delay_seconds" (4-10 seconds) in the Message for deal start signal for the Short bot.

  • Combine messages and validate the result.

  • Put combined messages into the message field in your alert.

Test with Paper Trading when you're not sure

If you're not ready yet to take any risk with real funds trading, switch to Paper trading account and check this strategy there.

Did this answer your question?