We will teach you how to build your first trading bot in 10 minutes using the functionality of the TradingView platform and talk about other interesting tools available to contemporary retail traders. In an age where an AI crypto trading bot is not a livid dream of a tech geek, working diligently to build your own automated solutions may look like something utterly unnecessary. Nevertheless, it can be an excellent practice for a newcomer.
How to create a bot for trading
A trading bot is a script that executes a certain algorithm when triggered by a condition. One of the easiest ways to get started is to focus on the biggest charting platform out there. TradingView is an incredibly versatile analytical tool and one of the most powerful terminals available to users in the crypto ecosystem. With its potent suite of tools, it allows retail traders to analyze the market, make predictions based on market history, and receive alerts.
Initially, the functionality of this charting tool was limited to just being a smart terminal with a handful of unique indicators and graphical instruments unavailable in many similar products at the time. Thanks to a zealous development team and strong leadership, the platform turned into a multi-purpose service that even allows for some basic automated trading for beginners.
The automation of all activities on the platform is done in the Pine Editor. It is a simple code editor that understands the proprietary Pine Script and can be used to work on any chart or group of charts. This coding language is very simple and does not require users to have any prior experience to be efficient from the get-go.
A beginner’s guide to crypto trading bots
Pine Editor is used to create indicators and strategies. In the Editor, they are called “Studies” and “Strategies”. Every piece of code that defines a strategy starts with the annotation call “strategy ()” and contains several operators that form an algorithm.
The current version of Pine Script is 6 and many examples out there are outdated as they use the 4th version. The syntax is nearly the same and the beginning of any script looks like this:
//@version=6
strategy (“my strategy”, overlay = true)
In these two strings, we specify the version of Pine Script and state that we are going to write a strategy under the name “my strategy” and make it visible on the chart.
In our example, we will be using several variables and parameters to create a simple strategy that executes a certain order when two simple moving averages cross. It is a staple approach in technical analysis. To learn how to create your own trading bot in Pine Editor, you will have to practice a lot but it is fine to start with something basic.
Here are some bits of knowledge you will need to follow the example we use in this guide:
● Float is a declaration of value or parameter that can have decimal points and thus provide more precision.
● Int means integer and represents a certain value that does not have any decimal points. In TradingView, it is often used to define indicator parameters.
● ta.sma is an operator that refers to the “simple moving average” indicator with “ta” standing for “technical analysis”. You can use ta. for different indicators (i.e., “ta.bb” means Bollinger Bands).
● Strategy.entry/exit are operators that define operations that are executed to enter and exit the market respectively.
● Plot is an operator that puts a series of data on a graphical chart. It can be used for indicators with “ta.(any indicator)” and a variety of adjustable parameters and comments.
These are operators and value types that we will need to make a trading bot that we are using as an example in this “lesson”. This particular script can be used as a template for many other simple designs. However, to make a complex robot that can perform under different market circumstances, you will need to dedicate some time to learning indicators and how they work as well as expand your knowledge of Pine Script.
How to create a trading bot in TradingView
We have already mentioned how to start the script. In this example, we will be using a simple method of automating trades that must be executed when a fast simple moving average crosses over a slow one. It is a strategy that many newcomers learn among the first when mastering technical analysis.
Start the script with the declaration of function:
//@version=6
strategy (“my sma strategy”, overlay = true, margin_long = 100, margin_short = 100)
Here, we give the strategy a name and allow it to be displayed on the chart. Adding margin_long/short arguments tells the system that the trade must use 100% of the allowed position size. You can also use leverage by using larger values.
Now, we must declare the parameters for simple moving averages using the Int value:
//@variable define the length of fastSMA and half it for slowSMA
int LengthInt = input.int (12, “base length”, 2)
float fastSMA = ta.sma (close, lenghtInt)
float slowSMA = ta.sma (close, lengthInt * 2)
We set up the period for fast SMA to 12 and the period for slow SMA to 24 using this piece of code. The strategy will now use two simple moving averages that use the closing prices of each bar and the parameters that we have defined for them.
Now, we must allow the strategy to make trades when the fastSMA crosses over the slow one. It can be done using this simple condition:
if ta.crossover (fastSMA, slowSMA)
strategy.entry (“long”, strategy.long)
Here, we specify that when fastSMA crosses over slowSMA, the strategy opens a long position by purchasing assets at 100% margin.
To visualize the strategy and deployed indicators, you need to use the plot function:
//draw SMA
plot (fastSMA, “Fast Moving Average”, color.red)
plot (slowSMA, “Slow Moving Average”, color.orange)
Here, we tell the system to plot the lines on the chart in specified colors and put tags on them to easier distinguish them from other graphical elements.
In the end, you must have a simple code that looks like this:
//@version=6
strategy (“my sma strategy”, overlay = true, margin_long = 100, margin_short = 100)
//@variable define the length of fastSMA and half it for slowSMA
int LengthInt = input.int (12, “base length”, 2)
float fastSMA = ta.sma (close, lenghtInt)
float slowSMA = ta.sma (close, lengthInt * 2)
if ta.crossover (fastSMA, slowSMA)
strategy.entry (“long”, strategy.long)
//draw SMA
plot (fastSMA, “Fast Moving Average”, color.red)
plot (slowSMA, “Slow Moving Average”, color.orange)
Note that this strategy is not used in the real market. It can be deployed for paper trading on partnered centralized exchanges and brokerage service providers. However, the main purpose of strategy scripts on TradingView is to test various approaches to identify their effectiveness using the history of price action in certain markets.
You can also utilize the alert system by using the same code but with different declarations:
//@version=6
indicator (“crossover SMA”)
//@variable define the length of fastSMA and half it for slowSMA
int LengthInt = input.int (12, “base length”, 2)
float fastSMA = ta.sma (close, lenghtInt)
float slowSMA = ta.sma (close, lengthInt * 2)
if ta.crossover (fastSMA, slowSMA)
alert (“buy now”)
if ta.crossunder (fastSMA, slowSMA)
alert (“sell now”)
//draw SMA
plot (fastSMA, “Fast Moving Average”, color.red)
plot (slowSMA, “Slow Moving Average”, color.orange)
The code is nearly the same but it is now used to generate alerts for when SMAs cross over and under. Alerts can be used as signals by third-party providers. For example, you can set up a WunderTrading robot that will use webhooks to get alerts from the TradingView platform and execute its algorithm in the real market.
WunderTrading trading bot tutorial
This automation provider offers a wide range of highly specialized instruments. To get started, you will need to do the following:
- Go to the official website of the provider at wundertrading.com.
- Sign up using any of the methods suggested by the system.
- Log in and connect your centralized exchange account when prompted by the system.
- Go to the Signal Bot section in the Dashboard and click “Create Signal Bot”.
- In the Settings menu of the Signal Bot, find and copy comments for “strategy.entry”, “strategy.exit”, etc.)
In the Pine Editor, open your alert script and replace the alert message (“buy now” and “sell now” in the example above) with the {{strategy.order.comment}} line to create a connection between your script and your WunderTrading robot. A detailed guide on how to set up an ATS using alerts from TradingView is provided in a comprehensive YouTube video published by the developers of the platform.
A quick guide to trading bots at WunderTrading
This automation provider is one of the most flexible vendors out there with a wide range of features that help thousands of traders automate their investment activities. While it is fun to write your own scripts and create custom solutions, it is more practical and efficient to use various tools readily available to all WunderTrading’s clients:
● Powerful ready-made strategies. If you want to use some of the best products in the automation industry, it is a good idea to work with time-tested solutions like DCA and grid trading robots that you can launch in a couple of clicks. WunderTrading allows its users to customize all ATS designs to their liking and the level of adjustability in their grid and DCA systems is quite impressive. You will be able to set up delayed orders, position sizes, quantization of orders, and more.
● Informative analytical tools. Being able to manage assets effectively is a huge advantage for any crypto investor. The dashboard is full of excellent tools to monitor the performance of deployed bots and search for various ways to improve portfolio composition. You can track positions, explore performance metrics in “My Analytics”, receive insights from the Pump Screener, and use all sorts of other sets of data.
● The AI-assisted statistical arbitrage bot is the next-gen premiere product from WunderTrading. The robot analyzes the historical price action data and identifies patterns to use as the foundation for future decisions. You don’t need to create your own trading bot and adjust parameters thousands of times to achieve success. This AI-enhanced tool can make the whole investment process that much easier.
● The copy-trading section is designed to provide newcomers with an easy entry to the crypto market. The platform supports 14 centralized exchanges and gives you access to hundreds of vetted lead traders from each of the CEXes. It is a great way for beginners to get started even if they do not have any experience with digital assets and financial markets.
Creating a unique Pine Script system can be challenging for people without any experience with coding and software development. While the language itself is not difficult even for newcomers, it is still a coding language that uses rules, terms, and syntax that must be learned quickly. At the same time, the final result may not be worth the hassle.
It is a much better idea to simply use some of the effective ready-made solutions from industry-leading providers like WunderTrading.
How to create a trading bot easily
Learning a whole new language just to make strategies that help you better test technical analysis forecasting systems does sound like a waste of time if you do not have any foundational knowledge in computer science or software development. However, you can learn some bits of Pine Code here and there to read scripts easily and make adjustments to open-source solutions created by power users of the TradingView platform.
Go to the “Trading Ideas” section in the Community menu and browse through hundreds of indicators, trading plans, strategies, and alert systems created by experienced users who are trying to build effective tools and make them available to the public.
You can take any open-source code and adjust it as you see fit using surface-level Pine Script knowledge. However, it is still necessary to have a third-party provider that can turn an alert from your TradingView strategy into actionable triggers for automated trading systems.
To find tools that can be used without any limitations, go to the “Indicators and Strategies” section of the Community Menu and click “Open-source only” (the sign will turn bold) to make sure that only publicly available scripts are displayed. Any of these Pine Script applications can be copied and pasted to be adjusted for personal use.
Crypto trading bot setup for beginners
We strongly suggest avoiding methods that you do not fully understand. Learning Python to build your own API-compatible robots or mastering Pine Script to use the TradingView platform more efficiently are both good ideas and can be excellent “investments” in your future. However, making money right here and right now is possible only with reliable tooling and confident asset management.
Use staples like DCA trading robots from WunderTrading or copy-trading sections on various CEXes to create functional strategies that do not require additional tinkering, coding, and editing. It is important to get into action as soon as possible while learning more about the market instead of learning the theory that you may never need to use.
This guide is written with an educational purpose in mind. The basic script explained here to make a test strategy or to produce alerts is not hard to write. However, without some firm knowledge of Pine Script and Editor, you will struggle to approach even the simplest of trading systems like using RSI to look for reversals or utilizing Bollinger Bands to seek new trends.
If this guide looks difficult to understand and follow, it is a good idea to either start learning Pine Script or shift focus to automation instruments that are convenient, effective, and affordable