How to write a trading robot: tools for beginners





The topic of automated systems for trading on the exchange is quite popular in RuNet in the past few years. However, it can be difficult for novice investors to create their own trading robot. Today we will talk about how this can be done without unnecessary costs.



Note : any investment activity on the exchange is associated with a certain risk, this must be taken into account. In addition, to launch your trading robot you will need a brokerage account, you can open it online . You can debug your strategy using test access with virtual money .



Options for creating robots



There are several options for creating robotic software for trading on the exchange:





Today we will consider the third option, since it is the simplest.



How it worked before



Trading terminals of previous generations could be integrated with various automation tools. Strange as it may seem, Excel was one of the most popular. With it, traders could configure the export of data from the trading terminal, as well as receive trading orders.







Menu for connecting Excel in one of the previous generation trading terminals



It was also common practice among traders to connect powerful technical analysis and robot development systems like WealthLab and MetaStock to their terminals. In such cases, integration is usually done using additional libraries.



In these cases, the trader got the opportunity to automate, and, in the case of MetaStock and WealthLab, the creation of rather complex trading systems, but links to external programs were often unreliable. Over time, this problem was solved - in some trading terminals built-in programming languages ​​appeared.



How it works now: learning TradeScript



Nowadays, on the Russian market, the easiest way to create a simple trading robot working with a broker system is to use the SMARTx terminal.



It has a special plugin with the TradeScript trading robot designer. Using a simple, but quite powerful scripting language, traders can create mechanical systems of various levels of complexity. The language was originally created for the development of trading robots, it is quite easy to learn, and many algorithms are similar in writing to Metastock, which makes it easier for users familiar with this software package.







The advantage of TradeScript compared to Wealth-Lab and the same Metastock is the absence of the need to create complex designs and use various connectors to transfer orders to the trading terminal. The robot designer is built into SMARTx, which allows to achieve significantly higher reliability and speed.



Here is an example of a trading strategy written in TradeScript:



Buy Signals # ,        TREND(EMA(CLOSE, 20), 15) = UP AND TREND(MACD(13, 26, 9, SIMPLE), 5) = UP Sell Signals # ,        TREND(EMA(CLOSE, 20), 15) = DOWN AND TREND(MACD(13, 26, 9, SIMPLE), 5) = DOWN Exit Long Signal # ,         TREND(EMA(CLOSE, 20), 15) = DOWN OR TREND(MACD(13, 26, 9, SIMPLE), 5) = DOWN Exit Short Signal # ,         TREND(EMA(CLOSE, 20), 15) = UP OR TREND(MACD(13, 26, 9, SIMPLE), 5) = UP
      
      





In a package with TradeScript, it also supplies a backtesting module that allows you to evaluate the productivity of the described strategy on historical data. Among other things, the system implements the function of testing the trading system “on the fly” using current exchange data, but without placing an order on the exchange — the time of the virtual transaction, the price and the resulting “profitability” will be displayed in a separate window.







In addition, the user can run as many simultaneously running algorithms as the processor clock speed and computer memory allow. Given the large number of words and operands of the scripting language, this means the ability to create arbitrarily complex trading strategies.



What else: debugging on test access



Using the built-in functionality for developing trading robots in the trading terminal is a convenient and reliable way to automate trading. However, despite the existing functions for testing strategies, you should not neglect the additional debugging capabilities.



Therefore, we recommend that before launching a strategy for trading real money, “run” it on test access . This step will allow you to debug all the moments, including the reaction of the program to the executed transactions, without the risk of real financial losses. The use of analysis using historical data, on-the-fly verification and the use of test access will allow you to fully debug your strategy.



Useful links on the topic of investment and stock trading:






All Articles