EA does not show my SL order

 

One question please ... when I place an order with SL and this order is executed in my EA, I see the order placed (graph + trade TAB) but my SL I see only @ graph (as picture atached).

Is this normal ? Was I supposed to see an order @ trade TAB ? (code also below) ?

ZeroMemory(mrequest);
      mrequest.type=0;
      mrequest.comment = "YouTrade";                                          // comment
      mrequest.action = TRADE_ACTION_DEAL;                                    // immediate order execution
      mrequest.magic = 0;                                                     // Order Magic Number
      mrequest.price = NormalizeDouble(price_info.ask,_Digits);               // latest ask price
      mrequest.symbol= _Symbol;                                               // currency pair
      if(ContratoDobrado==true)
        {
         mrequest.volume=(contratos*2);                                       // number of lots to trade
        }
      else
        {
         mrequest.volume=contratos;                                           // number of lots to trade
        }
      mrequest.sl=0;
      if(order==1)
        {
         Print("[ENVIA ORDEM DE COMPRA]");
         mrequest.type=ORDER_TYPE_BUY;
         mrequest.sl=NormalizeDouble(price_info.ask-stop_loss*_Point,_Digits);// Stop Loss (BUY)
        }
      if(order==-1)
        {
         Print("[ENVIA ORDEM DE VENDA]");
         mrequest.type=ORDER_TYPE_SELL;
         mrequest.sl=NormalizeDouble(price_info.bid+stop_loss*_Point,_Digits);// Stop Loss (SELL)
        }
      mrequest.tp = 0;                                                        // Take Profit
      mrequest.type_filling = ORDER_FILLING_FOK;                              // Order execution type
      mrequest.deviation=20;               
Files:
dddd.PNG  142 kb
 
YouTrade:

One question please ... when I place an order with SL and this order is executed in my EA, I see the order placed (graph + trade TAB) but my SL I see only @ graph (as picture atached).

Is this normal ? Was I supposed to see an order @ trade TAB ? (code also below) ?

Complementing the last post ... see that now, EA placed a new order with a new stop loss and the "old" stop loss disappeared! (Picture attached)

Files:
Capturar2.PNG  53 kb
 
YouTrade:

One question please ... when I place an order with SL and this order is executed in my EA, I see the order placed (graph + trade TAB) but my SL I see only @ graph (as picture atached).

Is this normal ? Was I supposed to see an order @ trade TAB ? (code also below) ?

Your SL is attached to the position, it's not an independent order. You can see it.
 
YouTrade:

Complementing the last post ... see that now, EA placed a new order with a new stop loss and the "old" stop loss disappeared! (Picture attached)

Yes it's how MT5 works, the last SL/TP always replace the old one.
 
angevoyageur:
Yes it's how MT5 works, the last SL/TP always replace the old one.
Thank you ! So I do not need to delete pending orders ...
 
YouTrade:
Thank you ! So I do not need to delete pending orders ...

Yes, you need to delete pending orders, IF your expert advisor actually sends it !!

What Alain is trying to say is: when you attach a SL to a POSITION you don't actually have an order sent to market, but this SL will be automatically executed by the trade server if the trigger price is reached.

I think a good article to better understand this situation can be found here: https://www.mql5.com/en/articles/211

Orders, Positions and Deals in MetaTrader 5
Orders, Positions and Deals in MetaTrader 5
  • 2011.02.01
  • MetaQuotes Software Corp.
  • www.mql5.com
Creating a robust trading robot cannot be done without an understanding of the mechanisms of the MetaTrader 5 trading system. The client terminal receives the information about the positions, orders, and deals from the trading server. To handle this data properly using the MQL5, it's necessary to have a good understanding of the interaction between the MQL5-program and the client terminal.
 
Malacarne:

Yes, you need to delete pending orders, IF your expert advisor actually sends it !!

What Alain is trying to say is: when you attach a SL to a POSITION you don't actually have an order sent to market, but this SL will be automatically executed by the trade server if the trigger price is reached.

I think a good article to better understand this situation can be found here: https://www.mql5.com/en/articles/211

Ok so here relies the question ... what is the best approach ?

1. Send one POSITION + SL - same OrderSend() or

2. Send TWO orders (one for POSITION and ONE for SL) - 2 OrderSend()

Regards

 
YouTrade:

Ok so here relies the question ... what is the best approach ?

1. Send one POSITION + SL - same OrderSend() or

2. Send TWO orders (one for POSITION and ONE for SL) - 2 OrderSend()

Regards

Well, it's a very good approach to ALWAYS send a position with a stop loss attached to it...

Think about the situation where you have any kind of failure while sending the buy stop / sell stop order you want to set as the stop loss... In this case you have the risk to create a position without any kind of stop loss attached to it. So, IMHO, it's a good approach to always send a position with its own SL attached.

It's also possible to have a partial execution, so if you use the second option, you also need to adjust the volume of the second buy stop / sell stop order.

So, I vote for option 1 (position + SL on the same OrderSend() ).

 
Malacarne:

Well, it's a very good approach to ALWAYS send a position with a stop loss attached to it...

Think about the situation where you have any kind of failure while sending the buy stop / sell stop order you want to set as the stop loss... In this case you have the risk to create a position without any kind of stop loss attached to it. So, IMHO, it's a good approach to always send a position with its own SL attached.

It's also possible to have a partial execution, so if you use the second option, you also need to adjust the volume of the second buy stop / sell stop order.

So, I vote for option 1 (position + SL on the same OrderSend() ).


ok ... I will work on option 1. Please give me a clue on how to find the pending order since (1) I cannot see it on the Trade TAB and (2) my delete_pending_order() funcion also cannot find it :)

 
YouTrade:


ok ... I will work on option 1. Please give me a clue on how to find the pending order since (1) I cannot see it on the Trade TAB and (2) my delete_pending_order() funcion also cannot find it :)

Marcelo, when you send an order with a SL attached to it and it becomes a position, please observe on the chart that you have two lines: a green one and a red one. The green line identifies the position price, while the red line identifies the SL price.

Although you cannot see any buy stop / sell stop order on your MT5 terminal, the SL IS PLACED AND WILL AUTOMATICALLY BE EXECUTED BY THE TRADE SERVER WHEN THE TRIGGER PRICE IS REACHED!!!

So don't worry if you cannot see any pending order on your terminal... if you can see a green line and a red line on the chart, then your SL is placed.

 

 
Malacarne:

Marcelo, when you send an order with a SL attached to it and it becomes a position, please observe on the chart that you have two lines: a green one and a red one. The green line identifies the position price, while the red line identifies the SL price.

Although you cannot see any buy stop / sell stop order on your MT5 terminal, the SL IS PLACED AND WILL AUTOMATICALLY BE EXECUTED BY THE TRADE SERVER WHEN THE TRIGGER PRICE IS REACHED!!!

So don't worry if you cannot see any pending order on your terminal... if you can see a green line and a red line on the chart, then your SL is placed.

 

FIRST

Ok ... This I understood. However, my question was different from what you exposed.

If the order is there "somewhere"and I cannot see it, how can I delete it?

My delete_orders() is only getting the orders I see on my trade tab so I understand that I am using a wrong process to "visualize/ delete this order".

IOW, I understood the order is there. How can I catch/ reach it? 

SECOND

Another point that I explained before is that indeed, I see two lines (green + red) but when the EA places another new order (position + SL) the red line from the previous order dissapear. From angelvoyageur: Yes it's how MT5 works, the last SL/TP always replace the old one.

English is not my mother language but the verb replace means remove one and places a new one (order in this case) 

void Apaga_Pending_Orders()
  {
   int ord_total=OrdersTotal();
   if(ord_total>0)
     {
      for(int i=ord_total-1;i>=0;i--)
        {
         ulong ticket=OrderGetTicket(i);

         ZeroMemory(mrequest);

         mrequest.action=TRADE_ACTION_REMOVE;                                   // immediate order execution
         mrequest.magic=0;
         mrequest.order=ticket;
         mrequest.comment="YouTrade";                                          // comment

         if(OrderSend(mrequest,mresult) && (mresult.retcode==TRADE_RETCODE_DONE))
           {
            Print("[TICKET] Order ticket: ",mresult.order," retcode: ",mresult.retcode);
           }
         else
           {
            Print("Order error: ",GetLastError()," retcode: ",mresult.retcode);
            ResetLastError();
            return;
           }
        }
     }
  }
Reason: