Referencing OP_BUYSTOP once opened

 

 I have to recognize , in this case, a long trade has been opened when a pending OP_BUYSTOP has been hit. It returns it to a variable nlongs.  If nlongs is >0 and the price has moved x pips, the stop loss is moved to break even.

int GetLongsNumber()
{
   int n = 0;
   for(int x = 0; x < OrdersTotal(); x++)
   {
      OrderSelect(x, SELECT_BY_POS, MODE_TRADES);
      if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_BUYSTOP)
      {
         n++;
      }
   }
   return(n);
}
 
if(nLongs > 0)
      {
         //First stop move at +15
         if(SLMoved == 0 && Bid >= OrderOpenPrice() + 15*k*Point)
         {
            OrderModify(nOrderTicket, OrderOpenPrice(), OrderOpenPrice() + k*Point, OrderTakeProfit(), 0, CLR_NONE);
            SLMoved = 1;

Sorry for the sloppy post, hope you can follow.

 

Anyway, if nlongs is >0 and price has moved 15 pips, this sets the stop loss of an OP_SELLSTOP that I also have pending to break even and I have no idea why.  I hope I described this clearly.

 
bluesman: I have to recognize , a long trade has been opened when a pending OP_BUYSTOP has been hit.
When a pending order's open price has been hit, it is no longer pending, its type is now OP_BUY/OP_SELL
 
WHRoeder:
When a pending order's open price has been hit, it is no longer pending, its type is now OP_BUY/OP_SELL
They were originally OP_BUY and OP_SELL in the getlongsnumber routine and I was having the same problem.  So I changed them to OP_BUYSTOP and OP_SELLSTOP.  I'll change them back again and see what happens.  Thanks...
 
bluesman:

Sorry for the sloppy post, hope you can follow.

 

Anyway, if nlongs is >0 and price has moved 15 pips, this sets the stop loss of an OP_SELLSTOP that I also have pending to break even and I have no idea why.  I hope I described this clearly.


if(nLongs > 0)
      {
         //First stop move at +15
         if(SLMoved == 0 && Bid >= OrderOpenPrice() + 15*k*Point)
         {
            OrderModify(nOrderTicket, OrderOpenPrice(), OrderOpenPrice() + k*Point, OrderTakeProfit(), 0, CLR_NONE);
            SLMoved = 1;

What trade do you select to modify ???

Are you sure  nOrderTicket is the number of the trade to modify ??

 
deVries:

What trade do you select to modify ???

Are you sure  nOrderTicket is the number of the trade to modify ??

And how do you know? You don't check the orderModify return value and verify. What are Function return values ? How do I use them ? - MQL4 forum
 

 "What trade do you select to modify ???"

There is only 1 open trade at a time.  The only open trade is the one to be modified.

The EA worked fine and the SL was moved to break even correctly on the open trade until I changed the OP_BUY and OP_SELL to OP_BUYSTOP and OP_SELLSTOP.  The system opens 1 pending OP_BUYSTOP and 1 pending OP_SELLSTOP per day.  When one is hit it opens and the other remains pending until the next day when it is deleted.  When the open order moves x pips the stop is moved to break even.  It worked fine before.  But now the stop is moved on the pending order, not the open order.  

So you're saying to check the nOrderTicket number and the OrderModify return value?   I will try to figure out how to do it with the link you included. Thanks...

Reason: