how to close orders after taking a specific profit

To add comments, please log in or register
Ankit Jain
458
Ankit Jain  

hello all;

i am practicing mt4 lang and made this ea whic

closes orders if profit lies bw 1.5-2.


closes same order if loss lies bw -2  to  -3..


but the code is not working on ecn 55 digit broker...

int start()
  {
//----
if(OrdersTotal()==0)
{
   OrderSend(Symbol(),0,0.04,Ask,30,0,0);
   OrderSelect(0,SELECT_BY_POS);
   if(OrderProfit()>1.5 && OrderProfit()<2)
   OrderClose(OrderTicket(),OrderLots(),Bid,30);
   if(OrderProfit()>-2 && OrderProfit()<-3)
   OrderClose(OrderTicket(),OrderLots(),Bid,30);
   Print(OrderProfit());
}
Simon Gniadkowski
17644
Simon Gniadkowski  
ankit29030:

hello all;

i am practicing mt4 lang and made this ea whic

closes orders if profit lies bw 1.5-2.


closes same order if loss lies bw -2  to  -3..


but the code is not working on ecn 55 digit broker...

If your OrderSend() fails so does everything else . . .  why don't you check if it has worked or failed ?  don't you want to know ?  don't you want to know why it failed ?  what if youhave more than one order open ?  your OrderSelect() fails,  and your OrderProfit() will be wrong . . . so will your OrderTicket(),  etc, etc.

Read this:   What are Function return values ? How do I use them ?

whroeder1
17954
whroeder1  
if(OrdersTotal()==0)
{
   OrderSend(Symbol(),0,0.04,Ask,30,0,0);
   OrderSelect(0,SELECT_BY_POS);
   if(OrderProfit()>1.5 && OrderProfit()<2)
   OrderClose(OrderTicket(),OrderLots(),Bid,30);
   if(OrderProfit()>-2 && OrderProfit()<-3)
   OrderClose(OrderTicket(),OrderLots(),Bid,30);
   Print(OrderProfit());
}
  1. Tick comes in and there is no open orders. (any pair, any EA - not just this one)
  2. You create one (buy.) Maybe: check your return codes.
  3. You select the only one in the list. Maybe.
  4. Since your buy just paid the spread, it will not be in profit by $1.50 to $2.00 (or what ever your account currency is.)
  5. Likewise not that much negative.
  6. You print OrderProfit which is bogus if you had closed the order.
  7. Next tick comes in and there is an open order - nothing else happens.
To add comments, please log in or register