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

 
Maxim Kuznetsov:

What canon is this? there is an official doc - it's exactly like yours...everything else is just a fake.

1. it is worth to set serialization of all used arrays inside OnCalculate

2. Before entering the loop, put buff[length]=Bid+size; - you will get approximately what you want. A curved line and at the end a "visor" at Bid+size

3. Watch the array boundaries. Of course, rates_total < length, but you can't joke about it :-)

In other words, you must write ArraySetAsSeries in the beginning and then dance from there?

Oh yes, I've described it wrong. You need this line to go left on the chart and update it with each tick

 
YanSay:

Thank you very much for your detailed reply!

Following your advice I split branches and everything worked.

I faced a problem with simultaneous opening of 10-15 pending orders, I solved the problem by adding your code after it:

This is not a solution either. The order can be opened manually or by another EA. As a result, the EA being developed will not open anything. Therefore we need to count the number of orders opened by the Expert Advisor. Having this data, decide whether or not to open an order.

I am sure there is a better way.

With respect to your code, please explain what 1; i >=0; --i?

This is the standard order loop. OrdersTotal() is the number of orders. The orders are indexed starting from zero. So, if there is 1 order, its index will be 0, while the OrdersTotal() will return 1. Thus, the loop should start with the index, which is 1 less than the number of orders. We obtain OrdersTotal() - 1. The second operand is the condition of the loop body execution. In this case, the loop will terminate at i = -1. The third operand is the execution of loop jump to the next index (decrease by 1).

You can read about the loop operator in the documentation.

 
Ihor Herasko:

This is not an option either. The order can be opened manually or by another EA. As a result, the EA being developed will not open anything. Therefore we need to count the number of orders opened by the Expert Advisor. Having this data, we will have to make a decision whether or not to open an order.

I tried it this way but it started to open 10-15 orders per 1 signal again:

if ((OrdersTotal ()>0) && (OrderMagicNumber() != 100)) return;

The third operand is to move to the next index (decrease by 1).

So it is looking at all orders from the end?

 
YanSay:

Tried this, but it started opening 10-15 orders for 1 signal again:

So it's looking at all orders from the end?

To use the OrderMagicNumber() function, you should first select an order. The standard loop of collecting information about one's orders looks like this (for example, count the number of one's orders):

int nCnt = 0;    // Счетчик количества своих ордеров
for (int i = OrdersTotal() - 1; i >= 0; i--)
   {
      if (!OrderSelect(i, SELECT_BY_POS))
         continue;

      if (OrderSymbol() != Symbol())
         continue;

      if (OrderMagicNumber() != <значение ID ордеров эксперта>)
         continue;

      ++nCnt;
   }

After this code is executed, the variable nCnt will contain the number of the Expert Advisor's work orders.

 
Ihor Herasko:

I solve the problem as follows...


Thank you.

 
Ihor Herasko:

To use the OrderMagicNumber() function, you must first select an order. The standard cycle of collecting information about one's orders looks like this (e.g., count the number of one's orders):

After this code is executed, the variable nCnt will contain the number of working orders of the EA.

int nCnt = 0;    // Счетчик количества своих ордеров
for (int i = OrdersTotal() - 1; i >= 0; i--)
 {
  if (!OrderSelect(i, SELECT_BY_POS))
     continue;
  if (OrderSymbol() != Symbol())
     continue;
  if (OrderMagicNumber() != MagicNumber)
     continue;
  ++nCnt;
  {
   if (nCnt>0)
      return;
  }
 }

Thank you very much! It worked!

Could you advise whether ++nCnt is substitution of the obtained number of orders into the nCnt variable itself?

 
YanSay:

Thank you very much! It worked.

Can you tell me if ++nCnt is substituting the received number of orders into the nCnt variable itself?

In all such cases see documentation at once. ))

 
YanSay:

Thank you very much! It worked.

Can you tell me if ++nCnt is substitution of received number of orders into nCnt variable itself?

There is full documentation of the language, just have a look at the top menu of the site.

Don't be lazy to read it, it's impossible to keep everything in your head. Almost everyone, not only beginners, always manages it there.

Документация по MQL5: Основы языка / Операции и выражения / Арифметические операции
Документация по MQL5: Основы языка / Операции и выражения / Арифметические операции
  • www.mql5.com
Операция инкремента и декремента применяются только к переменным, к константам не применяются. Префиксныe инкремент (++i) и декремент (--k) применяются к переменной непосредственно перед использованием этой переменной в выражении. Могут возникнуть вычислительные проблемы при переносе вышеуказанного выражения из одной среды программирования в...
 
Artyom Trishkin:

There is full documentation on the language, just have a look at the top menu of the website.

Don't be lazy to read it - you can't keep everything in your head - it's always there for almost everyone - not just newbies.

Thank you. I'm not always sure which section to look in, I'm still not very good at it and F1 editor doesn't always send me to the right place)

I will try not to bother with stupid questions, thank you for your patience)

 
Roman Sharanov:

1. you mean to write ArraySetAsSeries in the beginning and then go from there?

Oh yes, I described it wrong. You want this line to go left on the chart and update with each tick

So draw a horizontal line.

Why do you need any buffers and their recalculation? ObjectSetDoubke(0,myHLine,OBJPROP_PRICE,concrete_price_value);

the user will see the line, you won't waste time recalculating the buffers, everyone is happy and disperses happily

PS/ get it right - indicator buffer, it's for transferring(sharing/sharing) the results of the calculations performed in the first place. Drawing a horizontal line of length N is different