[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 254

 
Desead:
Folks, previously in the editor when you hover over a reserved word and press f1 a window would open at the bottom with a description of the function, now I don't have this. What could be the problem ?
Previously you pressed CTRL+F1.
 
Who can tell me how to make the result always positive ? (Buy lots - Sell lots)= -0.25, but I want it to be always positive ?
 
mikanit:
Who can tell me how to make the result always positive ? (Buy lots - Sell lots)= -0.25, but it must be always positive ?
MathAbs().
 

I do so: if (profitbuy+profitsell > SymbProf_magBUY_magSELL* MathAbs((OrdersTotalMagicBuyLots(MagicBuy)-OrdersTotalMagicSellLots(MagicSell))/Lots)())

what's in brackets?

 

if (profitbuy+profitsell > SymbProf_magBUY_magSELL* MathAbs((OrdersTotalMagicBuyLots(MagicBuy)-OrdersTotalMagicSellLots(MagicSell))/Lots)(??????))

Where ???? what?

 
Thank you, it's sorted.
 

I open a position with a volume = 0.05. Need a code - how to reduce position volume by 0.01 when a loss reaches 100 pips for 5 digits ???

Thank you.

 

How many EAs I've written, all of them check market conditions (stop levelling, spread, etc.) when trading with pending orders. I've looked at how gridders are written, but I haven't seen any of them check the value of the same stop levelling before sending any order. What is the reason?

 
alsu:

There are plenty of metarials on the forum about the tester and why its results differ from real life. Look in the Articles section, this topic has been touched on more than once.

Thank you.
 

Found an alternative.

alsu:

It means that in DLL the string is passed exactly as char*, but not as MqlStr. But itdoesn't mean that in ex4 program the string is not stored as MqlString. In general, the transfer of parameters from ex4 to dll (according to the developers) is a rather complex process, accompanied by all kinds of checks and transformations of parameters.

Zhunko:

Have you read the MQL4 Reference? MQL4-string is the same as c-string with null-terminator.

The structure is designed only for arranging arrays of strings. Purely an invention of the Metacvots to facilitate the creation of string arrays.

StrStrA from the shlwapi.dll library. Test:

#property indicator_chart_window
#import "stdlib.ex4"
string IntegerToHexString(int integer_number);//это для перевода десятичного формата в шестнадцатеричный, используем в print.
#import "StrAddress.dll"
int GetStrAddress(string szStr);//из самописной dll.
#import "shlwapi.dll"
int StrStrA(string pszFirst, string pszSrch);//из WinAPI.
#import

int addr1;//будет выходной переменной для функции из самописной dll.
int addr2;//то же самое для функции из WinAPI.

int init()
  {//тестовый прогон; в init(), это чтобы не повторялось
   string s; strAddress (s);
   s=""; strAddress (s);
   s=s+"something"; strAddress (s);
   s="MyStr"; strAddress (s);
   s="mystr"; strAddress (s);
   return(0);
  }

int start()
  {
   int    counted_bars=IndicatorCounted();//оставляем блок пустым
   
   return(0);
  }

void strAddress (string myStr)//тестовая функция
  {
   addr1=GetStrAddress(myStr);//эта из dll
   addr2=StrStrA(myStr,myStr);//эта из WinAPI
   Print(" строка ", CharToStr(34), myStr, CharToStr(34), " указатель 1: ", IntegerToHexString(addr1), ", указатель 2: ", IntegerToHexString(addr2));//в лог
  }

Log:

строка "" указатель 1: 00000000, указатель 2: 00000000
строка "" указатель 1: 043 BE440, указатель 2: 00000000
строка "something" указатель 1: 043 C8970 указатель 2: 043 C8970
строка "MyStr" указатель 1: 043 BE450, указатель 2: 043 BE450
строка "mystr" указатель 1: 043 BE458, указатель 2: 043 BE458

строка "" указатель 1: 00000000, указатель 2: 00000000
строка "" указатель 1: 01 C980E0, указатель 2: 00000000
строка "something" указатель 1: 01 CDD050, указатель 2: 01 CDD050
строка "MyStr" указатель 1: 01 C980F0, указатель 2: 01 C980F0
строка "mystr" указатель 1: 01 C980F8, указатель 2: 01 C980F8

строка "" указатель 1: 00000000, указатель 2: 00000000
строка "" указатель 1: 01 CAFF20, указатель 2: 00000000
строка "something" указатель 1: 01 CA7100, указатель 2: 01 CA7100
строка "MyStr" указатель 1: 01 CAFF30, указатель 2: 01 CAFF30
строка "mystr" указатель 1: 01 CAFF38, указатель 2: 01 CAFF38

The mechanism is as follows. Shlwapi.dll in /system32. StrStrA is a WinAPI analog ofStringSubstr. MQL4 is a typeless language, so if we set an int at the output, rather than a string, we get a pointer to it, not a string. StrStrA searches for the first occurrence of a substring in the string (case-sensitive, but since our strings are the same, we don't care), and since our strings are the same, it returns a pointer to the first character of the string, i.e. the string itself.

Let me explain for those who will be using this code. There is no string format in the WinAPI. Instead, there is only the lpsz format (a pointer to the first element of an array of characters ending with 0x00, aka /0). It is a pointer to a memory address. Since our memory cells are 32-bit (i.e. 4 bytes) and int is also 4 bytes in size, everything fits there neatly.

Conclusion: you can easily pack strings into int arrays, thereby emulating structures (and there are no structures and classes in MQL4) to pass them further to the dll, if a structure or class is needed. Self-written dll for data type translation (i.e. constructions like "int(const char*)" (C-type translation) or similar in C++) can not be used now.