StringFind is not working correctly

 

Hi guys,

I'm facing a problem when Using the StringFind() function.

Here it is my code:

GlobalVariableName is in format: "Msg_123456789_-213.34"
double a(int ticket)
  {
   string tik = IntegerToString(ticket);
   Alert("t- "+tik);
   int tot=GlobalVariablesTotal();
   for(int i=0; i<tot; i++)
     {
      string name=GlobalVariableName(i);
      Alert("g- "+name);
      if(StringFind(name,tik)>=0)
        {
         Alert("1");
         string temp_array[];
         ushort sep = StringGetCharacter("_",0);
         StringSplit(name,sep,temp_array);
         double res = StrToDouble(temp_array[2]);
         return res;
        }
     }
   Alert("0");   
   return 0.0;
  }

So time to time it Alert "1", and 20% of the time StringFind () no works and it Alert "0"

Please help if you can see what I'm doing wrong.

Thanks in advance!

Documentation on MQL5: String Functions / StringFind
Documentation on MQL5: String Functions / StringFind
  • www.mql5.com
String Functions / StringFind - Reference on algorithmic/automated trading language for MetaTrader 5
 
There is no problem with StringFind(), fix your code.
 
Alain Verleyen:
There is no problem with StringFind(), fix your code.

Hi, thanks for the response!

I don't see the error in my code so therefor I did the post.

 
Your code
ushort sep = StringGetCharacter("_",0);
StringSplit(name,sep,temp_array);
Simplified
StringSplit(name,'_',temp_array);
 
William Roeder:
Your code
Simplified

Hi, thank you for the response!

I did the suggested correction but ... this part of the code is working just fine, the issue is StringFind()

I really cannot understand why once it finds the string, once not (80/20)

The string in the global var is in format "Msg_123456789_-213.34" and StringFind() is seeking the # 123456789(temp_array[1]) in that string

 
Relina:

Hi, thank you for the response!

I did the suggested correction but ... this part of the code is working just fine, the issue is StringFind()

I really cannot understand why once it finds the string, once not (80/20)

The string in the global var is in format "Msg_123456789_-213.34" and StringFind() is seeking the # 123456789(temp_array[1]) in that string

Show your log.
 
Alain Verleyen:
Show your log.

Here it is.

Thanks for helping by the way :)

Files:
 
Relina:

Here it is.

Thanks for helping by the way :)

There is no problem in this snippet of the log.

Please provide the log file, not a picture of it.

 
Alain Verleyen:

There is no problem in this snippet of the log.

Please provide the log file, not a picture of it.

Here it is ...
Files:
20200623.log  33 kb
 
Relina:
Here it is ...
0       16:02:07.672    HedgeEA_v.4.0 AUDNZD,M5: Alert: t- 25721959
0       16:02:07.672    HedgeEA_v.4.0 AUDNZD,M5: Alert: gn- Mag_25716995_-211.60
0       16:02:07.672    HedgeEA_v.4.0 AUDNZD,M5: Alert: 0

What is the problem with StringFind() ? There is not, the function can't find something inexistent.

Fix your logic and your code, and stop blaming the language for your error, it will help you to progress.

 
Alain Verleyen:

What is the problem with StringFind() ? There is not, the function can't find something inexistent.

Fix your logic and your code, and stop blaming the language for your error, it will help you to progress.

Sorry but I really don't see any error in my code.

Anyways I'm attaching the EA so you also can check ...

Thanks for your patience ... I know the error is with me somewhere but can't find it, so I'm seeking help from pro guys here on the forum

Thanks

Reason: