Sunday, January 28, 2024

What does a trading robot consist of?

In this lesson, we will look at the bones of the trading robot. We promise you that after this lesson your fear of coding in MQL5 will start to disappear!
At first, let’s have a look at the structure of a robot in the Meta Editor.



Looks scary, right? However, in reality, all trading robots have the same core elements you need to know about.


There are four main parts of a trading robot:

  •     Setup
  •     OnIntIt
  •     OnDeinit
  •     OnTick


Let’s have a closer look at each element.
 

Setup

This is the part of a robot where all the administrative information is placed. Here, you write notes, declare variables (different types of information with a unique name), track the list of changes, and set the property rights.





On the screenshot above, you can see a sample of the Setup code. It consists of copyright, the main properties of a robot, and the #include command that inserts the content of a certain file to your expert advisor. Also, in this section, we declare the main inputs under the #input command.
 

OnInIt

The second part is called OnInit (OnInitiation). This part launches when you start the EA for the first time.



In this part, you can see the commands that will be executed after the first launch of the program. We will explain these commands in the next articles!
 

OnDeInIt

The next section of the expert advisor is called OnDeinitiation, or shortly OnDeInIt. It runs when the expert advisor is shut down.
 

OnTick

This is the most interesting part of an expert advisor. It consists of three main parts that are updated on every tick (with the new information about a price). They are entries, exits, and sizing. These functions are important for any expert advisor, because they tell you when to buy, how much to sell, and when to close your trades.

This code will start every time a new tick arrives on your MetaTrader 5 platform. That is, if the bid, ask prices, or volume changes, this change affects the OnTick section of your code as well.

 


On the screenshot above, you can see that the robot checks the last trade processing time and other data.
 

So, if you were a computer, how would you read the code structure?

First of all, you would go to the OnInit section and run everything in it. You’d set up variables and parameters that you need for your strategy. This action is executed only once.

After this action is completed, you go to the OnTick section. At first, you check if you have any trades that need to be exited. After that, you look for trades that can be entered. Finally, a sizing algorithm will help you to identify the size of your position.

Once you shut down your EA, you run OnDeInIt. This option removes the graphics from the charts and deletes everything linked to the expert advisor itself.


Bottom line

To sum up, if you want to build a trading robot, you need to know its structure thoroughly. Luckily, all of the robots have a similar structure that allows you to construct it step-by-step.


Credit link:

https://fbs.com/th/analytics/guidebooks/building-a-trading-robot-without-programming-350

What is a robot in Forex?

Forex robots are programs, code written according to a specific trading strategy. It uses technical signals to enter trades while traders are fast asleep. This program can help traders automate market operations or trades.


Is it automatic trading? Like.. you don't have to do anything?

Actually, you can use robots in both partially and fully automated trading. Both options have their advantages. Smart robots analyze market patterns and possible reversals, read signals and indicators - some traders choose to place the entire trading process on the shoulders of computer code with the settings according to need However, some traders still prefer to participate in some trading procedures. and trust robots only for the market operations part Although robots are intelligent But it's still just program code. Some traders want to keep it under control.

Okay, so what are the advantages of using robots?

The obvious advantage of using Forex robots is the "free" time you get as a trader. The robot analyzes the market and opens trade orders 24 hours a day. The robot processes signals to open or close orders in an incredibly short time that cannot even be completed by any professional. It's important that many good robots have risk management built into their code from the beginning. Therefore, when you trade with robots, you are protected from losing your deposit due to emotions. The greatest advantage of robots is that they relieve mental stress: traders do not have to monitor all the charts. But robots will do this job instead.

So.. robots are always right? So what are its disadvantages?

Robots work according to set rules. In terms of what settings it is written in and what indicators it uses. It's always right. However, they cannot adapt to the rapidly changing situation in the market by themselves. Robots are smart, but they're just programs that need to be reset and updated from time to time. Therefore, whenever the market changes beyond the robot's default settings, Traders need to modify the program and sometimes rewrite or modify the default code. The fact that the robot must be updated in accordance with the market situation may turn out to be a serious disadvantage for some.

It looks like robots are useful. But it's so different!

This is true. Trading robots are no different from other software. It may be sold with different configurations. Make sure that when you buy the robot you get a manual or other instructions for installation - otherwise it's nothing but a bunch of code. The more robots come with their own manual and settings, the better - that means you can take a peek inside. And there is an opportunity to set it according to your needs. Moreover, if you intend to go one step further, you may write the robot yourself: it will be fully customized and most probably will suit your trading goals as perfectly as possible.


Got it, so how do I choose a good robot?

To choose the right trading robot First you need to decide on a working strategy and memorize it in your mind. Don't let yourself be fooled by the quick huge profit percentages - this can be the result of the aggressive settings of the robots. And in the future it may make your funds unsafe. Follow your trusted trading strategy. Otherwise, the robot can easily disappoint you. There is a lot of advice out there on how to choose the “right robot” but remember – the only way to see if a robot is working properly is to test it.


Is there anything else you would like to recommend?

Remember, robots aren't magic tricks that will make you rich in an instant. The default settings of most robots are too simple to set up and lack precision in operation until you have customized them with the signals you want for your purposes. In order to be able to do that It is better if you have enough trading experience to teach the robot to trade for you.


Featured Posts

Two Ways to Win in Trading

Two approaches to trading Forex trading is complex and challenging. Numerous and various market participants constantly contemplate how to ...