Last Order being missed in a for loop - page 2

 
Alain Verleyen:

I don't keep anything, I said you the problem.

Do your homework, debug your code and stop whining.

Dude, if you dont want to help, dont get involved with useless comments. If you dont feel like talking or helping simply dont react, and also dont get offensive.

 
Stanislav Ivanov:

Dude, if you dont want to help, dont get involved with useless comments. If you dont feel like talking or helping simply dont react, and also dont get offensive.

As it seems I have to explain the obvious, here it is :

void Breakeven()
  {
   for(int i=OrdersTotal()-1;i>=0;i--)  // OrdersTotal=2, ticket 100 and 101 to say something
     {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))   // i=1, ticket 101 selected (count down)
         continue;
      if(OrderMagicNumber()==magic && OrderSymbol()==Symbol())
        {
         if(OpenPositions()==2 && OrderStopLoss()!=openlevel)   // call to OpenPositions(), see below...now ticket 100 is selected ALWAYS.
           {
            bool modify=OrderModify(OrderTicket(),OrderOpenPrice(),openlevel,OrderTakeProfit(),0);
            if(!modify){Print("Order ",OrderTicket()," not modified ,op2,,error ",GetLastError());}
            else{Print("Order ",OrderTicket()," modified !");}
            Print("--------");
           }

         if(OpenPositions()==1 && OrderStopLoss()!=level1)
           {
            bool modify=OrderModify(OrderTicket(),OrderOpenPrice(),level1,OrderTakeProfit(),0);
            if(!modify){Print("Order ",OrderTicket()," not modified,op1 ,error ",GetLastError());}
            Print("++++++++");
           }
        }
     }
  } 

int OpenPositions()
  {
   int cnt=0;
   for(int i=OrdersTotal()-1;i>=0;i--)   // OrdersTotal = 2, tickets 100 and 101
     {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))   // Order select 101 (index = 1)  then 100 (index = 0)
         continue;
      if(OrderMagicNumber()==magic && OrderSymbol()==Symbol())
        {
         cnt++;
        }
     }
   return cnt;  // At the end ticket 100 (index 0) was last selected.
  }

If you had used the debugger and/or added print statement to debug your code, you would have seen that by yourself. Aren't you a freelancer ?

And please don't call me "dude".

 
Alain Verleyen:

As it seems I have to explain the obvious, here it is :

If you had used the debugger and/or added print statement to debug your code, you would have seen that by yourself. Aren't you a freelancer ?

And please don't call me "dude".

Oh, I got it now.

Listen, I did printing , checking, debugging and wrote only after i didnt understand  what was the reason  I do now. My "dude" comment was simply in return to your "whining".

Yes, i may be a freelancer, but i am also learning, I thought this was obvious.

Still, thanks for the help

 
Stanislav Ivanov:

Oh, I got it now.

Listen, I did printing , checking, debugging and wrote only after i didnt understand  what was the reason  I do now. My "dude" comment was simply in return to your "whining".

Yes, i may be a freelancer, but i am also learning, I thought this was obvious.

Still, thanks for the help

That's ok. Sometimes I am not patient enough.
Reason: