Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1302

 

Forum on trading, automated trading systems & strategy testing

Any questions from newbies on MQL4 and MQL5, tips and discussion on algorithms and codes

Dmitry Custurov, 2020.08.27 13:10

Greetings.

I have the following thing in MT4:

#import "user32.dll"
   int SendMessageA(int hWnd, int Msg, int wParam, char &lParam[]);
   int RegisterWindowMessageA(uchar &lParam[]);
#import

string IndiName="TestBot";

void OnStart()
  {
   char buf[];
   StringToCharArray("MetaTrader4_Internal_Message", buf);
   int MT4InternalMsg=RegisterWindowMessageA(buf);
   StringToCharArray(IndiName, buf);
   long handle=ChartGetInteger(0, CHART_WINDOW_HANDLE);
   Print(MT4InternalMsg);
   bool res=SendMessageA((int)handle, MT4InternalMsg, 14, buf);
   Print("Функция SendMessageA завершила работу с результатом: ",res);
  }

This code sends a command to the terminal window to start a specific EA.

Is there similar functionality for MT5 ?

I tried it like this:

#import "user32.dll"
   int SendMessageA(long hWnd, long Msg, uint wParam, uchar &lParam[]);
   int RegisterWindowMessageA(uchar &lParam[]);
#import

string IndiName="TestBot";

void OnStart()
  {
   uchar buf[];
   StringToCharArray("MetaTrader5_Internal_Message", buf);
   long MT5InternalMsg=RegisterWindowMessageA(buf);
   StringToCharArray(IndiName, buf);
   long handle=ChartGetInteger(0, CHART_WINDOW_HANDLE);
   Print("Window handle: ", handle);
   Print("Message: ",MT5InternalMsg);
   for(int i = 0; i<100; i++){
      bool res=SendMessageA(handle, MT5InternalMsg, i , buf);
      printf("Функция SendMessageA завершила работу с результатом: %d, номер: %d ",res, i);
   }
  }

Doesn't work.

I tried scanning for spy++, but there are no messages in MT5 unlike in MT4.

I need exactly to open Expert Advisor settings window.


I need to be able to run the script through WinAPI. Is there a solution for 5?

 
Hey! Guys, help me out! I can't think of a function. The Expert Advisor opens one position per day (between 00:00 and 23:59), i.e. one day, one order. The task is to find the series of continuous losses and display it in the log (using the command Print(), to print once). The number of elements in the series is entered from the keyboard (For example, if you entered 5 from the keyboard and the series has 4 losing days, then we ignore it --> wait for the occurrence of 5 or more days). A series is considered if losing days are consecutive or orders are closed in one day (they are opened once a day, and market orders can "hang" more than one day). For example, in the log there should be the following loss series: 01.05, 02.05, 03.05, 04.05, 05.05. Important condition: recognize series (and consequently output it to the log), which is greater than or equal to the value entered from the keyboard (extern).
//
Personally I have the following idea:
1. Fiya fills the array of losing orders with their closing values ( Mass[i] = OrderCloseTime();). That is, the array stores only the closing dates and times of the losing orders
2. We start comparing the element at position i and at position i-1 (2 adjacent ones)
2.1 we compare them by converting the cell data to the day of the year ( TimeDayOfYear(Mass[i]) and TimeDayOfYear(Mass[i-1])
2.(Suppose the first losing day = 178, and the previous one = 176 --> no series, because they are not consecutive, respectively if the first = 178, and the second 177 --> we have a series)
2.3 With the for loop we look through all cells of the array and compare its neighbours. If there is a series of losses on neighboringelements of the array--> let's start compressing until 1.we have not reached the minimum requirednumber of losing days to consider it as a series. 2. (if point 1 is fulfilled) BEFORE the series stops.
2.4 THE SERIES STOP --> remember the index of the array element where it ended and remember the number of elements in the series (the series can be == OR greater than the value entered from the keyboard)
3. ----here begins problem of realization---
3.1 We should "step back" somehow through series of losing days, knowing date of each element, translate date from datetime --> string,
3.11 fill string ( I don't know, maybe through StringAdd()?), and output it to LOG-file (not million times, just one)

Algorithm of advisor is not important, important is user function itself

For Christ sake, help!))
Документация по MQL5: Основы языка / Переменные
Документация по MQL5: Основы языка / Переменные
  • www.mql5.com
Переменные должны быть объявлены перед их использованием. Для идентификации переменных используются уникальные имена. Описания переменных используются для их определения и объявления типов. Описание не является оператором. Индексом массива может быть только целое число. Допускаются не более чем четырехмерные массивы. Нумерация элементов массива...
Files:
 

Hello.
Advice on an algorithm is required.
I am trying to form the following requirement before processing a block of open orders:

If there are already buy/sell orders and opening price of the last order is less by X points than current price, then ignore block/not open orders.

Please advise - what are the options for implementation in the code?

 

Has anyone measured for mt 5 from the moment an order is sent to open a position until it actually appears, how long can it take?

I'm more interested if an order is sent and a trade is advised, from the moment the order is sent until the trades appear, how long can it take ?

 
Сергей Таболин:

k = {1,2,4,8,16,......}

cn = k[c]

Funny solution))))

 
Vladimir Baskakov:
Is MQ planning to add custom indicators to the mobile platform?

Judging by the responses on the new mobile terminal, not in the near future. Only pens.

 
Valeriy Yastremskiy:

Fancy solution))))

Well, if the coefficients are known in advance, why calculate them? )))

 
Сергей Таболин:

Well, if the coefficients are known in advance, why calculate them? )))

It's more universal if you calculate them.

 

Colleagues, good day to all - intuitively I understand the solution, I would like to hear from you.

What is the best way, to allocate parts of the lot for their subsequent closing (partial closing of the Total lot - in parts - 5 unit parts).

In my understanding, for example, lot 2.58. I divide by 5, the result is 0.51 lot to close 4 parts and the fifth part is 0.54 lot.

What is the best way to represent this in the code? What math function takes the remainder of the division to take 0.54 to close?

 
Roman Shiredchenko:

Colleagues, good day to all - intuitively I understand the solution, I would like to hear from you.

What is the best way, to allocate parts of the lot for their subsequent closing (partial closing of the Total lot - in parts - 5 units of parts).

In my understanding, for example, lot 2.58. I divide by 5, the result is 0.51 lot to close 4 parts and the fifth part is 0.54 lot.

What is the best way to represent this in the code? What function takes the remainder of the division to take 0.54 to close?

Can I read the documentation?


Reason: