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

 
Alexandr Sokolov:

it doesn't get to the calculations


here's the initialization


And here's the test condition.

THANK YOU!!!!!))))) I Tf=false on purpose and......Forget . Oops

Everything works.
 
Alexey Viktorov:
First, we need to decide on the number of values in the second dimension of the future array. Already now we can see that the number of elements is not equal. Probably, we should take maximal one and fill with zeros or -1, for example, where extra ones remain. And it wouldn't hurt to define the first dimension beforehand if it is known. And then in the nested loop take L1 and write everything you need into the array, then the second iteration of the outer loop writes into the next index everything in L2 and so on.


And quite properly, it's better to stick it in a structure.

Then the array will be able to change dimension in the first and in the second dimension. That is, it will be a one-dimensional array in a one-dimensional array.
Thanks for the vector.
 
stepystr:
Thanks for the vector.

I suddenly got an order in which it was also more profitable to write the parameters into a string and use it to create an array of parameters. I had to turn theory into practice. Well, I extended my task to your task. Here is an example using structures. Only in your examples at the end of the list of values you need to remove the delimiter character ";"

/********************************************************************\
|                                                             00.mq5 |
|                                            © 2020, Alexey Viktorov |
|                       https://www.mql5.com/ru/users/alexeyvik/news |
\********************************************************************/
#property copyright "© 2020, Alexey Viktorov"
#property link      "https://www.mql5.com/ru/users/alexeyvik/news"
#property version   "1.00"
struct TEST
 {
  double             s0[];
  double             s1[];
 } test[2];
string L1 = "1.15110;1.14105;1.13240;1.12370;1.11640;1.11170;1.10655;1.09895;1.08850;1.07850;1.06475";
string L2 = "1.32130;1.31030;1.29860;1.29042;1.27985;1.25605;1.24725;1.23565;1.22505;1.20815;1.20115;1.18850;1.16690;1.14465";
/********************Script program start function*******************/
void OnStart()
 {
  String_to_Array(L1, test[0].s0);
  String_to_Array(L2, test[1].s1);
  ArrayPrint(test[0].s0);
  ArrayPrint(test[1].s1);
 }/******************************************************************/

/********************************************************************/
void String_to_Array(string str, double &array[])
 {
  StringTrimRight(str);
  int index = INT_MAX;
  while(index > 0)
   {
    index = StringFind(str, ";");
    int i = ArraySize(array);
    ArrayResize(array, i+1);
    array[i] = StringToDouble(StringSubstr(str, 0, index));
    StringTrimLeft(str);
    str = StringSubstr(str, index+1);
   }
 };/*****************************************************************/
/*****************************End program****************************/
Files:
00.mq5  4 kb
 
Alexey Viktorov:

I suddenly got an order in which it was also more profitable to write the parameters into a string and use it to create an array of parameters. I had to turn theory into practice. Well, I extended my task to your task. Here is an example using structures. Only in your examples at the end of the list of values you need to remove the delimiter character ";"

struct TEST
{
   double             s0[];
   double             s1[];
} test[2];
string L1 = "1.15110;1.14105;1.13240;1.12370;1.11640;1.11170;1.10655;1.09895;1.08850;1.07850;1.06475";
string L2 = "1.32130;1.31030;1.29860;1.29042;1.27985;1.25605;1.24725;1.23565;1.22505;1.20815;1.20115;1.18850;1.16690;1.14465";
/********************Script program start function*******************/
void OnStart()
{
   String_to_Array(L1, ';', test[0].s0);
   String_to_Array(L2, ';', test[1].s1);
   ArrayPrint(test[0].s0);
   ArrayPrint(test[1].s1);
}/******************************************************************/

/********************************************************************/
void String_to_Array(const string str, const ushort separator, double &result[])
{
   string s_arr[];
   if(StringSplit(str, separator, s_arr) <= 0)
   {
      ArrayResize(result, 0);
      Print(__FUNCTION__ + " Error converting !");
      return;
   }
   ArrayResize(result, ArraySize(s_arr));
   for(int i = ArraySize(result) - 1; i >= 0; i--)
      result[i] = StringToDouble(s_arr[i]);
}
 

without checks, you can even go like this

void String_to_Array(const string str, const ushort separator, double &result[])
{
   string s_arr[];
   StringSplit(str, separator, s_arr);
   for(int i = ArrayResize(result, ArraySize(s_arr)) - 1; i >= 0; i--)
      result[i] = StringToDouble(s_arr[i]);
}
 
Igor Makanu:

Also an option. It turns out I haven't read all the documentation either.

 
Alexey Viktorov:

Also an option. It turns out that I haven't read all the documentation either.

StringSplit is a cool thing, very convenient to parse delimited strings

 
Hi all. Help me insert a String variable into my code. Thanks
ObjectCreate("ObjName11",OBJ_LABEL,0,0,0);
   ObjectSetText("ObjName11","|Direction: ="+ <String>   +"|Spread: ="+IntegerToString(Spread,0)+"|Today: ="+DoubleToStr(ATRToday,2)+"%" ,Size,"Verdana",Red);
   ObjectSet("ObjName11",OBJPROP_CORNER,infoCorner);
   ObjectSet("ObjName11",OBJPROP_XDISTANCE,0);
   ObjectSet("ObjName11",OBJPROP_YDISTANCE,120);
 
Carcass77:
Hi all. Help me insert a String type variable into the code. Thanks

Could you answer your own question?

or did you cut out a piece of code somewhere and can't use it? and you need to guess what's going on at least)))

write above

string s;

and replace <String> with s

but i don't think that's the way to go with this approach.

 
Igor Makanu:

Could you answer your own question?

or did you cut out a piece of code somewhere and can't use it? and you need to guess what's going on at least)))

write above

and replace <String> with s

but i think this is not the solution with this approach

My indicator works, just extending.string s; has been added.

Ok, I'll get to it myself.

Reason: