Questions from Beginners MQL5 MT5 MetaTrader 5 - page 576

 

Hello.

Can you please tell me if it is possible to copy the text from the EA to the clipboard, for example, by condition, the text of the allert.

If so, how to do it?

 
mila.com:

Hello.

Can you please tell me if it is possible to copy the text from the EA to the clipboard, for example, by condition, the text of the allert.

If so, how to do it?

No. Working with the clipboard is a system function (Windows API). In MQL5 there is no direct access to WinAPI. And why work with the clipboard? After all, you are generating the message yourself - it means that you have the source text of the message.
 
Karputov Vladimir:
No. Working with the clipboard is a system function (Windows API). In MQL5 there is no direct access to WinAPI. And why should you work with the clipboard? After all, you are generating the message yourself - so you have the source text of the message.

Yes, the source code is there, but I need it, by a certain condition, on the clipboard.

Sorry, I didn't specify, I need the implementation in MQL4.

Is it possible to open the clipboard somehow using #import "user32.dll"?

 
mila.com:

Yes, the source code is there, but I need it, by a certain condition, on the clipboard.

Sorry, I didn't specify, I need the implementation in MQL4.

Maybe you can open the clipboard somehow using #import "user32.dll"?

It's time to write in MQL5. Using dll is the top of recklessness.

As I understand it, you want to read the information from a third-party program. Then use writing to a file, in a common directory of all client terminals \Terminal\Common\Files. Already from this directory you can read the file with a third-party program.

 
Karputov Vladimir:

It is high time to write in MQL5. Using a dll is the height of folly.

As I understand it, you want to read information from a third-party program. Then use writing to a file, in a common directory of all client terminals \Terminal\Common\Files. From that directory you can read the file with a third-party program.

Thanks for the recommendations, but now I need to copy the text to clipboard from MQL4 program.

 
Karputov Vladimir:

Let's take it in order. Here's the template:

Attach it to the chart and a screenshot of the chart in the studio, as well as the entries from the "Log" and "Advisors" tabs (if they appear there).

Hello !!!

I restarted the MT5 platform for starters. Compiled your template. The result of compilation is shown below. I had to throw away the screenshots because of the large volume

An EA has appeared in the navigator:

Threw the EA on the chart and allowed trading in 3 places:

Got the EA icon on the chart instead of a smiley face

Here is an excerpt from the log 2016.05.11 12:44:47.139 Expert Expert Test (GBPUSD,H1) loaded successfully

Below is the content of the message about loading the EA:

CO 0 10:35:45.020 Terminal Alpari Limited MT5 x64 build 1325 started
HD 0 10:35:45.020 Terminal Windows 8.1 (x64 based PC), IE 11.00, UAC, Intel Core i5-2320 @ 3.00GHz, RAM: 2209 / 4078 Mb, HDD: 45023 / 149999 Mb, GMT+03:00
ND 0 10:35:45.020 Terminal C:\Users\Boris\AppData\Roaming\MetaQuotes\Terminal\73D45AFCBD5653CAF29C407A081F030C
LI 0 10:35:47.200 Network '50016841': authorized on Alpari-Ltd-MT5 via mt5.nl.3 (ping: 57.34 ms)
NG 0 10:35:47.200 Network '50016841': previous successful authorization performed from 79.172.69.175 on 2016.05.10 23:47:58
FK 0 10:35:47.617 Network '50016841': terminal synchronized with Alpari Limited
RM 0 10:35:47.617 Network '50016841': trading has been enabled - netting mode
OH 0 10:35:48.253 Network '50016841': scanning network for access points
CL 0 10:35:51.446 Network '50016841': scanning network finished
ND 1 12:00:49.011 Network '50016841': connection to Alpari-Ltd-MT5 lost
MR 0 12:01:08.842 Network '50016841': authorized on Alpari-Ltd-MT5 through mt5.nl.3 (ping: 56.41 ms)
HR 0 12:01:08.842 Network '50016841': previous successful authorization performed from 79.172.69.175 on 2016.05.11 10:35:52
PQ 0 12:01:08.907 Network '50016841': terminal synchronized with Alpari Limited
PH 0 12:01:08.907 Network '50016841': trading has been enabled - netting mode
KL 0 12:41:45.169 Expert Advisor Test (GBPUSD,H1) loaded successfully

Please have a look at it. Maybe you will find the cause. I'm stumped, maybe it's a problem with the build?

Thank you !!!



Thanks for the help !!!

 
Boris.45:

Hello !!!

I restarted the MT5 platform for starters. Compiled your template. The result of compilation is shown below. I had to throw away the screenshots because of the large volume

An EA has appeared in the navigator:

Threw the EA on the chart and allowed trading in 3 places:

Got the EA icon on the chart instead of a smiley face

Here is an excerpt from the log 2016.05.11 12:44:47.139 Expert Expert Test (GBPUSD,H1) loaded successfully

Below is the message content about loading the EA:

CO 0 10:35:45.020 Terminal Alpari Limited MT5 x64 build 1325 started
HD 0 10:35:45.020 Terminal Windows 8.1 (x64 based PC), IE 11.00, UAC, Intel Core i5-2320 @ 3.00GHz, RAM: 2209 / 4078 Mb, HDD: 45023 / 149999 Mb, GMT+03:00
ND 0 10:35:45.020 Terminal C:\Users\Boris\AppData\Roaming\MetaQuotes\Terminal\73D45AFCBD5653CAF29C407A081F030C
LI 0 10:35:47.200 Network '50016841': authorized on Alpari-Ltd-MT5 via mt5.nl.3 (ping: 57.34 ms)
NG 0 10:35:47.200 Network '50016841': previous successful authorization performed from 79.172.69.175 on 2016.05.10 23:47:58
FK 0 10:35:47.617 Network '50016841': terminal synchronized with Alpari Limited
RM 0 10:35:47.617 Network '50016841': trading has been enabled - netting mode
OH 0 10:35:48.253 Network '50016841': scanning network for access points
CL 0 10:35:51.446 Network '50016841': scanning network finished
ND 1 12:00:49.011 Network '50016841': connection to Alpari-Ltd-MT5 lost
MR 0 12:01:08.842 Network '50016841': authorized on Alpari-Ltd-MT5 through mt5.nl.3 (ping: 56.41 ms)
HR 0 12:01:08.842 Network '50016841': previous successful authorization performed from 79.172.69.175 on 2016.05.11 10:35:52
PQ 0 12:01:08.907 Network '50016841': terminal synchronized with Alpari Limited
PH 0 12:01:08.907 Network '50016841': trading has been enabled - netting mode
KL 0 12:41:45.169 Expert Advisor Test (GBPUSD,H1) loaded successfully

Please have a look at it. Maybe you will find the cause. I'm stumped, maybe it's a problem with the build?

Thank you !!!



Thanks for the help !!!

Install the terminal on top of this faulty one. It may be cured.
 
Karputov Vladimir:

It's high time we wrote in MQL5. Using a dll is the height of folly.

As I understand it, you want to read information from a third-party program. Then use writing to a file, in a common directory of all client terminals \Terminal\Common\Files. Already from this directory you can read the file with a third-party program.

If it were "the height of folly", it would be forbidden.

WinAPI greatly extends the capabilities of MQL. And you can do something stupid even without dll.

And here is an example of passing a string to the clipboard:

#define  CF_UNICODETEXT 13
#define  GHND 0x0042

#import "User32.dll"
   int OpenClipboard( uint );
   int EmptyClipboard();
   int CloseClipboard();
   uint SetClipboardData( uint uFormat, uint hMem );
#import "Kernel32.dll"
   uint GlobalAlloc( uint uFlags, uint dwBytes );
   uint GlobalLock( uint hMem );
   int GlobalUnlock( uint hMem );
#import "msvcrt.dll"
   uint memcpy( uint dest, string src, uint count );
#import

string str = "АБВГД";

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{
   uint hwnd = (uint)ChartGetInteger( 0, CHART_WINDOW_HANDLE );
   
   int strSize = StringLen( str ) * 2 + 2;  // Получаем размер строки в байтах
   
   if( OpenClipboard( hwnd ) )    // Открываем буфер
   {
      EmptyClipboard();           // Очищаем буфер
      
      uint hMem = GlobalAlloc( GHND, strSize ); // Выделяем память
      uint pMem = GlobalLock( hMem );    // Получаем адрес выделенной памяти
      memcpy( pMem, str, strSize );     // Копируем строку в память
      GlobalUnlock( hMem );
   
      SetClipboardData( CF_UNICODETEXT, hMem );  // Передаём память со строкой в буфер
      
      CloseClipboard();  // Закрываем буфер
   }
}
 
Artyom Trishkin:


Artem, tell me, if I insert all this from under the On Start function in the On Tick function, the script will be executed the same way, only on each tick, right?

Or something needs to be changed?

Since the previous candlesticks, except the current one, do not change on every tick, so, I suppose, we should add a condition to check it once, for example 1 - 2 seconds before the current candlestick closes? Or there is no sense in it and we can leave the check on every tick?

 
Andrey Koldorkin:

Artem, tell me, if I insert all this from under the On Start function in the On Tick function, the script will be executed the same way, only on each tick, right?

Or something needs to be changed?

Since the previous candlesticks, except the current one, do not change on every tick, so, I suppose, we should add a condition to check it once, for example 1 - 2 seconds before the next current candlestick closes? Or there is no sense in it and we can leave the check on every tick?

Well, I would form it all into a function and call it when I need it - at every tick (if it is reasonable and necessary), or at the opening of a new candle - once an hour, for example, if we work with H1.
Reason: