A sub-workshop to fill in the FAQ (frequently asked questions). Let's help comrades! - page 13

 
What is the difference between Instant Executuion and Market Execution?

(Integer ): With Instant Executuion, an order can be opened with a pre-set stop-loss and take-profit, set the Slippage in pips, which allows opening an order when the price at the moment of its execution by the broker deviates from the trader's request price. At Market Execution it is not possible to open an order with a pre-determined Stop Loss and/or Take Profit, there is no parameter for the Slippage. The order is opened at any price available at the moment of its execution by the broker. A Stop Loss and/or Take Profit can be set immediately after the order is opened. Most dealing centres work in the Instant Execution mode. Not so many dealing centres operate in the Market Execution mode.
 
More and more brokerage companies are switching to Market Execution. Soon the information given by Integer will become irrelevant.
 
joo:
More and more brokerage companies are switching to Market Execution. Soon the information given by Integer will become irrelevant.

it's just information about the two modes.

and that's exactly what the last paragraph of the FAQ says - a trend! https://www.mql5.com/ru/forum/131853/page3#464977

-------

By the way, how is the glossary of terms, is the patient rather alive?

Files:
mql4_10.zip  419 kb
 
sergeev:

1. and the last paragraph in the FAQ says exactly that - trend! https://www.mql5.com/ru/forum/131853/page3#464977

-------

2. By the way, how is the glossary of terms, is the patient rather alive?

1. Didn't see the last paragraph in the FAQ on the link and only reacted to granit77's post.

2. I have read the section on which I offered my own help. But it is as complete as one could wish for. There is practically nothing to add. I should have reported it earlier - I regret not having done so.

Still, the section can add jargon abbreviations of terms that are in use by programmers and traders. I have just started a new job and I have very little free time now, barely enough to at least continue my own project. Therefore, I will gradually write down "on a piece of paper" and when I accumulate more of it, I will add it to the section. OK?

 
joo:

ok
 

Question: Getting an array of "own" orders

Answer: From the point of view of code optimization, this is the convenient approach: first, we conduct "revision" of "friendly" (that is orders with the given MagicNumber()) orders, create an array of tickets with full information concerning each ticket, and then we conduct all other checks (for closing and modifying positions) with the same array of tickets.
Example #1. Gathering information about tickets on one currency pair.
// Сначала объявляем массив в глобальных переменных
double gda_Tickets[30][10]; // массив для хранения информации о "своих" ордерах:
       // gda_Tickets[][0] - Ticket
       // gda_Tickets[][1] - Type
       // gda_Tickets[][2] - Lots
       // gda_Tickets[][3] - Open Price
       // gda_Tickets[][4] - OrderProfit
       // gda_Tickets[][5] - Stop Loss
       // gda_Tickets[][6] - Take Profit
       // gda_Tickets[][7] - Open Time
       // gda_Tickets[][8] - MagicNumber
       // gda_Tickets[][9] - Expiration Time
// Не забываем о счётчике ордеров (он нам ещё понадобится)
int   gi_cnt_Tickets;
// сама функция
void fMyTickets (double& ar_Tickets[][10], int fi_Magic = -1)
{
    int li_cnt = 0; // счетчик заполнения
    int li_total = OrdersTotal();
//----
    for (int li_int = li_total - 1; li_int >= 0; li_int--)
    {
        if (OrderSelect (li_int, SELECT_BY_POS))
        {
            //---- проверка на Symbol
            if (OrderSymbol() != Symbol()) 
            {continue;}
            //---- проверка MagicNumber
            if (OrderMagicNumber() != fi_Magic
            && fi_Magic >= 0) // предусматриваем возможность контролтровать любой Magic
            {continue;}
            //---- заполняем массив
            ar_Tickets[li_cnt][0] = OrderTicket();
            ar_Tickets[li_cnt][1] = OrderType();
            ar_Tickets[li_cnt][2] = OrderLots();
            ar_Tickets[li_cnt][3] = OrderOpenPrice();
            ar_Tickets[li_cnt][4] = OrderProfit() + OrderSwap() + OrderCommission();
            ar_Tickets[li_cnt][5] = OrderStopLoss();
            ar_Tickets[li_cnt][6] = OrderTakeProfit();
            ar_Tickets[li_cnt][7] = OrderOpenTime();
            ar_Tickets[li_cnt][8] = OrderMagicNumber();
            ar_Tickets[li_cnt][9] = OrderExpiration();
            //---- увеличим счётчик заполненных тикетов
            li_cnt++;
        }
    }   
    gi_cnt_Tickets = li_cnt;
//----
    return;   
}

If you like, you can declare this function of int type and make it return the number of "own orders".

gi_cnt_Tickets = fMyTickets (gda_Tickets, Magic);

If our EA is multi-currency.
Example #2. Gathering ticket information for several currency pairs.

In order to check for "friendly" symbols in this case, we will need one more small function:

//IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+
//|  UNI:      Получаем номер элемента в массиве string                               |
//IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+
int fGetNumElementInArray_STR (string sArray[], string Element)
{
//----
    for (int l_int = 0; l_int < ArraySize (sArray); l_int++)
    {
        if (sArray[l_int] == Element)
        {return (l_int);}
    }
//---- 
    return (-1);
} 

and our function will have this form:

// В глобальных переменных объявляем ещё одина массив, теперь с символами с которыми работает наш мультивалютный советник
string gsa_Symbols[];
// Для использования его в советнике, нужно предварительно задать его размер и заполнить символами
// (как это сделать - отдельная тема)
// сама функция
int fMyTickets (string ar_Symbol[],        // заполненный массив рабочих символов
                 double& ar_Tickets[][11], // массив тикетов (для заполнения)
                 int fi_Magic = -1)        // MagicNumber
{
    int NUM_Symbol, li_cnt = 0; // счетчик заполнения
    int li_total = OrdersTotal();
    string ls_Sym;
//----
    for (int li_int = li_total - 1; li_int >= 0; li_int--)
    {
        if (OrderSelect (li_int, SELECT_BY_POS))
        {
            ls_Sym = OrderSymbol();
            //---- Определяем номер символа в массиве (фильтр по Symbol)
            NUM_Symbol = fGetNumElementInArray_STR (ar_Symbols, ls_Sym);
            //---- Если ордер не "свой" - пропускаем
            if (NUM_Symbol < 0)
            {continue;}
            //---- проверка MagicNumber
            if (OrderMagicNumber() != fi_Magic)
            {continue;}
            //---- заполняем массив
            ar_Tickets[li_cnt][0] = OrderTicket();
            ar_Tickets[li_cnt][1] = OrderType();
            ar_Tickets[li_cnt][2] = OrderLots();
            ar_Tickets[li_cnt][3] = OrderOpenPrice();
            ar_Tickets[li_cnt][4] = OrderProfit() + OrderSwap() + OrderCommission();
            ar_Tickets[li_cnt][5] = OrderStopLoss();
            ar_Tickets[li_cnt][6] = OrderTakeProfit();
            ar_Tickets[li_cnt][7] = OrderOpenTime();
            ar_Tickets[li_cnt][8] = OrderMagicNumber();
            ar_Tickets[li_cnt][9] = OrderExpiration();
            //---- для дальнейших вычислений не лишним будет запомнить номер индекса символа в массиве символов
            //---- но для этого не забудьте увеличить размер массива тикетов при его объявлении gda_Tickets[30][11]
            ar_Tickets[li_cnt][10] = NUM_Symbol;
            //---- увеличим счётчик заполненных тикетов
            li_cnt++;
        }
    }   
//----
    return (li_cnt);   
}
 

Question: Obtaining an array of "own" order tickets

Answer: (Continued)

No wonder if you want your EA to have additional statistics about its work, for example: the maximal drawdown, total profit, etc. So that you don't have to "disturb" the server with additional requests, we recommend you to add functionality to our function (excuse the pun). In this case the function may look like this

Variant 1 for a monocurrency EA:

// Объявляем массив в глобальных переменных
double gda_Tickets[30][10]; // массив для хранения информации о "своих" ордерах:
       // gda_Tickets[][0] - Ticket
       // gda_Tickets[][1] - Type
       // gda_Tickets[][2] - Lots
       // gda_Tickets[][3] - Open Price
       // gda_Tickets[][4] - Order Profit
       // gda_Tickets[][5] - Stop Loss
       // gda_Tickets[][6] - Take Profit
       // gda_Tickets[][7] - Open Time
       // gda_Tickets[][8] - MagicNumber
       // gda_Tickets[][9] - Expiration Time
// Добавляем массив для сбора ститистики
double gda_AddInfo[5]; // массив для хранения дополнительной информации по работе советника
       // gda_AddInfo[0] - количество соих ордеров (всех)
       // gda_AddInfo[1] - количество своих рыночных ордеров
       // gda_AddInfo[2] - общий размер открытых рыночных лотов
       // gda_AddInfo[3] - общий профит по открытым позициям
       // gda_AddInfo[4] - максимальная просадка по открытым позициям
void fMyTickets (double& ar_Tickets[][10], // массив тикетов (для заполнения)
                 double& ar_Info[],        // массив для заполнения дополнительной информацией
                 int fi_Magic = -1)        // MagicNumber
{
    int li_cnt = 0; // счетчик заполнения
    int li_total = OrdersTotal();
    double tmp_Loss;
//----
    tmp_Loss = ar_Info[4];
    //---- Обнуляем заполняемый массив перед использованием
    ArrayInitialize (ar_Info, 0.0);
    for (int li_int = li_total - 1; li_int >= 0; li_int--)
    {
        if (OrderSelect (li_int, SELECT_BY_POS))
        {
            //---- проверка на Symbol
            if (OrderSymbol() != Symbol()) 
            {continue;}
            //---- проверка MagicNumber
            if (OrderMagicNumber() != fi_Magic
            && fi_Magic >= 0) // предусматриваем возможность контролтровать любой Magic
            {continue;}
            //---- заполняем массив
            ar_Tickets[li_cnt][0] = OrderTicket();
            ar_Tickets[li_cnt][1] = OrderType();
            ar_Tickets[li_cnt][2] = OrderLots();
            ar_Tickets[li_cnt][3] = OrderOpenPrice();
            ar_Tickets[li_cnt][4] = OrderProfit() + OrderSwap() + OrderCommission();
            ar_Tickets[li_cnt][5] = OrderStopLoss();
            ar_Tickets[li_cnt][6] = OrderTakeProfit();
            ar_Tickets[li_cnt][7] = OrderOpenTime();
            ar_Tickets[li_cnt][8] = OrderMagicNumber();
            ar_Tickets[li_cnt][9] = OrderExpiration();
            //---- увеличим счётчик заполненных тикетов
            li_cnt++;
            //---- заполняем массив дополнительной информацией
            ar_Info[0]++;
            if (OrderType() < 2)
            {
                ar_Info[1]++;
                ar_Info[2] += OrderLots();
                ar_Info[3] += OrderProfit() + OrderSwap() + OrderCommission();
            }
        }
    }   
    //---- Учитываем максимальную просадку
    ar_Info[4] = MathMin (ar_Info[3], tmp_Loss);
//----
    return;   
}

Variant #2 for multi-currency:

// В глобальных переменных объявляем массив, с символами, с которыми работает наш мультивалютный советник
string gsa_Symbols[];
// Массив с дополниетельной информацией должен быть 2-ух мерным
// 1-ый индекс - это номер символа в массиве символов gsa_Symbols[]
// Не забудьте перед его использованием задать ему размер в первом измерении равный количеству используемых символов
// ArrayResize (gda_AddInfo, ArraySize (gsa_Symbols));
double gda_AddInfo[][5]; // массив для хранения дополнительной информации по работе советника
       // gda_AddInfo[][0] - количество соих ордеров (всех)
       // gda_AddInfo[][1] - количество своих рыночных ордеров
       // gda_AddInfo[][2] - общий размер открытых рыночных лотов
       // gda_AddInfo[][3] - общий профит по открытым позициям
       // gda_AddInfo[][4] - максимальная просадка по открытым позициям
// Для использования его в советнике, нужно предварительно задать его размер и заполнить символами
// (как это сделать - отдельная тема)

void fMyTickets (string ar_Symbol[],      // заполненный массив рабочих символов
                double& ar_Tickets[][11], // массив тикетов (для заполнения)
                double& ar_Info[][5],     // массив для заполнения дополнительной информацией
                int fi_Magic)             // MagicNumber
{
    int NUM_Symbol, li_cnt = 0, li_Range = ArraySize (ar_Symbol); // счетчик заполнения
    int li_total = OrdersTotal();
    string ls_Sym;
    double tmp_Loss[];
//----
    //---- Инициализируем временный массив для хранения сведений о максимальной просадке
    ArrayResize (tmp_Loss, li_Range);
    //---- Сохраняем в него эти сведения
    for (int li_int = 0; li_int < li_Range; li_int++)
    {tmp_Loss[li_int] = ar_Info[li_int][4];}
    //---- Обнуляем используемый массив
    ArrayInitialize (ar_Info, 0.0);
    for (int li_int = li_total - 1; li_int >= 0; li_int--)
    {
        if (OrderSelect (li_int, SELECT_BY_POS))
        {
            ls_Sym = OrderSymbol();
            //---- Определяем номер символа в массиве (фильтр по Symbol)
            NUM_Symbol = fGetNumElementInArray_STR (ar_Symbols, ls_Sym);
            //---- Если ордер не "свой" - пропускаем
            if (NUM_Symbol < 0)
            {continue;}
            //---- проверка MagicNumber
            if (OrderMagicNumber() != fi_Magic
            && fi_Magic >= 0) // предусматриваем возможность контролтровать любой Magic
            {continue;}
            //---- заполняем массив
            ar_Tickets[li_cnt][0] = OrderTicket();
            ar_Tickets[li_cnt][1] = OrderType();
            ar_Tickets[li_cnt][2] = OrderLots();
            ar_Tickets[li_cnt][3] = OrderOpenPrice();
            ar_Tickets[li_cnt][4] = OrderProfit() + OrderSwap() + OrderCommission();
            ar_Tickets[li_cnt][5] = OrderStopLoss();
            ar_Tickets[li_cnt][6] = OrderTakeProfit();
            ar_Tickets[li_cnt][7] = OrderOpenTime();
            ar_Tickets[li_cnt][8] = OrderMagicNumber();
            ar_Tickets[li_cnt][9] = OrderExpiration();
            ar_Tickets[li_cnt][10] = NUM_Symbol;
            //---- увеличим счётчик заполненных тикетов
            li_cnt++;
            //---- заполняем массив дополнительной информацией
            ar_Info[NUM_Symbol][0]++;
            if (OrderType() < 2)
            {
                ar_Info[NUM_Symbol][1]++;
                ar_Info[NUM_Symbol][2] += OrderLots();
                ar_Info[NUM_Symbol][3] += OrderProfit() + OrderSwap() + OrderCommission();
                ar_Info[NUM_Symbol][4] = MathMin (tmp_Loss[NUM_Symbol], ar_Info[NUM_Symbol][3]);
            }
        }
    }   
//----
    return;   
}

In the above examples on ticket information gathering, this information is enough in the vast majority of cases. But in more complex systems, no one forbids you to store information about them in an array of tickets, for example, if virtual stops are implemented in your Expert Advisor:

double gda_Tickets[30][12]; // массив для хранения информации о "своих" ордерах:
       // gda_Tickets[][0] - Ticket
       // gda_Tickets[][1] - Type
       // gda_Tickets[][2] - Lots
       // gda_Tickets[][3] - Open Price
       // gda_Tickets[][4] - Order Profit
       // gda_Tickets[][5] - Stop Loss
       // gda_Tickets[][6] - Take Profit
       // gda_Tickets[][7] - Open Time
       // gda_Tickets[][8] - MagicNumber
       // gda_Tickets[][9] - Expiration Time
       // gda_Tickets[][10] - Virtual SL
       // gda_Tickets[][11] - Virtual TP

In general, here you are limited only by the flight of fancy / fanaticism and the level of MQL4 knowledge.

 

TarasBY

In order not to unnecessarily "disturb" the server with requests...

The server is not disturbed when collecting orders. The ideology of collecting order information into an array is UG. There is no way this should be in the FAQ.
 
TheXpert:
The server is not disturbed when collecting orders. The ideology of collecting order information into an array -- UG. This is in no way allowed in the FAQ.

Suggest another option. for the need to work with "own" orders
 
I wouldn't suggest it. More often than not, an array of tickets is not needed at all. And the right thing to do, imho, is to always ask the terminal for the most up-to-date information possible.