Lua programming, trading robots and scripts for trading

Программирование

Using the Lua programming language, you can create various games, utilities,
trading robots and other developments. The Lua language is easy to understand, has a popularized interpreter. It is proposed to get acquainted with Lua closer, as well as learn how to write a trading robot or script in this language.

What is the Lua language and how is it useful?

Lua is an easy to use embeddable language. Beginners admit that with its help, you can learn the basics of programming in a short time. Lua is successfully combined with developments that were compiled in another language. It is often recommended to students who are just starting out in the science of electronic design.
Lua programming, trading robots and scripts for tradingThe Lua language is often used in various fields. It may come in handy:

  1. A user who plays computer games (write plugins).
  2. Game development specialist (develop the engine).
  3. Application development programmer (write plugins for various utilities).
  4. Developer in the direction of embedded (the language does not slow down the process and allows you to work efficiently)
  5. Traders for writing scripts and trading bots.
    Lua programming, trading robots and scripts for trading
    Trading robot for QUIK on Lua by rebuy levels

Thanks to Lua, more than one trading robot has been created. The advantage is that each user can quickly understand the nuances of the language and independently create such a program. Through it, it will be possible to send commands to
the Quik terminal and carry out technical analysis. What is the Lua language for, an overview of the LUA programming language: https://youtu.be/PbYf6uNZFCE

Short historical data

Lua was invented in 1993 by Brazilian programmers from the Tecgraf division. The developers made sure that each user could make certain amendments to the development of the language. This can be done through open access to the code. For Brazil, the emergence of its own programming language was a real discovery. Indeed, before that, this country did not achieve such success in the field of computer development.
Lua programming, trading robots and scripts for tradingThe language was created on the basis of SOL and DEL. These developments saw the world a year earlier than Lua. The same Brazilian organization acted as the author. These programming languages ​​were commissioned by Petrobras, a company of the same state engaged in the extraction and processing of oil. The latest version of Lua 5.4.0 was released relatively recently – in 2020. Developers try to introduce interesting and useful features into the project as often as possible. Therefore, the program is constantly updated and is in demand among developers.

Features of the Lua programming language

Faced with Lua, the developer is given the opportunity to use this language, both built-in (due to the fact that it is scripted) and standalone (in certain cases, it can be used without add-ons). When the authors worked on the creation of Lua, they deliberately went to make an operational tool that does not take up much space and will easily function on any device.
Lua programming, trading robots and scripts for tradingThe developers tried to simplify this language as much as possible, so that even novice programmers could quickly master it. This is the increased demand for the project. Specialists have the opportunity to write code and create large-scale developments without resorting to libraries on the official website. The authors took care of the availability of the necessary parameters in the program itself. Novice users tend to learn in what areas the Lua language is used. It was designed for the production of programs in the industrial sector. But today, with the help of this language, various trading robots, scripts, computer games, applications, bots for Telegram and so on are created. In addition, Lua is involved in an innovative technique that helps to explore space. It is also used in teaching students at universities. The most popular programming language Lua is considered at home. It is in Brazil that it is used almost everywhere (where possible).

Advantages and disadvantages

Lua programming, trading robots and scripts for tradingLike any program, the mechanism and programming language of Lua has a number of its pros and cons. It is worth starting with the positive aspects of development:

  1. Quality transportation . Unlike many programs, Lua is easy to transfer from one operating system to another. In this case, there are no major changes. In any case, there will be no errors in the code.
  2. Lots of libraries . Compared to JavaScript , Lua has much fewer library options. However, the official resource has everything you need to fully work with the language.
  3. Efficiency . The system allows you to add those libraries that are important for a particular coding process in a short time.
  4. Ease of use . Programming gurus only need to learn a few details of the language, and even then they can safely use it in their developments. For those just starting out with programming, it doesn’t take long to understand Lua either.
  5. Substantial memory savings . By creating programs in this language, a specialist is guaranteed to notice the difference with other analogues. After all, Lua developments need less memory on the device.

The only significant disadvantage of the language is that it is scripted. And this means that often it can only be used in combination with other development languages. The most popular of these is C. That is, you will have to learn an additional programming language.

Comparison with Javascript

Many users compare Lua to JavaScript, claiming that their codes are almost the same. There are indeed more similarities between languages ​​than differences. But, despite the obvious similarities, there are many differences. For example, Lua has its own software support. However, JavaScript developers have recently introduced an update, according to which, it is enough for the user to write the word “yield” between the generators, after which the program will be supported.
Lua programming, trading robots and scripts for tradingThe Lua operator for raising to a power denotes such a sign “^”, while in JavaScript it is “**”. The latter has zoom in and zoom out functions. But Lua can perform operator overloading. JavaScript contains only variable functions, while Lua has them defined. JavaScript can boast of supporting the well-known Unicode standard. The combination “!==” is used to indicate inequality in the language, and Lua uses “~=” for the same purpose. Other differences are presented in the table.
Lua programming, trading robots and scripts for trading

Features of programming robots for trading in the Lua language

Creating robots on QLua is not at all difficult, even beginners can handle it. The main thing is to understand the basic theory at the very beginning. In order to compose the code, the simplest text editor is useful. The scheme of creation is similar to the compilation of an indicator. However, there is an insignificant difference in the code itself. Another good “highlight” – the newly minted robot can be placed anywhere on your PC.

Important! There should be only one function in the code – “main”.

Once the robot code is compiled and edited, it is recommended to save it. Don’t forget about the lua extension. As already mentioned, the program can be placed anywhere on the computer. To test your code, you need to run the robot. To do this, go to the “Services” section. At the bottom there will be a line “Lua scripts”, it should be clicked.
Lua programming, trading robots and scripts for tradingNext, a window with loaded scripts will appear. There you should select the required file and run it using the appropriate button.
Lua programming, trading robots and scripts for tradingAt the end, it is recommended to check the bot code for errors. If all is well, the robot will start. In case of hitches, it is worth returning to the code again and checking its correctness.

Overview of the best trading robots on Lua – ready-made solutions for beginners

Using the Lua programming language, you can create various types of robots of any complexity. However, you can purchase a ready-made program. It is proposed to get acquainted with the well-known algorithms that are already ready for work. You can buy them or try out the demo version. Complete trading robot for the QUIK terminal in Lua: https://youtu.be/Z2xzOfNZFso

Robot-terminal “Delta Pro”

Allows you to activate about 120 any options on one platform. In this case, you can use different types of strategies and tools.
Lua programming, trading robots and scripts for trading

RQ: One Percent

The robot is designed for trading in the field of trading. The algorithm allows you to increase the income from this activity several times. Risks are minimized, they can be easily calculated.
Lua programming, trading robots and scripts for trading

RQ: Martin

The system allows you to calculate the lot before making a deal. Trading in the “semi-automatic” mode is provided. Levels can be successfully tracked and set manually.
Lua programming, trading robots and scripts for trading

Types of Lua scripts for the QUIK terminal

When performing a certain task in the QUIK terminal, the following scripts are used:

  1. Lua scripts . They can be stored on the network, on a local disk, or in another place where they will be accessible to the terminal. They are functional enough to create a trading robot with their help. It will be possible to create tables in QUIK, use tool options, give commands to perform various tasks, and so on.
  2. Custom indicators . Here, compared with the previous view, much less functionality. The program is intended for the user to display the algorithm of actions on the terminal charts.

Programming in Lua for those who want to master the language thoroughly – download the complete guide:
Programming in Lua Robots in Lua for QUIK – Iceberg robot: https://youtu.be/cxXwF_xmTHY

How to write a robot in Lua

Having decided to create his own robot, the user must follow a pre-compiled algorithm. When he gains experience in programming, he will be able to easily write his own codes and experiment. By choosing Lua to study this area, a beginner will not be mistaken. After all, in the beginning, the main thing is to stop at a simple and most understandable programming language. To get started, open the QUIK trading terminal program. In its window, you need to create a folder. This is the place where all written scripts will be saved. The user can give the folder absolutely any name, but it must consist only of Latin characters. Let’s say its name is “LuaScripts”. Next, you need to activate the folder and create a text editor there, for example, Notepad. In an empty space (within the program window) you need to right-click
. A dialog box will appear, in the list of which you need to select the “Create” tab, and then the “Text Document” row.
Lua programming, trading robots and scripts for tradingIt should also be given a name, so as not to be confused later. For example, you can write “Script_N1”. Do not forget about the resolution of the language used – .lua. That is, the user should get such an inscription on the document “Script_N1.lua”. However, Windows often changes the extension automatically by putting in a .txt file. In this case, it is recommended to create a document in NotePad++, setting the desired resolution. In this program, you will need to select the “Syntaxes” section. A dialog box with several options will appear here. You will need to select “L”. From there, another window will appear where you need to click on “Lua”.
Lua programming, trading robots and scripts for tradingAfter that, in the same menu, along with the “Syntaxes” section, you should click on the “File” section. In the next window there will be an inscription – “Save as”. The user needs to click on it and wait until a new window opens.
Lua programming, trading robots and scripts for tradingThere, at the top, a line with the name of the previously created folder “Lua scripts” will be visible. At the bottom of the window, 2 other documents that the user has created are displayed. If everything matches, you must confirm the action and save the current state of the code.
Lua programming, trading robots and scripts for tradingThe next step is to write the code in the chosen Lua programming language. Beginners can use the instruction, it will help to create a simple code, so that the specialist can try his hand. The algorithm of actions is located in the program file called QLUA.chm. It is proposed, for example, to write such a lightweight code:
function main()
message(“My first script has been launched”);
end Next, you need to click on the save button in the menu.
Lua programming, trading robots and scripts for tradingThe code should be saved in the file “Script_N1.lua”. We launch it and see how the debut script is displayed. To open it in QUIK, you need to open this program and select the “Services” tab in the options section. Next, a dialog box will appear, there you should click on “LUA scripts …”.
Lua programming, trading robots and scripts for tradingThen the user will see the folder “Available scripts”. On the top right side is the Add button. Click it and look for the file with the code. It is located here “Script_N1.lua”.
Lua programming, trading robots and scripts for tradingWhen opening a document, it is important to select the line “Script_N1.lua” (it must be saved on drive C), then, at the bottom, click on the “Run” button.
Lua programming, trading robots and scripts for tradingA new window will immediately appear.
Lua programming, trading robots and scripts for tradingTo avoid these incomprehensible characters, you need to go to the NotePad program. In the settings there is a section “Encodings”, click on it. Then a list of tabs will appear, among which you should click on “Convert to ANSI”.
Lua programming, trading robots and scripts for tradingNext, you should click on the save button and return to the message window. There will already be another inscription, and not a row with scribbles.
Lua programming, trading robots and scripts for trading

How to program in LUA in QUIK terminal

There are 3 popular ways:

  1. Any text file is created, where the .lua extension should be put. Next, you need to open the editor and write the code. After starting, such an algorithm will be executed only once. You can run it manually indefinitely. You can use it for a one-time calculation of certain information.
  2. In the Lua script itself, you need to create a function called  main() . Further, in the same function, you need to insert the written code. And the sleep() function is  useful to temporarily pause the script or, conversely, resume it. That is, if you activate the main () function, and then insert the sleep () function, you will be able to achieve calculation with a frequency of a specific time interval.
  3. In a QLUA program, you can use the event-driven development model. Thus, now it is not necessary to “detect” changes in one function and, due to this, execute the following commands.

It is proposed to analyze the latter method in more detail. To handle a specific event, you should write a function in a script in Quick. You can use the following scheme: A
Lua programming, trading robots and scripts for tradingLUA script can consist of several functions with special names: deal, quotes, and so on. You need to find the “Tables” section in the program, go to “Lua”. A dialog box will appear there and the line “Available scripts” will be visible, click on it. Next, click on the “Launch” tab. Then comes the processing and execution of the obligatory
main() function . Then, you need to declare 
is_run , the function will contain the value 
trueuntil the user activates the Stop Script button. Then the function variable goes into false mode inside OnStop(). After that, the main() function ends, and the script itself stops. The written script must be saved and run. When making transactions, the user will see the data for each lot and the final amount of transactions.
Lua programming, trading robots and scripts for tradingTo run QLua in Quick, you need to transfer it to a new folder on your PC. You can call it whatever you like, for example, “MyLua”. All Lua scripts will be stored there. Having entered QUIK, you need to open the “Services” section, then click on the “Lua scripts” tab. In the window that opens, activate the “Add” button. Then you need to select the script and open it. It will be in the “Downloaded Scripts” section. Then you should highlight the line of the script and click “Run”. To stop the script, just click “Stop”.

Lua programming, trading robots and scripts for trading
Bot for Quik on LUA

How to install a LUA script in a trading terminal

The training and standard terminals require the same algorithm for installing a trading robot:

  1. It is necessary to click on the “Services” section in the top menu of the terminal.
  2. Next, find the “LUA scripts” button in the drop-down dialog box and click:Lua programming, trading robots and scripts for trading
  3. At that time, the “Available Scripts” window should appear. Then, you should activate the “Add” button and select the file of the required trading robot.

Taking data from the Lua chart with a script in the Quik terminal: https://youtu.be/XVCZAnWoA8E Lua is a great option for learning programming and for success in the future. The main thing is not to stop only at reading the theory. It is better to learn the material by constantly practicing. After a certain time, the developer will begin to make progress and be able to create his own worthwhile product.

Поделиться ссылкой:

Rate this post
Rate author
Programming, investment and algorithmic trading
Add a comment