IMPORTANT NOTE: Trading Bots are currently a Beta feature, which means that certain issues are still to be expected. We've done our best in order to iron out all the problems, but still, we can't claim that it's guaranteed to be stable. Please be cautious and double-check your bots.
The trading bots feature in TrendSpider is a powerful functionality that allows the traders to fully automate the order execution with a broker or exchange via webhooks, receive live notifications, and post in a private chat room or to social media. In this documentation, we will explore:
- Creating a Bot Strategy
- Create a Trading Bot
- Setting Up a Trading Bot
- On-Chart Signal Marks
- Verify Trading Bot Functionality
- Manage Trading Bots
- Changing or Downgrading Plan
- Best Practices of Using Trading Bot
Let’s get started 🚀
Creating a Bot Strategy
Before you can start setting up the trading bot, it is a prerequisite to have a strategy in the first place. You can create a Strategy in the Strategy Tester. Please refer to the documentation -Creating a New Strategy to learn more about how to create strategies using a strategy tester.
Create a Trading Bot
There are three methods to navigate to the Trading Bot Configuration for setting up your trading bot:
Method 1: Using the “Alerts & Bots” Option from the Top Toolbar
Method 2: Using Strategy Tester
Method 3: Using Trading Bot Widget
Method 1: Using the “Alerts & Bots Option” from the Top Toolbar
Step 1: Click on the vertical ellipsis adjoining the Alerts & Bots button
Step 2: Select Create a Trading Bot option from the dropdown list.
The window for creating the trading bot will appear. You can select your strategy from the dropdown and complete setting up your trading bot through this window.
NOTE: The strategy selector box only contains strategies that are not read-only.
Method 2: Using Strategy Tester
Step 1: Click on the Strategy Tester button from the top-right corner of the top menu bar.
Step 2: Load any of your strategies from the Strategy List in the left panel (or create and configure a new one) and click on the RUN button to run the backtest.
Step 3: Click on the Launch as Trading Bot button (which appears as soon as the test of a strategy has been completed) at the top-right corner of the tester.
The window for creating the trading bot will appear. The strategy selected in Step 2 above will be automatically picked and you can configure the rest of the settings to complete setting up your trading bot.
NOTE: The strategy selector box only contains strategies that are not read-only. So if you are testing a strategy that is read-only and then tries to create a bot from it, then your Strategy box won’t have it pre-selected.
Method 3: Using Trading Bot Widget
Step 1: Navigate to the right sidebar and click on the Trading Bots option to add to the sidebar.
Step 2: Select Add to the Sidebar from the dropdown.
Step 3: Click on the Create a Bot button.
The window for creating the trading bot will appear. You can select your strategy from the dropdown and complete setting up your trading bot through this window.
You can also click on the vertical ellipsis ⋮ from the top of the trading bot widget and select the option- Create a Trading Bot from the dropdown list.
Setting Up a Trading Bot
After navigating to the Bot configurations settings, you can set up and create your trading bot. The below-provided instructions explain every property you can set up while creating a bot.
Bot Name
Provide a name for your trading bot. We’ll auto-generate a name for you, in case you don’t want to invent one.
Strategy
Select your backtesting strategy from the dropdown.
Time Frame
Select the time frame for which you want the trading bot to check the criteria. For example, if the time frame selected is 1 hour, then the trading bot will check for the criteria after each hourly candle is closed.
Limitation
- Trading bots can only work on time frames from 15 minutes to Daily.
- On short days bots created on the Daily time frame won’t trigger at 13:00 and will trigger at 16:00 instead.
Notifications
Select the mode with which you are most comfortable receiving the notifications whenever your trading bot enters or exits a position.
You can select any combination or all of the following modes for receiving the notifications:
- SMS: If enabled, then you will receive the corresponding notifications to the cell phone number defined in your Account Notification settings
- Email: If enabled, then you will receive the corresponding notifications to the email address defined in your Account Notification Settings.
- Webhook: if enabled, then we’ll send HTTP POST requests to the webhook you provide (see below).
Webhook
Selecting Webhook as the notification preference will require you to define the following two criteria for entry webhook and exit webhook.
- Webhook URL/Endpoint
- Webhook Body (Enter it in the format your destination server expects to receive when a signal is sent to it)
NOTE: Your webhook provider should be capable of executing orders on a post-market. You won’t have any signals executed on the last candle of a day otherwise.
Read more about Webhooks on TrendSpider, along with variables supported in Webhooks (with Discord examples)in our Knowledge Base. The table below provides the list of documents explaining the instructions for establishing a Webhook connection between TrendSpider and third-party applications:
NOTE: You can also choose to skip configuring the notifications, but in this case, the SMS option will be selected by default. However, if you choose to disable all the notification modes, then you will not receive any notification whenever your trading bot enters or exits a position.
Control Notifications
Control notifications play an instrumental role in providing you with insights into the behavior of the trading bot. They explain every step of a trading bot (even if the step is “do nothing at this time”).
Critical Only Control Notification: Selecting this from the dropdown will provide you with a notification that is critical in nature, for example- stopping the bot.
Verbose Control Notification: Selecting this from the dropdown will provide you with a notification on every step of the trading bot workflow, in addition to the critical notifications. For example, you will be notified every time the bot enters the position.
TIP: You can use control notifications to track your bot for a while before attaching the webhook as your notification preference.
You can select SMS Email or both as the mode for receiving the control notifications.
Bot Behavior Settings
The bot behavior settings allow you to configure how your bot should behave under certain circumstances. The set of settings you can customize depends on whether your bot has webhooks enabled or not (explained below).
Behavior Settings (When the Bot Has No Webhooks)
In this case, you can define the following two options:
I. When Missed A Check: This option is always selected to Notify and stop a bot. If the trading bot has missed a check (for any weird reason, which is never supposed to happen), then you will be notified and the bot will be stopped.
II. When Started in Position: This option allows you to decide how the bot should behave if it starts while already being in an entry position, by making the selection between any of the following two from the dropdown.
- Generate the first entry after the next exit: Selecting this will allow the bot to pretend as if the bot was never in the entry position. In this way, the bot will wait for the next exit and then wait for the next entry before going in.
- Generate the entry signal immediately: Selecting this will allow the bot to make an entry position right away since the bot is already in an entry position. Be aware that in this case, your Stop Loss/Take Profit/Trailing Stop levels will be computed from the "entry point in the past", for the purpose of being consistent with the back tester.
Behavior Settings (When the Bot Has Webhooks)
If your bot has webhooks attached, then the system allows for setting a few additional options. When there’s a webhook, you are provided with the option to handle the “webhook calls failures”. Webhook call error is not somewhat what’s supposed to happen, but eventually, your webhook provider might have issues and we want you to be in control of what the bot should do in this case.
In this context, a “failure” means “webhook has failed to respond within 7 seconds or has responded with an HTTP code which is 4xx or 5xx but not HTTP 400.
The additional options which are only available if your bot has webhooks attached are listed below.
I. Retry failed webhooks: This option selected to Never means that the trading bot will not make a retry if it fails to call the webhook. However, selecting a particular number for the retry will allow the trading bot to perform the retry for the number of times selected with a pause of 3 seconds between the attempts. For example, selecting Retry 5 Times will enable calling webhook up to 5 times like that:
1. Call a webhook
2. Wait for its response (or for a time-out of 7 seconds)
3. If it’s worth retrying (according to the error code) then wait for 3 seconds
4. Repeat 1-3, up to 4 more times
II. When failed to enter: If the Bot fails to “enter the position” (defined as “calling a webhook failed after the set number of retry attempts defined in (I) above”), then you will need to define the behavior of the bot by making a selection between any of the following two from the dropdown.
- Notify and assume manual entry: Selecting this option will send you a notification for the failed entry and instruct the bot to assume that the entry has happened and proceed to work as usual (which means that it will start seeking to exit the position, as per your strategy).
- Notify and stop a bot: Selecting this option will send you a notification for the failed entry and instruct the bot to stop functioning.
III. When failed to exit: If the Bot fails to exit the position after the set number of retry attempts defined in (I) above, then you will need to define the behavior of the bot by making a selection between any of the following two from the dropdown.
- Notify and assume manual exit: Selecting this option will send you a notification for the failed entry and instruct the bot to assume that the exit has happened and proceed to work as usual.
- Notify and stop a bot: Selecting this option will send you a notification for the failed exit and instruct the bot to stop functioning.
NOTE: Failure to call a webhook (after all the attempts, if any) is a subject for a critical control notification, never mind what the “When failed to ***” settings are.
After configuring all the above settings, click on the CREATE BOT button. After that, the trading bot will start generating and painting the entry/exit signals according to the strategy defined. After creating the bot, it is added to the Trading Bot widget in the right sidebar.
NOTE: There are some corner cases when you have one candle generating both entry and exit signals (i.e., stop loss triggering and entry condition triggering at the same candle). In case your bot was “in position” before this candle, then it won’t generate any signals at all and will stay in position instead.
NOTE: Bots check their conditions as soon as the corresponding candle closes, in 40 to 60 seconds.
Creating a bot will clone and lock the particular strategy that has been used so that you can have a record of the strategy used and check it out at any time for your reference. You cannot edit this strategy and it will be in the read-only mode.
If you want to change the strategy, then you will have to perform the alterations in the original one and then create a new trading bot using it as a base. Also, you can not remove the “cloned version” of the strategy until there's a bot that uses it. Removing a bot removes its own clone of a strategy.
Note: Cloned strategies are named after the bot “as of the moment when you created it”. If you will rename a bot, then the cloned strategy won’t be renamed.
Limitation: Creating a bot disables the “ext. hours” flag for a strategy. Currently, trading bots can’t work on extended-hours candles.
On-Chart Signal Marks
After creating the bot, it will generate the entry/exit signals and paint them on the chart using the strategy defined. A bot paints signals only when the chart matches it in terms of ticker, time frame, chart type, and extended session status. For example, you won’t see your 15-minute bot’s signals on a Daily chart.
For a more clear view of the signals painted by the trading bot, you can choose to toggle off and hide the strategy tester from the indicator list on the top-left corner of the chart.
The entry/exit signals will stay visible on the chart as long as the bot is not removed and the Alerts & Bots button is toggled on (enabled) at the top toolbar.
Limitations:
- The colors are assigned automatically while creating the bot and you cannot customize them. It’s a limitation of the Beta version which will be resolved soon.
- You cannot hide the marks generated and painted by one trading bot. You can only hide or display all the marks of all of your bots and alerts.
- Trading Bots do not paint the execution arrows on the mobile view for now.
Verify Trading Bot Functionality
Trading bots internally makes use of backtesting the strategy you have defined. This means that your bots will either be consistent with the backtests or dead. We believe that bots should behave according to how your strategy has acted when you backtested it). There is basically only one exception here: conflicting signals emerging on the same candle (entry + exit or exit + entry) are muted by trading bots and don't lead to the bot's state changes.
To verify the trading bot functionality, you can use control notifications that explain your bot‘s behavior and track your bot for a while before attaching a webhook. In this way, you will have an understanding of how things work and what to expect.
However, if you want to compare, then please use the “cloned/read-only” version of a strategy, because it’s exactly the version your bot uses. This version of a strategy will have its “Backtest date” locked to a particular date in the past and this date won’t ever change.
Upon every condition check, our bots execute an internal consistency check. This check ensures that signals past or recent signals have not changed (i.e., have not moved) and such. In case this check (we call it a "health check") detects a change, we stop a bot and notify you. Signals are not supposed to move once emerge, and normally they don't. Signals can move either in case of major history adjustments (which happen rarely) or in case you misuse unstable indicators or forward-looking indicators like ZigZag.
Manage Trading Bots
You can manage your trading bots from the trading bot widget and perform the following actions:
- Edit the Trading Bot Settings
- Stop the Trading Bot
- Clone the Trading Bot
- View Trading Bot Status
- Remove the Trading Bot
Edit the Trading Bot Settings
Edit any of the active bots from the list to execute the following modifications:
- Bot Name
- Notifications
- Control Notifications
- Some of the Behavior settings
Step 1: Click on the edit icon on any active trading bot from the list.
Step 2: A modal window for editing the Trading Bot will appear, allowing you to execute the necessary modifications listed below.
1. Rename the Bot
2. Change the notification mode
3. Change the control notification preferences
4. Change those Behavior settings that are not locked (like “when failed to enter” for example)
Step 3: Click on the SAVE button after making the relevant changes.
Stop the Trading Bot
You can stop an actively running trading bot from receiving any signals. Please note that stopping a bot leaves your position “as they are”: a bot won’t attempt to exit the position if it exists.
Step 1: Click on the Stop icon of any of the active trading bots from the list.
Step 2: A confirmation window will appear. Click on the YES button to proceed with your action.
Clone the Trading Bot
When an existing Trading Bot is cloned, whether active or inactive, a complete copy of all the configurations is done (except the backtesting strategy) which you can use as a base for creating a new Trading Bot.
Step 1: Click on the Clone button of any of the active trading bots from the list.
Step 2: A modal window for cloning the Trading Bot will appear, allowing you to create a new Trading Bot by using the existing configuration as a base.
Step 3: You can choose to keep the existing configurations or edit the same for Name, Time Frame, Notification Mode, Control Notification Preferences, and Behavior Settings. Once done, select the backtesting strategy from the dropdown, click on the Create Bot button, and the new Trading Bot will appear in the listing.
View Trading Bot Status
Click on the ⓘ button of any of the active or inactive trading bot from the list to view its current status.
A rectangular callout window will appear providing you with the following details:
- Name of the Bot, Symbol, and Timeframe Selected
- Backtesting Strategy Used
- Date and Time of Creating the Bot
- Date and Time of Updating the Bot
- Running Status: Active or Not Active
- Position Status: In Position or Not in Position
- Last 5 signals (if they exist): action + date & time for each of them
If checking the status of an inactive Trading Bot, then in addition to the above details (except Signals), you will also view the Date and Time of Stopping the Bot and the Reason for Stop.
Tip: You can also copy and paste the Trading Bot status information.
Remove the Trading Bot
You can permanently remove a stopped trading bot from the list by clicking on the delete icon button. Removing a trading bot will leave your positions “as they are” (it won’t exit if it’s in the position) and will wipe all the bot’s action history from our servers. You will stop receiving any signals from this bot and you won’t be able to undo this action.
A confirmation window will appear. Click on the YES button to proceed with your action.
Changing or Downgrading Plan
If you select a plan in which backtesting is not available or downgrade your plan (which either has less of bots or does not allow for backtesting), then all of your bots will be stopped.
Best Practices of Using Trading Bot
Follow the below-listed practices for the best results:
1. In general, we recommend taking the following steps before you have your bot trading with real money:
- Backtest your strategy and make sure that it’s sane
- Run it as a bot, but don’t attach it with any trading webhooks: enable verbose control notifications and wait for a couple of days to make sure that its behavior does match your expectations.
- Attach entry/exit webhooks that trade. You’re ready now!
2. Don't trade manually with the assets (tickers) managed by your bot, unless you’re correcting its mistakes
3. If you trade cryptos, then do have some spare amount of currency for the purpose of paying the fees, or trade using “percentage of your account” rather than “amount of currency”.
Frequently Asked Questions
Q 1: My bot had been stopped by the system as "it can't be trusted anymore". Why?
A: Things like that are not supposed to happen in normal circumstances, yet still they can. Long story short, upon every check bot checks quite a few things in order to make sure that it's reliable and launching on time, etc. We call that a "health check" internally. Sometimes this check reveals problems, which means that this bot is at risk of being inconsistent with its signals. In the vast majority of cases, it means that there's something wrong on our end. We're being notified about every case when a bot fails and we treat these with the highest priority. We're aiming to make that never happen as Beta comes to an end.
Q 2: My webhook was not executed, why?
A: When you create a bot, please have Verbose Control Notifications (via email) enabled for a while. Any time the bot enters or exits, it will send you an email about that along with a copy of your webhook server response. Please verify that the response is legit and is not flagging any errors in the input data (i.e., in your JSON). If your webhook service is not stable, then please consider enabling "Retry failed webhooks".
Q 3: My stop loss or take profit was fired late, why?
A: At the moment (during Beta) stop-losses, take-profits, and trailing stops will only be fired "as soon as the corresponding candle closes", never mind which part of a candle has hit the level. This is a limitation of a Beta version which we're going to address.
Q 4: I have a forward-looking indicator (like Williams Fractals) in my strategy, will it work?
A: Willams Fractal Highs or Lows always emerge "2 candles ago" (with the standard Fractal length) which means that one needs to be careful when designing backtests or bots with it. I.e., checking if "last candle is a Fractal High" will technically work on the back tester, but it can't work on a live strategy because the last candle can never be a Fractal point. In cases like that, you're supposed to use offsets (X candles ago). Like, if you wanted to "sell when a Fractal High emerges" then you'd need to do it like this: 15min High (2 candles ago) Equals 15min Fractal.Bear (2 candles ago)