TP value works for EURUSD but not AUDUSD... Why...

 

Hi Everyone

In my EA, whenever i open an order, i will open 2 one after the other.

For the second order, i will put in a TP value (fixed at 10 pips).

           res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",MAGICMA,0,Blue);
           res=OrderSend(Symbol(),OP_SELL,LotsOptimized()*2,Bid,3,0,0,"",MAGICMA_2,0,Blue);
                      
                if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES) == true)
                {
                  sl = 0; //sl=Ask+slPoints;
                  tp=Ask-tpPoints;
                  
                  //if(sl-Ask<=MarketInfo(Symbol(),MODE_STOPLEVEL)*Point && sl>0) // check broker stop levels
                  //{
                  //   Alert("Stop Loss is too close to market price or on wrong side!!!");
                  //   return(0);
                  //}         
                  
                  if(Ask-tp<=MarketInfo(Symbol(),MODE_STOPLEVEL)*Point && tp>0)
                  {
                     Print("Take Profit is too close to market price or on wrong side!!!");
                  } 
                         
                  OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,Green);
                } 

I ran the same EA on the same broker for both EURUSD and AUDUSD.

For EURUSD, it was ok, but for AUDUSD, the first 2 orders went through, but the TP order didnt.

Here is the log

2014.03.13 04:00:04.690 '668687': order was opened : #61527502 buy 0.20 AUDUSD at 0.89896 sl: 0.00000 tp: 0.00000
2014.03.13 04:00:04.689 '668687': request in process
2014.03.13 04:00:04.688 '668687': request was accepted by server
2014.03.13 04:00:04.227 '668687': order buy market 0.20 AUDUSD sl: 0.00000 tp: 0.00000
2014.03.13 04:00:04.176 '668687': order was opened : #61527498 buy 0.10 AUDUSD at 0.89896 sl: 0.00000 tp: 0.00000
2014.03.13 04:00:04.175 '668687': request in process
2014.03.13 04:00:04.174 '668687': request was accepted by server
2014.03.13 04:00:03.904 '668687': order buy market 0.10 AUDUSD sl: 0.00000 tp: 0.00000
2014.03.12 23:51:11.013 '668687': order #61472493 buy 0.20 EURUSD at 1.38930 was modified -> sl: 0.00000 tp: 1.39117
2014.03.12 23:51:11.012 '668687': request in process
2014.03.12 23:51:11.011 '668687': request was accepted by server
2014.03.12 23:51:10.754 '668687': modify order #61472493 buy 0.20 EURUSD at 1.38930 sl: 0.00000 tp: 0.00000 -> sl: 0.00000 tp: 1.39117
2014.03.12 23:51:10.753 '668687': order was opened : #61499907 buy 0.20 EURUSD at 1.39033 sl: 0.00000 tp: 0.00000

Anyone knows why such a behavior?

Thanks!

 

The code that you show opens sell orders

           res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",MAGICMA,0,Blue);
           res=OrderSend(Symbol(),OP_SELL,LotsOptimized()*2,Bid,3,0,0,"",MAGICMA_2,0,Blue)

The journal shows buy orders

2014.03.13 04:00:04.690 '668687': order was opened : #61527502 buy 0.20 AUDUSD at 0.89896 sl: 0.00000 tp: 0.00000
2014.03.13 04:00:04.689 '668687': request in process
2014.03.13 04:00:04.688 '668687': request was accepted by server
2014.03.13 04:00:04.227 '668687': order buy market 0.20 AUDUSD sl: 0.00000 tp: 0.00000
2014.03.13 04:00:04.176 '668687': order was opened : #61527498 buy 0.10 AUDUSD at 0.89896 sl: 0.00000 tp: 0.00000
2014.03.13 04:00:04.175 '668687': request in process
2014.03.13 04:00:04.174 '668687': request was accepted by server
2014.03.13 04:00:03.904 '668687': order buy market 0.10 AUDUSD sl: 0.00000 tp: 0.00000

That code did not open those orders, please show the actual code.

 
GumRai:

The code that you show opens sell orders

The journal shows buy orders

That code did not open those orders, please show the actual code.


Hi

Sorry about that.. here is the code for the BUY orders

           res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,"",MAGICMA,0,Blue);
           res=OrderSend(Symbol(),OP_BUY,LotsOptimized()*2,Ask,3,0,0,"",MAGICMA_2,0,Blue);
           
                if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES) == true)
                {
                  sl = 0; //sl=Bid-slPoints;
                  tp = Bid+tpPoints;
                  
                  //if(Bid-sl<=MarketInfo(Symbol(),MODE_STOPLEVEL)*Point && sl>0)          // check broker stop levels
                  //{
                  //   Alert("Stop Loss is too close to market price or on wrong side!!!");
                  //   return(0);
                  //} 
         
                  if(tp-Bid<=MarketInfo(Symbol(),MODE_STOPLEVEL)*Point && tp>0)
                  {
                     Print("Take Profit is too close to market price or on wrong side!!!");
                  } 
                         
                  OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,Green);
                }
 

Was there anything printed in the expert log?

Check if OrderModify was successful and if not GetLastError

 
GumRai:

Was there anything printed in the expert log?

Check if OrderModify was successful and if not GetLastError

For example: What are Function return values ? How do I use them ?
 

Hi Folks

Thanks for the inputs, I modified the code to get the error log.

Here is the modified code.

           res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",MAGICMA,0,Blue);
           res=OrderSend(Symbol(),OP_SELL,LotsOptimized()*2,Bid,3,0,0,"",MAGICMA_2,0,Blue);
                      
                if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES) == true)
                {
                  sl = 0; //sl=Ask+slPoints;
                  tp=Ask-tpPoints;
                  
                  //if(sl-Ask<=MarketInfo(Symbol(),MODE_STOPLEVEL)*Point && sl>0) // check broker stop levels
                  //{
                  //   Alert("Stop Loss is too close to market price or on wrong side!!!");
                  //   return(0);
                  //}         
                  
                  if(Ask-tp<=MarketInfo(Symbol(),MODE_STOPLEVEL)*Point && tp>0)
                  {
                     Print("Take Profit is too close to market price or on wrong side!!!");
                  } 
                         
                  res_om= OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,Green);
                  if(!res_om)
                  {
                     Print("Error in OrderModify. Error Code: ", GetLastError());
                  }  
                  else
                  {
                     Print("OrderModify: Successful.");
                  }                
                } 

Again, the code seemed to work fine for EURUSD but not for another currency pair, this time GBPUSD.

Here is the Expert Log

2014.03.14 04:00:05.298 MA_Cross_1h GBPUSD,H1: Error in OrderModify. Error Code: 130
2014.03.14 04:00:05.298 MA_Cross_1h GBPUSD,H1: open #176279296 sell 0.10 GBPUSD at 1.66150 ok
2014.03.14 03:00:06.008 MA_Cross_1h EURUSD,H1: OrderModify: Successful.
2014.03.14 03:00:06.008 MA_Cross_1h EURUSD,H1: modify #176273934 sell 0.10 EURUSD at 1.38568 sl: 0.00000 tp: 1.38484 ok
2014.03.14 03:00:05.035 MA_Cross_1h EURUSD,H1: open #176273953 sell 0.20 EURUSD at 1.38568 ok
2014.03.14 03:00:04.061 MA_Cross_1h EURUSD,H1: open #176273934 sell 0.10 EURUSD at 1.38568 ok

Here is the part of the code where I set the TP value

   if (Digits == 5 || Digits == 3)    // Adjust for five (5) digit brokers.
   {            
      pips2dbl = Point*10; pips2point = 10;
   } 
   else 
   {    
      pips2dbl = Point;   pips2point = 1;
   }    
   
   slPoints=SLpip*pips2dbl;
   tpPoints=TPpip*pips2dbl;

TPpip is fixed at 10.

This part of the code was actually referenced from others who shared in this forum.

I am still not sure why it works only for EURUSD and not other currency pairs.

I am running the same EA on a few brokers like Alpari, Axi, HotForex and finFx.

All have the same behavior.

Thanks!

 
if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES) == true)

i assume you have more than one open order

 

Hi qjol

I am not sure what you mean..

The line

if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES) == true)

is supposed to select the last "Open" order and in this case it should be the one executed by

res=OrderSend(Symbol(),OP_SELL,LotsOptimized()*2,Bid,3,0,0,"",MAGICMA_2,0,Blue);

Here is more of the expert log

2014.03.14 04:00:12.563 MA_Cross_1h GBPUSD,H1: Error in OrderModify. Error Code: 130
2014.03.14 04:00:12.563 MA_Cross_1h GBPUSD,H1: open #32629629 sell 0.20 GBPUSD at 1.66161 ok
2014.03.14 04:00:10.264 MA_Cross_1h GBPUSD,H1: open #32629620 sell 0.10 GBPUSD at 1.66161 ok
2014.03.14 03:00:14.382 MA_Cross_1h EURUSD,H1: OrderModify: Successful.
2014.03.14 03:00:14.382 MA_Cross_1h EURUSD,H1: modify #32622567 sell 0.20 EURUSD at 1.38567 sl: 0.00000 tp: 1.38485 ok
2014.03.14 03:00:12.694 MA_Cross_1h EURUSD,H1: open #32626761 sell 0.20 EURUSD at 1.38582 ok
2014.03.14 03:00:08.865 MA_Cross_1h EURUSD,H1: open #32626749 sell 0.10 EURUSD at 1.38572 ok

You can see that for EURUSD, both the orders open and the OrderModify is successful for the second order.

For GBPUSD, both the orders open but the OrderModify is not successful.

Thanks!

 

raviragas:

is supposed to select the last "Open" order and in this case it should be the one executed by

who told you that ?

if(OrderSelect(OrdersTotal() - 1,SELECT_BY_POS,MODE_TRADES) == true)

is the last open order !

this:

if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES) == true)

is the first open order !

 
qjol:

who told you that ?

is the last open order !

this:

is the first open order !


Hi qjol

Thanks for pointing out my misunderstanding... I decided that it would be easier to deal with OrderSElect using Ticket number instead of order_pos.

I modified the code as below and it works fine now.

         res=OrderSend(Symbol(),OP_BUY,LotsOptimized()*2,Ask,3,0,0,"",MAGICMA_2,0,Blue);

                if(OrderSelect(res,SELECT_BY_TICKET,MODE_TRADES) == true)
                {
                  sl = 0; //sl=Bid-slPoints;
                  tp = Bid+tpPoints;
                  
                  //if(Bid-sl<=MarketInfo(Symbol(),MODE_STOPLEVEL)*Point && sl>0)          // check broker stop levels
                  //{
                  //   Alert("Stop Loss is too close to market price or on wrong side!!!");
                  //   return(0);
                  //} 
         
                  if(tp-Bid<=MarketInfo(Symbol(),MODE_STOPLEVEL)*Point && tp>0)
                  {
                     Print("Take Profit is too close to market price or on wrong side!!!");
                  } 
                         
                  res_om = OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,Green);
                  if(!res_om)
                  {
                     Print("Error in OrderModify. Error Code: ", GetLastError());
                  }
                  else
                  {
                     Print("OrderModify: Successful.");
                  }

Thanks again to all who helped!

 
who said that there are difficult and easy stuff
it's difficult if we don't understand
and it's easy if we do understand ;-)
Reason: