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

 

Hi all!

I spent half the night trying to figure out why a simple condition does not work, please help me figure it out:

      macd1 = iMACD (_Symbol,PERIOD_CURRENT,5,34,5,0,1,0);
      macd2 = iMACD (_Symbol,PERIOD_CURRENT,5,34,5,0,1,1);
      highprice1 = High [0];
      highprice2 = High [1];
      lowprice1 = Low [0];
      lowprice2 = Low [1];
              if (macd1 > 0 && macd1 > macd2 && highprice1 > highprice2) 
                 {
                 maxprice1 = highprice1;
                 macdMAXSell = macd1;
                 Print("maxprice1 = highprice1",maxprice1);
                 }
              if (macd1 < 0 && macd1 < macd2 && lowprice1 < lowprice2)
                 {
                 minprice1 = lowprice1;
                 macdMAXBuy = macd1;
                 Print("minprice1 = lowprice1",minprice1);
          	 } 

I am running on historical data, the variables macd1,2, lowprice, highprice are assigned values, but the condition does not want to run, I broke my head can not understand where to dig ... (((

 
Nikolay Gaylis:

maybe 1 and 1 ?/i.e. true and error code 1

ERR_NO_RESULT1No error, but the result is unknown

Total mess and no understanding of what you are doing

bool takelimit;   // Здесь переменная равна false

//--- Здесь вот что: сначала выбирается ордер по тикету (MODE_TRADES здесь не нужно от слова "совсем", что говорит о том, что вы не представляете что вы делаете), 
//--- далее переменной takelimit присваивается результат работы функции выбора ордера, 
//--- и если ордер есть с таким тикетом, или был когда-то, то функция вернёт true, и takelimit будет присвоено true, соответственно, будет выведен код последней ошибки,
//--- что вовсе не говорит, что ошибка здесь была при выборе ордера по тикету - вы же переменную, хранящую код последней ошибки, не сбросили при помощи ResetLastError()
//--- И далее вообще не понятно к чему у вас фигурные скобки - они висят в пустоте, а это составной оператор, который должен после условия идти.

if(takelimit=OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
   Print(string(takelimit)+"   :",GetLastError());//здесь возвращает число 11, получается ошибка код 11, но не нашел расшифровку нигде?
  {
   if(iBarShift(Symbol(),0,OrderOpenTime())==1)
      deletelimit=OrderDelete(ticket);
   if(!deletelimit)
      Comment(GetLastError());
  }
//+------------------------------------------------------------------+
//--- А нужно примерно так (фигурные скобки специально оставил для понимания где какой блок кода):
   ResetLastError();
   if(OrderSelect(ticket,SELECT_BY_TICKET) && OrderCloseTime()==0)
     {
      if(iBarShift(Symbol(),PERIOD_CURRENT,OrderOpenTime())==1)
        {
         if(!OrderDelete(ticket))
            Print("Ошибка удаления ордера #",(string)ticket,": ",GetLastError());
        }
     }
   else
     {
      Print("Ошибка выбора ордера #",(string)ticket,": ",GetLastError());
     }
 
Вадим Мотеюнас:

Print(takelimit,GetLastError()) returns two values because the 1st variable is of bool type and does not need GetLastError, and since there is a comma, GetLastError returns the last error in the code at the time of calling GetLastError?

Yeah... there's two values that print.....

That's almost exactly what you wrote.

int ticket;

void Fn()
  {
   ResetLastError();//Сбрасываем код предыдущей ошибки
   if(!OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)){Print(GetLastError());}//Если не выбран ордер по указанному тикету-принтим код ошибки
   else//иначе(если ордер нашёлся)
     {
      if(iBarShift(Symbol(),0,OrderOpenTime())==1 && !OrderDelete(ticket)){Comment(GetLastError());}//Если выбранный ордер открылся на предыдущем баре и не удалось его удалить(надеюсь Вы работаете с отложенниками)-тогда выводим комент ошибки
     }
  }
 
Nikolay Gaylis:

Yes... there are two values to print.....

That's almost exactly what you wrote.

And so are you...
And if the order is already deleted, then what?
 
Artyom Trishkin:

A complete mess and a misunderstanding of what you're doing...

I'm not actually doing anything, I just assumed that the man will print 1 and 1 instead of 11))

and that's all...

 
Artyom Trishkin:

A complete mess and misunderstanding of what you're doing...

Ah... so you're responding to the wrong person... I see)

 
Nikolay Gaylis:

I'm not actually doing anything, I just assumed that the person will print not 11, but 1 and 1.)

Like this line here:

Print(string(takelimit)+"   :",GetLastError());

Should I print "11"?

It'll print "1:1" then.

The error code 1 is no error, but the result is unknown.

 
Artyom Trishkin:

Like this line here:

Can it print "11"?

It'll print "1:1" then.

The error code 1 is no error, but the result is unknown.

Yes, I've already changed it!

 
Nikolay Gaylis:

Ah... so you're responding to the wrong person... I see)

Yes, I was replying to the same person you were replying to. But you also told him the wrong thing - read when MODE_TRADES is required and when it is not. And how an order should be selected on a ticket.

 
Artyom Trishkin:

Well, yes, I was answering the same person you were answering. But you also have not told him everything correctly - read when MODE_TRADES is required and when it is not. And how to select an order by ticket.

MODE_TRADES hasn't looked at it yet, just the piece that 11 printed...

Reason: