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

 

Good day !

The problem arose out of the blue, the Expert Advisor was working, no problems, but as soon as I inserted a new function (trailing stop), OrderSelect did not work in my entire EA and error 4051 ERR_INVALID_FUNCTION_PARAMVALUE - Invalid value of function parameters. At first I didn't understand it, I thought I may have changed something somewhere, I removed trailing stop and returned everything as it was, but OrderSelect still generates error.

Here is the code just in case:

         for(int i = OrdersTotal(); i > 0; i--)
           {
            if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true)
              {
               if(OrderType() == OP_SELL)
                 {
                  if(!OrderClose(OrderTicket(), Lots, Ask, slippage, clrRed))
                    {Print("Error Order Close SELL = ", GetLastError());}
                 }
              }
            else
              {Print("Error order select, try order close SELL = ", GetLastError());}
           }


 
Vitaliy Sendyaev:

Good day !

The problem arose out of the blue, the Expert Advisor was working, no problems, but as soon as I inserted a new function (trailing stop), OrderSelect did not work in my entire EA and error 4051 ERR_INVALID_FUNCTION_PARAMVALUE - Invalid value of function parameters. At first I didn't understand it, I thought I may have changed something somewhere, I removed trailing stop and returned everything as it was, but OrderSelect still generates error.

Here is the code just in case:



This is not the full code. Most likely a parenthesis was removed somewhere.
 
Vitaliy Sendyaev: OrderSelect generates error 4051 ERR_INVALID_FUNCTION_PARAMVALUE - Invalid value of a function parameter

Here is the code just in case: for(int i = OrdersTotal(); i > 0; i--)

we need for (int i = OrdersTotal() -1; i>=0; i--) the orders are numbered starting from zero, so the largest number is 1 less than the number

 
STARIJ:

we need for (int i = OrdersTotal() -1; i>=0; i--) the orders are numbered from zero and therefore the highest number is 1 less than the number

Exactly! I didn't notice that... I need more sleep


 
STARIJ:

We need for (int i = OrdersTotal() -1; i>=0; i--) the orders are numbered from zero and therefore the highest number is 1 less than the number


Thank you !

 
Valerius:

This is not serious... What are they (input and extern) for then....

What's not serious about it? You asked a question in the code branch and got an appropriate answer.
Well, if you have not thought to restart the terminal, you have already been answered - servicedesk.

 
Valerius: What do I do if, for example, I set the settings in the EA today, then on the next day some of the settings are blank?

It's hard to guess how you did that. I don't want to show you the code of the Expert Advisor, and I'm too lazy to look through it all. Make a copy under a different name, delete everything except parameters and empty function OnTick (or Start ???). Is the effect still there? Show the resulting code

 
Vitaliy Sendyaev: Thank you !

Did it help? How did it work before?

 

I'm sorry, but I don't understand why oncalculate should pass values of predefined variables if they are global and also available

 
ijonhson:

Hello, I want to make an EA based on an indicator, I copied the indicator code into ontick, I'm missing the variables from the onCalculate function, I need to get it all through copytime copyhigh copylow, etc. or is there an easier and faster way?

iCustom to the rescue

iCustom - Технические индикаторы - Справочник MQL4
iCustom - Технические индикаторы - Справочник MQL4
  • docs.mql4.com
[in] input-параметры пользовательского индикатора, разделенные запятыми. Тип и порядок следования параметров должен соответствовать. Если параметры не указаны, то будут использованы значения по умолчанию.
Reason: