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

 
Alexey Viktorov:

The variable string x; should not be confused with the string character "x".

I did not understand the specific task. Accordingly, there is no specific answer.

Maybe you'd better think about overloading functions?

The situation is such that I need to create a universal function function_xy where the main program would understand that the name of the string variable object_xy changes depending on parameters passed(..., ..., string x, string y). Otherwise, further down the code in function_xy() I'll have to manually spell out the name of variable object_xy.
For example,

void function_xy(..., ..., string x="EURUSD", string y="GBPUSD")
{
...
string object_xy=...//то есть здесь программа должна понимать, что это переменная object_EURUSDGBPUSD
...
}

Otherwise when creating several graphical objects in function_xy(), I'll have to manually assign parameters of graphical functions

void function_xy(..., ...,...)
{
...
string object_EURUSDGBPUSD=...//то есть здесь программа должна понимать, что это переменная object_EURUSDGBPUSD
...
ObjectCreate(object_EURUSDGBPUSD,...,...)
ObjectSet(object_EURUSDGBPUSD,...,...)
ObjectSetText(object_EURUSDGBPUSD,...,...)
...
}

void function_wz(..., ...,...)
{
...
string object_USDCHFUSDJPY=...//то есть здесь программа должна понимать, что это переменная object_EURUSDGBPUSD
...
ObjectCreate(object_USDCHFUSDJPY,...,...)
ObjectSet(object_USDCHFUSDJPY,...,...)
ObjectSetText(object_USDCHFUSDJPY,...,...)
...
}

There are up to 2 hundred of such functions, can you somehow reduce and solve this problem?
I hope I have expressed my thought.



 
Timur1988:

The situation is such that I need to create a universal function function_xy where the main program understands that the name of the string variable object_xy changes depending on the parameters passed(..., ..., string x, string y). Otherwise, further down the code in function_xy() I'll have to manually spell out the name of variable object_xy.
For example,

Otherwise, creating several graphical objects in function_xy(), I'll have to manually assign parameters of graphical functions

There are up to 2 hundred of such functions, can you somehow reduce and solve this problem?
I hope I have expressed my thought.

All you need to do is write a piece of code that will form object name depending on X and Y, for example, take it from array like this: n=10*x+y. When x=0 and y=0...9, the first 10 elements will be chosen. When x=1 and y=0...9, the next 10 elements will be chosen

 
DOCTORGAD: Is there a code for opening a single trade with error checks? Exactly for real, not for test... Can as a function, just a deadlock :(

What's the use of checking mistakes - you have to react to them!!! How? Print("Error - ...") - this is good only during debugging. And even that would be better than Alert(). You have to react to an error by pause = delay. There was an article about it somewhere. But where? If someone saw it - remind me!

 
Timur1988:

The situation is that I need to create a universal function function_xy, in which the main program would understand that the name of the string variable object_xy changes depending on the parameters passed(..., ..., string x, string y). Otherwise, further down the code in function_xy() I'll have to manually spell out the name of variable object_xy.
For example,

Otherwise when creating several graphical objects in function_xy(), I'll have to manually assign parameters of graphical functions

There are up to 2 hundred of such functions, can you somehow reduce and solve this problem?
I hope I have expressed my thought.





//+------------------------------------------------------------------+
void OnStart()
  {

   function_xy();

  }
//+------------------------------------------------------------------+x1 x2 x3
void function_xy(string x="EURUSD",string y="GBPUSD")
  {
   string object_xy;
  string c = "object_EURUSDGBPUSD";
//Для начала,  склеим переданные в функцию строковые переменные 

   object_xy=StringConcatenate("object_",x,y);
   
   Alert("object_xy = ",object_xy);
   
// Cравниваем
   if(StringCompare(c,object_xy)==0)
     {
      Alert("       Ура получилось ))))))))");
      Alert("object_EURUSDGBPUSD == object_xy");
     }
//то есть здесь программа должна понимать, что это переменная object_EURUSDGBPUSD 
  }
//+------------------------------------------------------------------+

If I understand you correctly,

it goes something like this.

 
Ptichka12: Hello, a parenthesis drinks blood from me I can't pair it (it gives out a bunch of errors right away). The parenthesis in the first line.

Is that a decompile? Remove it immediately! It's forbidden here!!! Banned...

 
Ptichka12:

Hello, a parenthesis drinks blood from me I can't pair it (it gives out a bunch of errors right away). The parenthesis is in the first line.


You are warned for publishing decompiled code.
 
Artyom Trishkin:
You have been warned for posting decompiled code.

Sorry, I won't do it again...

 
Alexey Viktorov: it has to be completely rewritten. Who needs it?

Thanks)
To avoid rewriting, maybe you can overlay the trend lines on those segments that are >=100pts.

Can you tell me how to set the coordinates for the trendline points to plot it from the trough to the top of the zigzag -a.

 

Hello!

For a fortnight I've been working on a script that will check if the prices in the array are currently available for such an order....

Now I have come to a standstill while searching through the array. For some reason it's not giving out what's expected.


int start()
{
   while(!IsStopped())
    {    
      double prmas[5] = {11,22,33,44,99}; // Будем проверять каждую цену, есть ли ордер с такой ценой или нет
         for(int ordsel=0; ordsel<=4;ordsel++) {  // Цикл прохода по ценам в массиве
            for(int nmbr = 0; nmbr < OrdersTotal() ;nmbr++) {   // Проверяем каждую цену по всем ордерам
               int os = OrderSelect(nmbr, SELECT_BY_POS, MODE_TRADES); // Выбираем ордер по порядку цикла
               int maspos = ArrayBsearch(prmas,OrderOpenPrice(),5,0,MODE_ASCEND); //Ищем позицию цены в массиве по текущему проверяемому ордеру
               Alert ("Номер в цикле  ", nmbr, " Выбранный ордер  ", os, " Цена из массива ", prmas[maspos]); //Выводим скорбный результат
               Sleep(10000);  
      }
}
     if(!IsExpertEnabled()) break;
    }
return(nmbr);
}

it doesn't give out the wrong...

warrants:



 
Dimitry-1983:

Hello!

For a fortnight I've been trying to come up with a script that would check if the price in the array is now....

Now I got stuck on array search. For some reason, it doesn't give us what we expect.


It is correct:

ArrayBsearch

Returned value

Returns index of the first found element. If the sought value is not found, it returns the index of the closest by value element, between which the sought value is located.

You have the order prices (order by time of placing)
the first is 11,00000
the second 22.00000
third 0.98020
fourth 0.98004
fifth 33,00000

1, 2 and 5 respectively find correctly, but for 2 and 3 the nearest lower value...



Reason: