what's wrong?

 
  for(i=OrdersTotal()-1; i >=0 ; i--)
                        {
                        if(OrderSelect(i, SELECT_BY_POS,MODE_TRADES)==true)
                        
                         {if ((OrderType() == ((OP_BUYSTOP) ||(OP_SELLSTOP))))
                        OrderDelete(OrderTicket());
                         }
                       
                       } 
i get a error 4108. why is the orderticket invalid?
 
yuan83:
i get a error 4108. why is the orderticket invalid?


What was the ticketnumber you send you get error 4108 ??

What OrderType() did this ticket have ??

 Can you tell us ??

 
yuan83:
i get a error 4108. why is the orderticket invalid?
((OP_BUYSTOP) ||(OP_SELLSTOP)))  is equal 1, so you select OrderType()==1 (OP_SELL)

and you can't delete a market order.

Try this :

for(i=OrdersTotal()-1; i >=0 ; i--)
{
    if(OrderSelect(i, SELECT_BY_POS,MODE_TRADES)==true)
    {
        if (OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP)
            OrderDelete(OrderTicket());
    }
                       
} 
 
angevoyageur:

and you can't delete a market order.

Try this :

a little mistake in your explanation
((OP_BUYSTOP) ||(OP_SELLSTOP)))  is equal 1, so you select OrderType()==1 (OP_SELL)

This is giving output true or false  so possible value can be also 0,    then it will not be you have select OP_BUY

and if the outcome is 1, then also the selected OrderType( ) you try to delete can be different from  ( OP_SELL ) 

 
deVries:
a little mistake in your explanation

This is giving output true or false  so possible value can be also 0,    then it will not be you have select OP_BUY

and if the outcome is 1, then also the selected OrderType( ) you try to delete can be different from  ( OP_SELL ) 


I don't agree, why :

OP_BUYSTOP is a constant which is equal 4, OP_SELLSTOP is 5. So we have :

(4 || 5) which is ALWAYS true, and true is 1.

See documentation : 

Logical operation OR (||) of x and y values. The expression value is TRUE (1) if x or y value is true (not null).

Someone once said : "AS you can see good reading gives you the answer  and sometimes i have trouble with it"  ;-)

 
angevoyageur:

I don't agree, why :

OP_BUYSTOP is a constant which is equal 4, OP_SELLSTOP is 5. So we have :

(4 || 5) which is ALWAYS true, and true is 1.

See documentation : 

Someone once said : "AS you can see good reading gives you the answer  and sometimes i have trouble with it"  ;-)

From your link   See documentation : 

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


Logical operation OR (||) of x and y values. The expression value is TRUE (1) if x or y value is true (not null). Otherwise, it is FALSE (0). Logical expressions are calculated completely, i.e., the so-called "short estimate" method does not apply to them.

if(x<0 || x>=max_bars) Print("out of range");

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Means  Logical operation OR (||) outcome can only be 0 (false) or 1 (true)

((OP_BUYSTOP) ||(OP_SELLSTOP)))  is always equal to 1, so you select OrderType()==1 (OP_SELL)   You are right

and only if the selected OrderType was Sell trade the funtion

if ((OrderType() == ((OP_BUYSTOP) ||(OP_SELLSTOP))))OrderDelete(OrderTicket());

will return OrderDelete error 4108    EURUSD,H1: market order #2 cannot be deleted


if we get output 1  it means  (4 || 5) which is ALWAYS true, and true is 1.

So  

if ((OrderType() == ((OP_BUYSTOP) ||(OP_SELLSTOP))))

can be rewritten as

if ((OrderType() == ((true))))

 

 or 

if ((OrderType() == ((1))))

 and the selected OP_BUYSTOP   or the selected OP_SELLSTOP   is not deleted

 Hope With this explanation you do agree ???

overlooked one thing so i edit this post    if x or y value is true (not null)

 

Ok, sorry, seem like a communication problem because my english is not so good. When I write "so you select OrderType()==1 (OP_SELL)", actually I meant that the "if test" is always checking OrderType==1. This has nothing to do with selecting order. And I misunderstood your point, thinking that you were saying that "((OP_BUYSTOP) || (OP_SELLSTOP))" could be 0.

 
angevoyageur:

Ok, sorry, seem like a communication problem because my english is not so good. When I write "so you select OrderType()==1 (OP_SELL)", actually I meant that the "if test" is always checking OrderType==1. This has nothing to do with selecting order. And I misunderstood your point, thinking that you were saying that "((OP_BUYSTOP) || (OP_SELLSTOP))" could be 0.


It is not English it is the programming  you have to learn to understood to see what happens

first you have an orderselect gives a ordertype ( ) 

(   ||   )     true or false

== (    ||   )   means this way OrderType() equal to ....  0 or 1

and only if ordertype is equal the funtion     OrderDelete(OrderTicket())   will go to broker

this error i made myself also in the past

but searching why it failed i learned to understand the logic behind this

 about your coding return codes !!

bool result;

for(i=OrdersTotal()-1; i >=0 ; i--)
   {
    if(OrderSelect(i, SELECT_BY_POS,MODE_TRADES)==true)
    {
     //---- pending stop orders only are considered
        if (OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP)
           {
            //---- print selected order
            OrderPrint();   //if you like to print this also
            //---- delete first pending order
            result=OrderDelete(OrderTicket());
            if(result!=TRUE) Print(OrderTicket()," ",OrderType(),"  LastError = ", GetLastError());
           }          
    }
   else { Print( "Error when order select ", GetLastError()); break; }                    
} 

 

 something like this 

 

I responded to the initial question only : " why is the orderticket invalid?". Obviously if the code inside the "if" is not run there will be no errors. This is not my code, only the correction of the problem.


You (and others) you assign yourself the task of teaching others to program, while a forum is to answer questions.

 
angevoyageur:

I responded to the initial question only : " why is the orderticket invalid?". Obviously if the code inside the "if" is not run there will be no errors. This is not my code, only the correction of the problem.


You (and others) you assign yourself the task of teaching others to program, while a forum is to answer questions.

the explanation you gave by  the correction of the problem was in my opinion wrong !!!!

the code you gave will also not answer the questions I asked the OP

If the OP was using printstatements in the returncoding

then he was able to answer my questions. With his code and your code he is not !!! 

  What are Function return values ? How do I use them ?

 
angevoyageur:

I responded to the initial question only : " why is the orderticket invalid?". Obviously if the code inside the "if" is not run there will be no errors. This is not my code, only the correction of the problem.


You (and others) you assign yourself the task of teaching others to program, while a forum is to answer questions.

IMO a Forum is  place where the users can help each other,  sometimes that is a simple answer to a question, sometimes it is a more expanded reason for the answer,  sometimes it is questions to help the poster to understand.
Reason: