Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 421

 

Hi. How do I find out the price of the object closest to the current price by the part of the name, at the beginning of "R"

The objects are horizontal bars (OBJ_TREND) with names "R 11", "R 7"...

... does not show anything like that.

priceR = ObjectGet("R"+"" ,OBJPROP_PRICE1);

.

 
lil_lil:

Hello. How do you find an object by the part of the name that starts with "R"?

it doesn't find it that way.

.

The help says:

StringFind

Search for a substring in a string.

intStringFind(
stringstring_value, // string we are looking for
stringmatch_substring, //searched
intstart_pos=0// which position to start search
);

Parameters

string_value

[in] String to search in.

match_substring

[in] Match_substring to be searched.

start_pos=0

[in] Position in the string where the search should be started.

Returned value

Returns position number in the string where the substring to be searched starts, or -1 if no substring is found.

 
Artyom Trishkin:

The reference reads:



Thank you, but what line are we looking in?

 
lil_lil:

Thank you, but in which line are we looking?

Object name.
 
Artyom Trishkin:
Object name.
"String to be searched"-what should I write here?
priceR = ObjectGet(StringFind( 1,"R",0) ,OBJPROP_PRICE1);

. there is nothing.

 
What, and in what case does StringFind() return? I gave a full reference to the function from the help (although the help is right at your fingertips in the MetaEditor - just put the cursor on the function and press F1)
 
Artyom Trishkin:
What, and in what case does StringFind() return? I gave a full footnote of the function from the help (although the help is right at your fingertips in the MetaEditor - just put the cursor on the function and press F1).
Help is open, I don't understand which line to look in, nothing is known yet, except that the name has "R" in it.
 
lil_lil:
Help is open, I don't understand which line to look in, nothing is known yet except that there is an "R" in the name.

//--- показываем список объектов 
int obj_total=ObjectsTotal();
string name;

for(i=0;i<obj_total;i++)
  {
   name=ObjectName(i);
   if(ObjectType(name)!=OBJ_TREND) continue;
   if(StringFind(name,"R",0)!=-1)
     {
     priceR = ObjectGet(name ,OBJPROP_PRICE1);
     }
  }

Like this.

 
Alekseu Fedotov:

There you go.


Thank you.

 

Greetings. Help is getting a volume return error:

I have an array created. Bid, date and volume..:

extern ulong extreme_volume=50;
ulong volume_start=0;
ulong volume_end=0;

ulong mass_volume[];

volume_start=Volume; //Ругается на эту строку


Marks: Invalid Array access

Reason: