Self-learning the MQL5 language from scratch - page 77

 
MrBrooklin:

Hello Alexey, to be honest I'm not very good at programming. Does it mean that the code provided by Konstantin should be finalized?

Sincerely, Vladimir.

It needs to be reworked and thrown out.

 
Alexey Viktorov:

It needs to be reworked and thrown away.

Why so cruel!

Thank you Alexey!!! Your code works perfectly.

Regards, Vladimir.

 

Alexey, everything is clear about the search, because StringFind is a search for a substring in a string:

int  StringFind( 
   string  string_value,        // строка, в которой ищем 
   string  match_substring,     // что ищем 
   int     start_pos=0          // с какой позиции начинать поиск 
   );

The only thing I can't figure out is why we check the function for equality to zero when searching for a substring in a string.

if(StringFind(_Symbol, Symbol_Main, 0) == 0)

Regards, Vladimir.

 
MrBrooklin:

Alexey, everything is clear about the search, because StringFind is a search for a substring in a string:

The only thing I can't figure out is why we check the function for equality to zero when searching for a substring in a string.

Regards, Vladimir.

From the
documentation

Returned value

The function returns the number of the substring in the string, at which the sought substring starts. If no substring is found, the function returns -1.

I.e. chart symbol starts with "GBPUSD" and it doesn't matter what suffix is attached.

I was a bit hasty too, though. If you enter only "GBP" for example, then any graph will be valid if the base currency is "GBP". Additionally, we should check the length of the text in the input line.
 
Alexey Viktorov:

From the documentation

i.e. the chart symbol starts with "GBPUSD" and it doesn't matter what suffix is attached.

Although I was a bit hasty too. If you enter only "GBP" for example, any chart will be valid if the base currency is "GBP". Additionally, we should check the length of the text in the input line.

but just compare? and limit the input to small letters. or enum, that's for foolproof))))

 
Alexey Viktorov:

From the documentation

i.e. the chart symbol starts with "GBPUSD" and it doesn't matter what suffix is attached.

Although, I was a little hasty too. If you enter only "GBP" for example, then any chart will be valid if the base currency is "GBP". Additionally, we should check the length of the text in the input line.

I see!

Regards, Vladimir.

 
Valeriy Yastremskiy:

but just compare? and limit the input to small letters. or enum, for the sake of the fool))))

Hello Valery! Started with ENUM_SYMBOL_INFO_STRING from the beginning, but for some reason nothing worked. You can try it again, though.

Sincerely, Vladimir.

 
Valeriy Yastremskiy:

but just compare? and limit the input to small letters. or enum, what's foolproof))))

You could also just compare, but if the characters have a suffix, you have to enter them as is. In general, there are plenty of options, and it is futile to argue about the tastes of flomasters.

But if you have an enum, search in the string will be necessary. Because the enum contains pure symbol names and the chart can contain any attachments.

 
Alexey Viktorov:

Why make such a mockery of an immature mind? Your code does not meet the requirement at all. If only "eu" or "eur" is entered in the input parameters, this part of the condition

will be fulfilled no matter what currency pair contains "EU" in its name and it does not matter EUR as base currency or quoted currency. And why go through the SymbolName of MarketWatch searching for the right symbol?

Alexei, it's quite normal code. It's not normal, you have to enter several symbols in a parameter, which is unlikely to be done by anyone.

I have roughly the same implementation in my work product.

This implementation successfully works in a multicurrency solution, what cannot be said about other codes, i.e. the code is universal.

 
Alexey Viktorov:

You could also just compare them, but if the characters have a suffix, you have to enter them as is. In general, there are quite a lot of options and it is a futile task to argue about the tastes of flomasters.

But if you have an enum, search in the string will be necessary. The enum is used to store names of pure symbols, while the chart can contain any attachments.

Alexey, thanks for the tip in bold. I will try to rework the very first version of the code I wrote earlier for the sake of interest.

Regards, Vladimir.