Discussing the article: "Creating a market making algorithm in MQL5"

 

Check out the new article: Creating a market making algorithm in MQL5.

How do market makers work? Let's consider this issue and create a primitive market-making algorithm.

Many people think that a market maker does not bear any risks at all. However, this is not the case. The main risk of a market maker is inventory risk. This risk lies in the fact that a position can sharply move in one direction without the ability to off-load it and make money on the spread. For example, when a frenzied crowd sells an asset, the market maker is forced to buy out the entire supply. As a result, the price goes into the negative driving MM into losses. 

Companies try to avoid this risk by using special spread centering equations and determining the optimal price for buying and selling. But this is not always achievable. Even if the price is not optimal, MM's job is to supply liquidity to the market, and they must do this job, even if they are temporarily operating at a loss.

Author: Yevgeniy Koshtenko

 

Thank you, Eugene, for the article! Many gaps in the puzzle of my knowledge about the currency market are almost completely filled.

There is one single nuance: some readers of your article may not start the Expert Advisor in the strategy tester if the currency pair being tested has a suffix or prefix. They should take this into account and specify it in the settings of the Expert Advisor parameters.

But so - everything is SUPER!!!

Regards, Vladimir.

 
MrBrooklin #:

Thank you, Eugene, for the article! Many gaps in the puzzle of my knowledge of the currency market have been almost completely filled in.

There is one single nuance: some readers of your article may not start the Expert Advisor in the strategy tester if the currency pair being tested has a suffix or prefix. They should take this into account and specify it in the settings of the Expert Advisor parameters.

Otherwise - everything is SUPER!!!

Regards, Vladimir.

Thank you very much! I will check tomorrow with prefixes at another broker. If anything, I will make an addition).

 

Eugene, yesterday I did not look closely at the code of the Expert Advisor, as I was more interested in the text part of the article, so I did not ask a question about the part of the code highlighted in yellow:

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int CountOrders(string symb,ENUM_ORDER_TYPE type)
  {
   int count=0;

   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(OrderGetTicket(i)))
        {
         if(OrderGetInteger(ORDER_TYPE)==type && PositionGetString(POSITION_SYMBOL)==symb && PositionGetInteger(POSITION_MAGIC)==Magic)
            count++;
        }
     }
   return(count);
  }

I paid attention to your warning right away: Here are the functions for counting open orders and open positions. CountOrders and CountTrades deal with counting open orders and positions for a certain symbol taking into account the magic EA number. They are not actually used in the code yet, but they will be used in future versions, when I finally write a normal function for centring the spread between limits....

But I don't quite understand - was it your idea or should it be different?

Regards, Vladimir.

 
MrBrooklin open positions. CountOrders and CountTrades deal with counting open orders and positions for a certain symbol taking into account the magic EA number. They are not actually used in the code yet, but they will be used in future versions, when I finally write a normal function for centring the spread between limits....

But I don't quite understand - was it your idea or should it be different?

Regards, Vladimir.

It was intended - otherwise the Expert Advisor can start to confuse orders of its magician with others) Symb is intended to make a multicurrency version of the Expert Advisor in the future. I have not managed to make it yet)))))

 
Yevgeniy Koshtenko #:

It is intended - because otherwise the EA can start to confuse orders of its magician with others) By symb it is intended to make a multicurrency version of the EA in the future. I have not managed to make it yet)))))

Everything is clear with orders, but why are symbol and magik positions checked in this function? ))

Regards, Vladimir.

 

This is a disgrace to MQ, not an article. How can such a thing be allowed to be published?

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int CountTrades(string symb)
  {
   int count=0;

   for(int i=PositionsTotal()-1; i>=0; i--)
     {
      if(PositionSelectByTicket(PositionGetTicket(i)))
        {
         if(PositionGetString(POSITION_SYMBOL)==symb && PositionGetInteger(POSITION_MAGIC)==Magic)
           {
            count++;
           }
        }
     }
   return(count);
  }

PositionGetTicket(i) according to the documentation "Thefunction returns a ticket of a position by index in the list of open positions and automatically selects this position for further work with it...". And why select a position by its ticket using the PositionSelectByTicket function if it is already selected? Are you teaching newcomers how not to do it?

Vladimir's remark is quite fair. And your answer is not about that at all... Why check the symbol and the POSITION magik if we work with orders????

 

Apart from the code, I didn't like the text part either.

It's rubbish, it's nothing more than a piece of paper.

It's an interesting topic, no argument.

What kind of market-making are we creating, what's the point?

The fact that it was not possible to create it is a fact, because the author lacked matrix.

and there's a lot of it out there.

It's necessary to think about it for at least another ...ten years, maybe we'll manage to make it.

as a start and as a way to improve - ok, in this I support.

 

Renat Akhtyamov #:

What kind of market-making are we creating, what's the point?

The fact that it was not possible to create it is a fact, as the author lacked the necessary matrix

You should read thearticle not diagonally, but from the beginning to the end, i.e. completely, then such questions will not arise.

Icompletely agree with Alexey Viktorov's criticism about using thePositionSelectByTicket() functionwhen a ticket has already been selected without it. By the way, I didn't pay attention to it myself.

But thanks for the article anyway!

Regards, Vladimir.

 
MrBrooklin #:

Thearticle should not be read diagonally, but from beginning to end, i.e. completely, then such questions will not arise.

I completely agree with Alexey Viktorov's criticism about using the PositionSelectByTicket () function when a ticket has already been selected without it. By the way, I did not pay attention to it myself.

But thanks for the article anyway!

Regards, Vladimir.

Not a ticket is selected, but a position is selected to work with its properties by means of corresponding functions.

 
Alexey Viktorov #:

Not a ticket is selected, but a position is selected to work with its properties through the appropriate functions.

Hi Alexei, thanks for the clarification. )) When I wrote my message, I relied on the same documentation (highlighted in yellow):

Функция возвращает тикет позиции по индексу в списке открытых позиций и автоматически выбирает эту позицию для дальнейшей работы с ней 
при помощи функций PositionGetDouble, PositionGetInteger, PositionGetString.

ulong  PositionGetTicket(
   int  index      // номер в списке позиций
   );

Параметры

index

[in]  Индекс позиции в списке открытых позиций, начиная с 0.

Возвращаемое значение

Тикет позиции. В случае неудачного выполнения возвращает 0.

Regards, Vladimir.

Reason: