[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 348

 
FAQ:
Why don't you remember the ticket of the order and not its position. and what happens in a direct transfer if there is no such order? will you delete the zero order?


I already tried it. This does not work either:

//+-------------------------------------------------------------------------------------+
//| Удаление несработанных отложеннык шортов                                            |
//+-------------------------------------------------------------------------------------+
void DeletePendingSells(int& amountOfCurrPending)
{
   int total = OrdersTotal() - 1,
       ordersToDelete = level - amountOfCurrPending,  // Количество отложек, которые требуется удалить
       s_ticket = 1,                                  // Тикет искомого ордера
   amountOfCurrPendingBuys = 0;                       // Количество текущих отложек на покупку
   amountOfCurrPendingSells = 0;                      // Количество текущих отложек на продажу

   double OOP = 20.0;                                  // Зададим значение цены открытия отложки, которой не может быть..
   
   if (ordersToDelete == 0) return (0);

   for (int i=total; i>=0; i--)
   {
      if (!OrderSelect(i,SELECT_BY_POS)) continue;
      if (OrderSymbol() != Symbol()) continue;
      if (OrderMagicNumber() != i_magic) continue;
      if(OrderType() != OP_SELLSTOP) continue;         // Работает только с шортовыми ордерами
      
      if (OOP > OrderOpenPrice())
      {
          OOP = OrderOpenPrice();                  // Ищется ордер, с минимальной ценой открытия
          s_ticket = OrderTicket();                // Получаем тикет ордера с минимальной ценой открытия
      }
   }
   if (s_ticket != -1)
   {
      OrderDelete(s_ticket,Black);
   }
   return (0);
}
 
hoz:


I've tried this before. This doesn't work either:

You have to be more careful.
//+-------------------------------------------------------------------------------------+
//| Удаление несработанных отложеннык шортов                                            |
//+-------------------------------------------------------------------------------------+
void DeletePendingSells(int& amountOfCurrPending)
{
   int total = OrdersTotal() - 1,
       ordersToDelete = level - amountOfCurrPending,  // Количество отложек, которые требуется удалить
       s_ticket = 1,                                  // Тикет искомого ордера
   amountOfCurrPendingBuys = 0;                       // Количество текущих отложек на покупку
   amountOfCurrPendingSells = 0;                      // Количество текущих отложек на продажу

   double OOP = 20.0;                                  // Зададим значение цены открытия отложки, которой не может быть..
   
   if (ordersToDelete == 0) return (0);

   for (int i=total; i>=0; i--)
   {
      if (!OrderSelect(i,SELECT_BY_POS)) continue;
      if (OrderSymbol() != Symbol()) continue;
      if (OrderMagicNumber() != i_magic) continue;
      if(OrderType() != OP_SELLSTOP) continue;         // Работает только с шортовыми ордерами
      
      if (OOP > OrderOpenPrice())
      {
          OOP = OrderOpenPrice();                  // Ищется ордер, с минимальной ценой открытия
          s_ticket = OrderTicket();                // Получаем тикет ордера с минимальной ценой открытия
      }
   }
   if (s_ticket != -1)
   {
      OrderDelete(s_ticket,Black);
   }
   return (0);
}
 

It's finally working! It worked, in principle, and the previous version. The main bug was in the function call, not in the function itself.

From a professional's point of view, all variables should be zeroed when entering a function, unless they are static, i.e. there is no need to keep their value specific, right?

 
hoz:

It's finally working! It worked, in principle, and the previous version. The main bug was in the function call, not in the function itself.

From the point of view of a professional, all variables should be zeroed when entering a function, unless they are static, i.e. there's no need to keep their value specific, right?

Initialise the variables in the function with values that will not cause the function to malfunction and the hardest to find errors.

I usually use either 0 or -1, depending on the purpose of the variable. If the variable in the function will store the position index found, then initialize it to -1. If you initialize it to zero, then after looking for the right position and its absence, you can still choose the position with index 0, although it will not be the position you are looking for. At -1 the position will not be chosen. This is one of all possible examples of where an error is hard to find - everything seems to be correct in the function, but the output is totally wrong... and the EA does not work with the order/position we expected...

 

A function must be short (optional, but desirable) and perfectly clear (its purpose). like 2*2=4. i.e. the programmer must clearly understand what it is for and what operation it performs. then he should put it out of his mind and forget what it has inside, and use it as a "black box".

All variables used by a function must be passed to it as arguments. Using global variables without passing them as arguments is justified only if they are, for example, Externs (in the case of MT). Changing globals in a function is unacceptable, if one return value is missing, pass the variables by reference in the argument list.

That is, if you have to throw out this function, then you don't have to remember why the stripped down version doesn't work because any globals in this function have been modified. All this aims to ensure that if you have to redo it, it will not cause a chain reaction

 

Hi all!

Testing Pound-En.

The order should have closed at TAKE PROFIT earlier than STOP LOSS.

But my order didn't close on Take Profit for some reason.

QUESTION: WHY DIDN'T MY ORDER CLOSE AT TAKE PROFIT AS PRESCRIBED IN THE TRADING FUNCTION?

Modeling method - all ticks.

Example in the link

http://clip2net.com/s/55pdDU

NOTE.Such cases - do not happen often.In most cases, trades are closed at 10 pips stop. in time.

I.e., it seems to me it probably has nothing to do with the minimum acceptable distance between the price and the stop.

What else may be the reason?

Thank you.

 

Help to take data into global variables from an indicator

approximately:

USD 6.5

EUR 6.6

GBP 3.3

etc.

Thanks in advance for your help !

/*Decompilation removed. Warning*/.

 
FAQ:

A function must be short (optional, but desirable) and perfectly clear (its purpose). like 2*2=4. i.e. the programmer must clearly understand what it is for and what operation it performs. then he should put it out of his mind and forget what it has inside, and use it as a "black box".

All variables used by a function must be passed to it as arguments. Using global variables without passing them as arguments is justified only if they are, for example, Externs (in the case of MT). Changing globals in a function is unacceptable, if one return value is missing, pass the variables by reference in the argument list.

That is, if you have to throw away this function, then you don't have to remember why the stripped down version doesn't work because any globals in this function have been modified. All this is intended that if I have to redo it, it will not cause a chain reaction


Thank you, and, Artem, of course! You opened my eyes to those points, which are logical in principle, but sometimes my lack of experience left unnoticed.

There are just some other misunderstandings. You wrote that if there are global variables in EA, they should be used in functions only by passing them as arguments, right?

I'm just trying to understand, are there any reasons to create global variables (not externs)... If they must be passed only through arguments, a long chain of dependent functions can collect a lot of arguments, and the names of functions with arguments will be very long.

And again, you can create a global variable, pass it into a function by reference and do whatever you want with it, and return it by reference back to global, right?

When I read your post today, I started thinking about it and transferred some variables from global to a function. Then I realized that these variables are needed in another function, which is not related to the function where I declared them. If you listen to you here: "Changing globals and the function is not acceptable", then it turns out that the function that directly gets the required variables should be called in different places? But it already makes the code, so to say, not nice. You want the function to be called when it's needed and not more often than it's needed. For example, the function that searches for all orders, buy and sell orders. It is reasonable to suppose that it should be called only once per tick and no more than once. But if it is called at the start, not every function that uses these variables returned by the order search function can be passed through its parameters. Then we still return to the global variables, or what?

 

Please help to solve the problem with the shift value limit in iHigh(Symbol(),timeframe,shift), which is limited to the number 1000.

iTime(Symbol(),timeframe,1001) gives 1970.01.01 00:00
 
How the hell do you turn off the alert ???????? why after pressing the space bar, it ?(!%"?:? keeps beeping ??????????
Reason: