OrderClose generating more orders

 
Hi people, how are you? I am trying to code an EA for MQL4 that closes an order if it is below or above the entry in some candle number, but when using OrderClose it generates more order?! Weird, orderclose sending more orders?
 
Marcos Gomes Artischeff: Weird, orderclose sending more orders?

On the next tick your condition is still true, count is zero, and you open another. Act on a change of signal.
          MQL4 (in Strategy Tester) - double testing of entry conditions - MQL5 programming forum #1 2017.12.12

 
William Roeder:

On the next tick your condition is still true, count is zero, and you open another. Act on a change of signal.
          MQL4 (in Strategy Tester) - double testing of entry conditions - MQL5 programming forum #1 2017.12.12

I don't know if correct, but the problem can be the loop for, right?

  for(int ci = OrdersTotal();ci >= 0;ci--)
  {
  if(OrderSelect(ci,SELECT_BY_POS,MODE_TRADES))
  {
 
Marcos Gomes Artischeff: I don't know if correct, but the problem can be the loop for, right?
  1. That loop selects all orders. You don't show what the loop is doing.
         How To Ask Questions The Smart Way. 2004
              Be precise and informative about your problem

    We can't see your broken code.

  2. That loop has nothing to do with what I guessed is your problem.
 
William Roeder:
  1. That loop selects all orders. You don't show what the loop is doing.
         How To Ask Questions The Smart Way. 2004
              Be precise and informative about your problem

    We can't see your broken code.

  2. That loop has nothing to do with what I guessed is your problem.

William, hello, how are you? Another thing I didn't understand is: the -1 in PositionsTotal(), sometimes, people uses -1 instead of purely PositionsTotal(), why?

 
Marcos Gomes Artischeff: Another thing I didn't understand is: the -1 in PositionsTotal(), sometimes, people uses -1 instead of purely PositionsTotal(), why?

If there are n items, their positions are [0 … n-1].

 
Marcos Gomes Artischeff:

William, hello, how are you? Another thing I didn't understand is: the -1 in PositionsTotal(), sometimes, people uses -1 instead of purely PositionsTotal(), why?

MQL5 has  PositionsTotal().

MQL4 doesn't as far as I know.

 
Keith Watford:

MQL5 has  PositionsTotal().

MQL4 doesn't as far as I know.

I forgot this section is for MQL4 only, sorry.

Reason: