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

 
Nikolay Gaylis:
Hello, could you please tell me how to show/remove a certain symbol programmatically in the "market overview" window?

See SymbolSelect function.

 

Good afternoon, could you please tell me where there might be an error in this code snippet?

 if (TotalMax_1<1)Step_1max=TotalMax_0;                                                  // Если расчетов еще небыло Step_1max=TotalMax_0
 else Step_1max=TotalMax_0-TotalMax_1;                                                   // Если расчеты уже были Step_1max=TotalMax_0-TotalMax_1
 
 for (i_1max=Step_1max;TotalMax_0>TotalMax_1;i_1max--)                                   // Главный цикл для заполнения массива Max_1
  {
   if (Max_0[i_1max]>Min_0[i_1max] && Stop_1max==0)                                      // Если максимум больше минимума и Stop_1max равен 0 нужно произвести расчет Максимального Индекса
    {
     Mmax_1=Max_0[i_1max];                                                               // Задается значение параметру Mmax_1
     MIndex_1max=i_1max;                                                                 // Задается значение параметру MIndex_1max
       
     for (i_1maxH=i_1max;Max_0[i_1maxH]>=Min_0[i_1maxH];i_1maxH--)                       // Цикл для расчета Максимального Индекса
       {
        if (Max_0[i_1maxH]>Mmax_1)                                                       // Если встречается максимум и он выше предыдущего
         {
          Mmax_1=Max_0[i_1maxH];                                                         // ... то меняется значение параметра Mmax_1
          MIndex_1max=i_1maxH;                                                           // ... и параметра MIndex_1max
         }
       }
       
     Stop_1max=1;                                                                        // Задается значение пераметру Stop_1max
    }
                                                                             
   if (i_1max==MIndex_1max)                                                              // Условие для вычисления максимума
    {
     Max_1[i_1max]=Mmax_1;                                                               // Присвоение значения массиву Max_1
     TotalMax_1=ArraySize(Max_1);                                                        // Всего баров в массиве Max_1
     }
        
   else                                                                                  // Если нет
      { 
       Max_1[i_1max]=0;                                                                  // Присвоение 0 значения массиву Max_1
       TotalMax_1=ArraySize(Max_1);                                                      // Всего баров в массиве Max_1
       }

   if (Min_0[i_1max]>Max_0[i_1max]) Stop_1max=0;                                         // Если минимум больше максимума задается значение пераметру Stop_1max
       
  }
 

Hi all, I am facing the following problem:

I open a trade without stoploss and takeprofit:

OrderSend("EURUSD",OP_BUY,0.1,Ask,0,0,0,"",Magic,0,Red);

I want to close this order

OrderClose(Magic,OrderOpenPrice(),Ask,0,Red);

I get this error: OrderClose error 131

If instead ofOrderOpenPrice() I point 0.1 or OrderLots() there is an error: OrderClose error 138

What is the problem?

 
labvic:

Hi all, I am facing the following problem:

I open a trade without stoploss and takeprofit:

I want to close this order

I get this error: OrderClose error 131

If instead ofOrderOpenPrice() I point 0.1 or OrderLots() there is an error: OrderClose error 138

What is the problem?

You close at the wrong price
 
Artyom Trishkin:
You're closing at the wrong price

Can you be more specific about what it should be? Thank you

 
labvic:

Can you be more specific about what it should be? Thank you

This is the basics.
Buy opens on Ask and closes on Bid.
Sell opens at Bid, closes at Ask
 

Good afternoon!

I have carefully read the tutorial about include files, and nowhere does it say that an include file cannot be "included" twice in the EA.

I have the first one "triggered", the second one (with the same name) is skipped/ignored.

What I do - I make a copy of the included file, add a letter/digit to the file name and in the EA line, and everything works.

Question: is it the mql4 language or me?

Thanks in advance!!!

 
Roni Iron:

Good afternoon!

I have carefully read the tutorial about include files, and nowhere does it say that an include file cannot be "included" twice in the EA.

I have the first one "triggered", the second one (with the same name) is skipped/ignored.

What I do - I make a copy of the included file, add a letter/digit to the file name and in the EA line, and everything works.

Question: is it the mql4 language or me?

Thanks in advance!!!

Why would you include the same thing twice in the listing?

If the include file has function f(), then by including it twice in your code, you will get a compilation error about already declared function f()

 
Artyom Trishkin:

Why would you include the same thing twice in your listing?

If there is an f() function in the include file, then including it twice in your code will result in a compilation error about an already declared f() function

If I use the include file not as a user-defined function, but as a "substitution"/insertion of a simple code fragment, for example, to search for the last order by its symbol (or presence of an order at all). And this search can be used in a program several times. And there can be a lot of such "classic operations".
 
Roni Iron:
If I use the include file not as a custom function, but as a "substitution"/insertion of a simple code fragment, such as search for the last order by my symbol (or presence of an order at all). And this search can be used in a program several times. And there can be a lot of such "classic operations".

This is where you get confused. There can be many such useful functions in a include file. Include the file once and use the available functions from the file.

Reason: