What is Wrong with this code? - page 2

 
RaptorUK:

OK, what is wrong with that ? if there are no open orders an order can be opened . . . ( openbuy = true ) if there are orders the next block of code is run, it loops through the open orders and checks the symbol and the magic number, so if it finds and open order that has a match on the symbol and magic number no trade can be opened ( openbuy = false )

Am I missing something ?

The problem is, if there's already an opened order we never know the state of openbuy, is it true or false - whether it's a local or global variable . This is his code, I comb it a little, I gave investguy a clue so that his code will be similar like yours. Tell me, what the state of variable openbuy if there already opened position ?. Whether this variable local or global.

  { 
  Print("openbuy true"); 
  Ototal = OrdersTotal();
  if(Ototal == 0)
  {
  openbuy=true;
  }
  else
  {
   for(cnt = 0; cnt < Ototal; cnt++)
      {
       //Print("Order select");
       OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);   
       if(OrderSymbol() == Symbol() && OrderMagicNumber() == magic)
        {
        Print("opensbuy false");
         openbuy=false;
        }
      }
   }
 }
 
onewithzachy:

The problem is, if there's already an opened order we never know the state of openbuy, is it true or false - whether it's a local or global variable . This is his code, I comb it a little, I gave investguy a clue so that his code will be similar like yours. Tell me, what the state of variable openbuy if there already opened position ?. Whether this variable local or global.

ok, let me clarify this, sorry guys.

Take a look at this code.

bool openbuy=false;bool opensell=false;
               
 {
                Print("Openbuy 1 true");
                for(cnt = 0; cnt < OrdersTotal(); cnt++)
                        {
                        Print("Order select - BUY");
                        if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) && (OrderSymbol() != Symbol()))
                                {
                                        Print("Openbuy 2 true");
                                        openbuy=true;   
                                        break;
                                }
                }

I already checked for the output of Print("Openbuy 1 true"); and it shows up on mt4. The second one doesn't... =\

 
investguy:

... and it shows up on mt4. The second one doesn't... =\

Might be coz of this ... ???. BTW, use RaptorUK's code

(OrderSymbol() != Symbol()))
 
RaptorUK:
Read the rest of the code . . .

allright I see it.... not used to this...
 
onewithzachy:

Might be coz of this ... ???. BTW, use RaptorUK's code


ok, ill do it. let you guys know the result.
 

RaptorUK's code did the job very well =]

Thank you all for the help
 

This is very simple problem which actually investguy created and actually can be solved by himself. Let's imagine this, MetaTrader is opened and there is no trades opened.

The first EA attached to the chart. This code runs well and open order ...

{ 
  Print("openbuy true"); 
  Ototal = OrdersTotal();
  if(Ototal == 0)
  {
  openbuy=true;
  }
  

Second same EA attached to different symbol, That code above gives no buy signal !!!. And that's why investguy came to us saying ...

. Currently it only opens one order at a time. What i want to happen is that the ea will only open 1 order per symbol .

No wonder ...