[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 247

 

sss2019, no time to deal with it now, sorry.

Zhunko:
Wrong. Correct, as shown above.

As soon as I get around to it, I'll fix it and edit the code in the post there.

Question. How do I get a pointer to a string? The MQL4 string is C++ lpsz, as far as I understood. But how do we get the string address itself?

 
I have an idea how to make one and the same EA work with different wizards. The problem is that when there is a lock, the robot will separately handle this situation without interfering with other orders. i.e. we have one position opened at Bay (magic 001) the market went against us and instead of closing the deal the opposite deal opens at Sell with magic 001 and the robot will be liquidating this situation, but to avoid waiting long time to liquidate the situation I want to open again Bay but already with magic (002) and if the trend is not successful the lock with the magic (002) will open again Sell with (002), etc. Can you tell how to make deals work as follows with different magic pairs?
 
pasha5282:
If i have an idea how to make one and the same EA work with different wizards. the robot should separately handle this situation when a lock occurs and not interfere with other orders. i.e. we have one position opened at Bay (magic 001) the market went against us and instead of closing the deal the opposite deal opens at Sell with magic 001 and the robot will take care of the situation and I want to open again Bay but with magic (002) in order not to wait long time to take care of it and in case the trend is not successful the Sell lock with magic (002) will open again and so on. Any advice how to make deals work as a layer with different magic? Maybe somebody has faced? Or how to implement?
int MagicNumber=001;
//---
if (OrdersTotal()>0) // проверяем, есть ли ордера
{  for (int i=OrdersTotal()-1; i>=0; i--) // перебор ордеров
   {  if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) // выбирается ордер среди открытых и отложенных ордеров
      {  if (OrderSymbol()!=Symbol()) continue; // проверяем - ордер по текущему символу?
         if (OrderMagicNumber()!=MagicNumber) continue; // проверяем - ордер с нужным магиком?
         //---
         if (OrderType()==OP_BUY) // если это открытая позиция на покупку, то ...
           {  // ... какие-то действия
                 return(0);
           }
         //---
         else
         if (OrderType()==OP_SELL) // если это открытая позиция на продажу, то ...
           {  // ... какие-то действия
                 return(0);
           }
}  }  }

Example of a counter of open and pending orders by the required symbol and magician

string _Symbol="AUDUSD";
int MagicNumber=555;
//---
int Opened_pos=0;
if (OrdersTotal()>0)
{  for (i=OrdersTotal()-1; i>=0; i--)
   {  if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {  if (OrderSymbol()==_Symbol)
         {  if (OrderMagicNumber()==MagicNumber)
            Opened_pos++;
}  }  }  }
 

For some reason, the terminal glitched during testing. Now when you turn it on, it starts using about 150 mb of memory and hangs. Was going to reinstall, but moved all my files before doing so. When I opened the folders I found that not all the files I created were there. Where are the rest of them?


 
silhouette:

For some reason, the terminal glitched during testing. Now when you turn it on, it starts using about 150 mb of memory and hangs. Was going to reinstall, but moved all my files before doing so. When I opened the folders I found that not all the files I created were there. Where are the others?

The left screenshot is MQL5 and not 4.
 
gyfto:

sss2019, no time to deal with it now, sorry.


As soon as I get around to it, I'll fix it and edit the code in the post there.

Question. How do I get a pointer to a string? The MQL4 string is C++ lpsz, as far as I understood. But how do I get the address of the string itself?

There is no way to do it in MQL4. You can pass the string to DLL and return the address as INT.
 
paladin80:
The left screenshot is MQL5, not 4.

No, it's the fourth one. It's just that when you click on the fourth file, it opens through the fifth one, for some reason
 
silhouette:
No, the fourth one. It's just that the files of the fourth, when clicked, open through the fifth, for some reason

Open MetaEditor for 5, in the left window "Navigator" -> on a folder right mouse click -> "Open folder" and there among folders try to search.



 
Zhunko:
There is no way to do it in MQL4. You can pass a string to a DLL and return the address as INT.

//C++
#include "stdafx.h"
#include <windows.h>
#define MT4_EXPFUNC __declspec(dllexport)
struct MqlStr {
   int               len;
   char             *string;
  };
BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
    return TRUE;
}
MT4_EXPFUNC int __stdcall GetStrAddress(const char *str) {    
    MqlStr* s = (MqlStr*)str;
    return (int)s->string; 
}

//MQL4

#import "StrAddress.dll"
int GetStrAddress(string str);//на входе имя инициализированной строки, на выходе её адрес
#import
//объявляем:
string s="something";
int address;
//пример использования:
int start(){
   address=GetStrAddress(s);
   Print(" адрес s равен " s);
}

So that others don't suffer the same way, I've attached the whole zipped project. With sources, so that others could see that it is not a virus. I did not have time to check what is compiled in VC++ 6.0 and what is rubbish. StrAddress.dll is in the Debug folder.

Files:
straddress.zip  984 kb
 
paladin80:

Open MetaEditor for 5, in the left window "Navigator" -> right mouse click on a folder -> "Open folder" and there among folders try to search.



Thanks, but nothing from mt4 turned up there. Used search and found all files at the following address:

C:\Users\Qwer\AppData\Local\VirtualStore\Program Files\MetaTrader 4\experts\include

I have no idea how they got there, to be honest, as they were saved properly before.