EA mixes BUY and SELL orders - page 2

 

Without knowing the entire ea and how you're using it, we'll just be guessing as to what's wrong. Assuming that it's selecting a correct order to pass this statement.

while (!OrderSelect(cnt, SELECT_BY_POS)) {Sleep(500);}

there's no way it'll get pass:

if ((orderType == OP_BUY || orderType == OP_BUYSTOP)) {

if its Op_Sell. Unless you have this thing on multiple charts of the same Symbol.

Seeing that you're using a contentious while loop. This is probably some form of Rapid Order Maker.

My final guess. The selected order changes after the Ordertype check :)

Anything else, I suggest like Raptor that you utilize allot of print statements.

 
  1. The selected order can NOT change after the orderSelect.
  2.  for(cnt = total-1; cnt >= 0; cnt--)  {
          while (!OrderSelect(cnt, SELECT_BY_POS)) {Sleep(500);}
    if the orderSelect fails it will continuously fail and you have an infinite loop. If several orders close on another chart while you are updating yours, the next iteration's select will fail. Very dangerous.
 

I've printed the Ticket number and it doesn't match with the OrderType().


If the selected order is of type OP_BUY, the correct if will be processed, but then in my OrderModify(...) call, I pass OrderTicket() as the first parameter, but it is the ticket of an other order.


Any idea?

 
dvarrin:

Any idea?

Maybe you are trying to Modify an order that is already closed ? you aren't specifying a pool that you are Selecting your trades from . .

OrderSelect( int index, int select, int pool=MODE_TRADES) 
MODE_TRADES (default)- order selected from trading pool(opened and pending orders),

MODE_HISTORY - order selected from history pool (closed and canceled order).


	          
 
RaptorUK:

Maybe you are trying to Modify an order that is already closed ? you aren't specifying a pool that you are Selecting your trades from . .

MODE_TRADES (default)- order selected from trading pool(opened and pending orders),

MODE_HISTORY - order selected from history pool (closed and canceled order).


I tried that too, but it didn't change anything. It seems that I've to store all the data of the selected order I want to use:


int ticket=0;

double SL = 0.0;

OrderSelect(cnt, ...);

ticket = OrderTicket();

SL = OrderStoploss();

if (OrderType() == OP_BUY) {


}


...


Why is it so? I don't understand what is wrong in my code so that OrderTicket() doesn't correspond with the same order that the OrderType() is refering to.

 
dvarrin:

I've printed the Ticket number and it doesn't match with the OrderType().


If the selected order is of type OP_BUY, the correct if will be processed, but then in my OrderModify(...) call, I pass OrderTicket() as the first parameter, but it is the ticket of an other order.

Is it the next order in sequence, is it the previous order in sequence ?
 

orderType = OrderType()

change to

int orderType = OrderType(); and delete the original declaration.

 
forexCoder:

orderType = OrderType()

change to

int orderType = OrderType(); and delete the original declaration.


OrderType is ok. It is the OrderTicket() which is not the ticket of the right order.
 

I would encourage you to find out what is causing your problem rather than coding around it . . .

Software engineering is all about problem solving, it's how we learn and get better. I'm on my 3rd attempt since Saturday at coding a particular problem to do with Fibs, I'm almost there . . . careful use of the Print() function helps a lot . . .

 
dvarrin:

OrderType is ok. It is the OrderTicket() which is not the ticket of the right order.

int OrderType = OrderType() is not ok, one may be hiding the other (local declarations hide globals with no error.) Try

int orderType = OrderType()

Reason: