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

 
Reworked a bit, now do while instead of the main for loop, but still no occurrence of the first condition in the second nested loop!
int GetMagic(Order &order)
{
  int magic = 0;
  int unique = 0;
  
  if(order.cmd == OP_SELLSTOP || order.cmd == OP_BUYSTOP){
    if(OrdersTotal()){
      do{
        magic++;
        for(int i = OrdersTotal(); i > 0 ; i --){
          if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
            Print( "!!!!!!!!!!!!!!!!!!!");//<----------НЕ ПРИНТУЕТСЯ
            if(magic != OrderMagicNumber())
              unique ++;
          }
        }
      }while(unique < OrdersTotal());
    }else return (magic + 1);
  }
  return magic;
}
 
MakarFX #:

Really?!))

Have you tried it?

I've had the colour change working that way for a long time, but not on the line, although it should make no difference

                     if(SymOpen < SymClose) {
                       CColor=Mirroring?BearBarColor:BullBarColor;
                        SetIndexStyle(32+(num*8),DRAW_HISTOGRAM,STYLE_SOLID,Mirroring?1:WidthOC,CColor); SetIndexLabel(32+(num*8), SubSymbol);
                        SetIndexStyle(33+(num*8),DRAW_HISTOGRAM,STYLE_SOLID,Mirroring?WidthOC:1,CColor); SetIndexLabel(33+(num*8), SubSymbol);
                        SetIndexStyle(34+(num*8),DRAW_HISTOGRAM,STYLE_SOLID,Mirroring?WidthOC:1,CColor); SetIndexLabel(34+(num*8), SubSymbol);
                        SetIndexStyle(35+(num*8),DRAW_HISTOGRAM,STYLE_SOLID,Mirroring?1:WidthOC,CColor); SetIndexLabel(35+(num*8), SubSymbol);

PS. Looked at my other code, it changes the colour of the line there

SetIndexStyle(num,DRAW_LINE,STYLE_SOLID,1,BullColor);
 
Vitaly Muzichenko #:

I've had a colour change working that way for a long time, but not on the line, although it should make no difference

PS. Looked at my other code, it changes the colour of the line

SetIndexStyle(num,DRAW_LINE,STYLE_SOLID,1,BullColor);

Changes the whole line, not the desired section

 
MakarFX #:

Changes the whole line, not the right section

Well, he wrote that you have to change the whole line

 
So, I've adapted the code for the test, try running it and you get an infinite loop on the second order :(
Files:
 
Nerd Trader #:
So, I've adapted the code for the test, try running it and you get an infinite loop on the second order :(

I wonder! Why?

Why this, what sacred meaning does it have?

int GetMagic(Order &order)
{
  int magic = 0;
  int unique = 0;
  
  if(order.cmd == OP_SELLSTOP || order.cmd == OP_BUYSTOP){
    if(OrdersTotal()){
      do{
        magic++;
        for(int i = OrdersTotal(); i > 0 ; i --){
          if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
            Print( "!!!!!!!!!!!!!!!!!!!");//<----------НЕ ПРИНТУЕТСЯ
            if(magic != OrderMagicNumber())
              unique ++;
          }
        }
      }while(unique < OrdersTotal());
    }else return (magic + 1);
  }
  return magic;
}

---

You're searching by number, so search by number.

If you have 2 warrants, he'll go through them, but he can't find the 3rd, or the 23rd.

---

You don't seem to be quite clear on the task, so that's the solution.

 
Nerd Trader #:

the loop is not set correctly:

for(int i = OrdersTotal(); i > 0 ; i --){

it should be like this:

for(int i = OrdersTotal()-1; i >= 0 ; i --){
 
Aleksei Stepanenko #:

the loop is not set correctly:

it should be like this:

Yes! It works! But why earlier still entered the second for loop and if I insert next line Print() - it will be executed (infinitely) but will not go further? Thanks anyway, now I can at least go to sleep.
 
Vitaly Muzichenko #:

I wonder! Why?

Why this, what sacred meaning does it have?

---

You're searching by number, so search by number.

If you have 2 warrants, he'll go through them, but he can't find the 3rd, or the 23rd.

---

You don't seem to be quite clear on the task, so that's the solution.

It's just that the majik must be unique, i.e. it must not have a match with the others.
 
Aleksei Stepanenko #:

the loop is not set correctly:

it should be like this:

What's the difference? And isn't order numbering from zero rather than one?

Reason: