Why EA didn't send any orders?

 
Please give me a prompt if you know why this isn't runs when I add it as a strategy in my panel.
I want it to check if any order is on the market. If not it should send pending orders.
I think that the problem is in form or coding.
int start() { 



double ABUY=0;
double ASELL=0;
double BBUY=0;
double BSELL=0;
double point = MarketInfo(Symbol(),MODE_POINT);
double expiration=CurTime()+PERIOD_D1*60;
int n;
int total= OrdersTotal();
for( n=0; n<total; n++ ){ // count how many open orders we have
if( OrderSelect(n,SELECT_BY_POS,MODE_TRADES) )
continue;


if( OrderSymbol()==Symbol() )
continue;
if( OrderMagicNumber()== 1  &&  OrderType()== OP_BUY ){ //check if this order exists
ABUY=2; // it's a BUY order //if order exists - change variable
}
else if( OrderMagicNumber()== 1  &&  OrderType()== OP_BUYSTOP ){
ABUY=1; // it's a BUY pending order
}
else if( OrderMagicNumber()== 2  &&  OrderType()== OP_SELL ){ //check if another order exists
ASELL=2; // it's a SELL order //if this order exists - change variable
} 
else if( OrderMagicNumber()== 2  &&  OrderType()== OP_SELLSTOP ){
ASELL=1; // it's a SELL pending order
} 
else if( OrderMagicNumber()== 3  &&  OrderType()== OP_BUY ){ //etc.......
BBUY=2; // it's a BUY order
}
else if( OrderMagicNumber()== 3  &&  OrderType()== OP_BUYSTOP ){
BBUY=1; // it's a BUY pending order
}
else if( OrderMagicNumber()== 4  &&  OrderType()== OP_SELL ){
BSELL=2; // it's a SELL order
} 
else if( OrderMagicNumber()== 4  &&  OrderType()== OP_SELLSTOP ){
BSELL=1; // it's a SELL pending order
}
else {
       OrderSend(Symbol(),OP_BUYSTOP,0.1,Ask+6*point,4,Bid-52*point,Bid+20*point,"A BUY",1,expiration,Blue);
       OrderSend(Symbol(),OP_SELLSTOP,0.1,Bid-8*point,4,Ask+50*point,Ask-22*point,"A SELL",2,expiration,Green);
     }
}
  if ( ABUY== 2 ) {
     if ( ASELL>0 ) {
     
       OrderDelete(OrderMagicNumber()== 2 );
       OrderDelete(OrderMagicNumber()== 6 );         //delete pending Headging A
       OrderSend(Symbol(),OP_SELLSTOP,0.2,Bid-30*point,4,Ask-62*point,Ask-2*point,"HA SELL",4,expiration,Green);
       }
     else if ( BBUY== 0 && BSELL== 0 ) {
       OrderSend(Symbol(),OP_BUYSTOP,0.1,Ask+6*point,4,Bid-52*point,Bid+20*point,"B BUY",3,expiration,Blue);
       OrderSend(Symbol(),OP_SELLSTOP,0.1,Bid-8*point,4,Ask+50*point,Ask-22*point,"B SELL",4,expiration,Green);
      }
      }
  else if ( ASELL == 2 ) {
     if ( ABUY>0 ) {
       OrderDelete(OrderMagicNumber()== 1 );
       OrderDelete(OrderMagicNumber()== 5 );         //delete pending Headging A
       OrderSend(Symbol(),OP_BUYSTOP,0.1,Ask+28*point,4,Bid+60*point,Bid,"HA BUY",3,expiration,Blue);
       }
     else if ( BBUY== 0 && BSELL== 0 ) { 
       OrderSend(Symbol(),OP_BUYSTOP,0.1,Ask+6*point,4,Bid-52*point,Bid+20*point,"B BUY",3,expiration,Blue);
       OrderSend(Symbol(),OP_SELLSTOP,0.1,Bid-8*point,4,Ask+50*point,Ask-22*point,"B SELL",4,expiration,Green);
       }
       }
return(0)
}
 

There are more coding problems with this than I have time to list. I'll mention 2 ..

1) OrderDelete(OrderMagicNumber()== 7 ); // will not do what you expect as "OrderMagicNumber()== 7" is a boolean expression

2) check results of Order.... functions for any failures

Please check code samples here & elsewhere.

 
brewmanz:

There are more coding problems with this than I have time to list. I'll mention 2 ..

1) OrderDelete(OrderMagicNumber()== 7 ); // will not do what you expect as "OrderMagicNumber()== 7" is a boolean expression

2) check results of Order.... functions for any failures

Please check code samples here & elsewhere.

Thank you brewmanz.


1458
WHRoeder 2011.03.03 16:50https://www.mql5.com/en/forum/132153

WHRoeder - I know that this is my second post on the top of formu but now there are two problems that I want to understand.

First problem is Why Didn't send any orders and second problem how delete pending order with some ID.

I am working on underastanding how EA works and deleting the orders.

But I can't still understand why program didn't send any orders.

As you see down of this comment is the first sample of code and at the finish of that is function else.

So if there are not any orders on the market, program should send two orders. But didn't.

Can you tell me where is mistake, what i make wrong?

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
double ABUY;
double ASELL;
double BBUY;
double BSELL;
double HABUY;
double HASELL;
double HBBUY;
double HBSELL;
double point = MarketInfo(Symbol(),MODE_POINT);
double expiration=CurTime()+PERIOD_D1*60;
int n;
int total= OrdersTotal();
for( n=0; n<total; n++ ){ // count how many open orders we have
if( OrderSelect(n,SELECT_BY_POS,MODE_TRADES) )
continue;

if( OrderSymbol()==Symbol() )
continue;
if( OrderMagicNumber()== 1 && OrderType()== OP_BUY ){
ABUY=2;
}
else if( OrderMagicNumber()== 1 && OrderType()== OP_BUYSTOP ){
ABUY=1;
}
else if( OrderMagicNumber()== 2 && OrderType()== OP_SELL ){
ASELL=2;
}
else if( OrderMagicNumber()== 2 && OrderType()== OP_SELLSTOP ){
ASELL=1;
}
else if( OrderMagicNumber()== 3 && OrderType()== OP_BUY ){
BBUY=2;
}
else if( OrderMagicNumber()== 3 &&OrderType()== OP_BUYSTOP ){
BBUY=1;
}
else if( OrderMagicNumber()== 4 && OrderType()== OP_SELL ){
BSELL=2;
}
else if( OrderMagicNumber()== 4 && OrderType()== OP_SELLSTOP ){
BSELL=1;

}

else {

OrderSend(Symbol(),OP_BUYSTOP,0.1,Ask+6*point,4,Bid-52*point,Bid+20*point,"A BUY",1,expiration,Blue);

OrderSend(Symbol(),OP_SELLSTOP,0.1,Bid-8*point,4,Ask+50*point,Ask-22*point,"A SELL",2,expiration,Green);

}

}

return(0);

}

Reason: