Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 1155

 
int    total=OrdersTotal();      
for(int i=0;i<total;i++)
        {
         Print("i=",i);
         if(!OrderSelect(i,SELECT_BY_POS))
           {
            Print("order not selected. Error=",GetLastError());
            continue;
           }
         if(OrderMagicNumber()!=magic_number)
           {
            Print("magic number not correct.");
            continue;
           }
         if(OrderSymbol()!=Symbol())
           {
            Print("symbol not correct.");
            continue;
           }
         if(OrderType()!=OP_SELL)
           {
            Print("order type not correct.");
            continue;
           }
         if(OrderCloseTime()>0)
           {
            Print("order close time not correct.");
            continue;
           }
         if(!OrderClose(ticket,lots,price,slippage,clrClose))
              {
               Print("order Sell with ticket=",ticket,", was not closed. Error=",GetLastError());
              }
            else
              {               
               Print("order Sell with ticket=",ticket,", was closed.");
              }
        }

Why am I getting a 4051 error in OrderSelect()? First open order is closed correctly, on second order not selected. Error=4051. Valid value 2 in total.

 
igorbel:

Why am I getting a 4051 error in OrderSelect()? First open order is closed correctly, on second order not selected. Error=4051. Valid value 2 in total.

When deleting and closing, the loop should be reversed:

for(int i=total-1;i>=0;i--)
 
igorbel:

Some wondrous bug or other.

Adding in the inputs:

input datetime test                                =0;

Compile. With date 1970.01.01 zero, it is not possible to set the hour to 00, 01 or 02 in the settings.

input variable cannot be changed in the EA
extern variable - yes

 
Taras Slobodyanik:

The input variable cannot be changed in the EA
the extern variable - you can


Not in the EA code. In the input parameters window, when you attach the EA to the chart.

 
Artyom Trishkin:

The cycle should be reversed when deleting and closing:


thank you

 

Good afternoon, please help with these questions (2):

1. Is there such an EA, save the results of testing by history in an excel file. For example, I have tested an EA and want to get the parameters of the EA, there profit, type of trade, result, DAYS OF THE WEEK and so on.

I would also like to know how to do detailed analysis or share my experience on how you test an EA and see if it is worthwhile or total crap.

2. How do I pass an array or structure to a function? I.e. I have a lot of variables, I add these variables to a structure and pass it to a function.

Then I open this structure in this function and get the variables I need. This is done to avoid "dragging" all values of variables into a function (for convenience).

Thank you.

 
rabanik:

Good afternoon, please help with these questions (2):

1. Is there such an EA, save the results of testing by history in an excel file. For example, I have tested an EA and want to get the parameters of the EA, there profit, type of trade, result, DAYS OF THE WEEK and so on.

I would also like to know how to do detailed analysis or share my experience on how you test an EA and see if it is worthwhile or total crap.

2. How do I pass an array or structure to a function? I.e. I have a lot of variables, I add these variables to a structure and pass it to a function.

Then I open this structure in this function and get the variables I need. This is done to avoid "dragging" all values of variables into a function (for convenience).

Thank you.

The answer is here.

//+------------------------------------------------------------------+
//| передача параметров по ссылке                                    |
//+------------------------------------------------------------------+
double SecondMethod(int &i,int &j)
  {
   double res;
//---
   i*=2;
   j/=2;
   res=i+j;
//---
   return(res);
  }
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   int a=14,b=8;
   Print("a и b перед вызовом:",a," ",b);
   double d=SecondMethod(a,b);
   Print("a и b после вызова:",a," ",b);
  }
//+------------------------------------------------------------------+
//--- результат выполнения скрипта
//  a и b перед вызовом: 14 8
//  a и b после вызова: 28 4
Передача параметров - Функции - Основы языка - Справочник MQL4
Передача параметров - Функции - Основы языка - Справочник MQL4
  • docs.mql4.com
Передача параметров - Функции - Основы языка - Справочник MQL4
 

Dear Sirs!

Please help me to understand the problem.

I used a switch(int err) operator

got a message

int ErrorDescription()

{

Alert("beg ErrorDescription")


switch(err)

{

case 0: err="No error"; break;

case 1: err="No error, but result unknown"; break;

case 2: err="General error"; break;

case 3: err="Wrong parameters";

what's the matter, can't figure out where semicolon should be? It's not clear...

 
buyanov:

Dear Sirs!

Please help me to understand the problem.

I used a switch(int err) operator

got a message

int ErrorDescription()

{

Alert("beg ErrorDescription")


switch(err)

{

case 0: err="No error"; break;

case 1: err="No error, but result unknown"; break;

case 2: err="General error"; break;

case 3: err="Wrong parameters";

what's the matter, can't figure out where semicolon should be? It's not clear...

Have you looked after Alert()? Where is ";" ?

int ErrorDescription()
  { 
   Alert("beg ErrorDescription");   // где у вас ";" ???
   switch(err)
   {    
      case 0:   err="Нет ошибок";                                                     break;
      case 1:   err="Нет ошибки, но результат неизвестен";                            break;
      case 2:   err="Общая ошибка";                                                   break;
      case 3:   err="Неправильные параметры";        
And why do you give the function a fragment?
 
Artyom Trishkin:

Have you looked after Alert()? Where is the ";" ?

And why are you giving me a fragment of the function?

It didn't seem to be after Alert... And now it's there, or I put it there somewhere in the process and didn't notice it myself.

Thanks anyway.

The problem is solved. Thanks again, Artyom.

Reason: