Delete pending order after a previous order go a profit.

 
Hi, guys I have a problem with my ex that I can not solve.
What I would like is that the EA would eliminate a specific pending order after a previous order has reached the take profit.

I do not understand where I'm wrong, I hope someone can help me.


void DeletePendingOrder27()
{
    
    for (int i=OrdersTotal()-1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
        if (OrderType() == OP_SELLSTOP && OrderSymbol() == Symbol() && OrderMagicNumber() == 2 && Bid - OrderClosePrice() > BuyTakeprofit3*PipValue*Point)
        {
            bool ret = OrderDelete(OrderTicket(), Red);
            
            if (ret == false)
            {
                Print("OrderDelete() error - ", ErrorDescription(GetLastError()));
            }
        }
    }
   
 

Your logic doesn't make sense

if (OrderType() == OP_SELLSTOP && OrderSymbol() == Symbol() && OrderMagicNumber() == 2 && Bid - OrderClosePrice() > BuyTakeprofit3*PipValue*Point)

For a sell stop order OrderClosePrice()=Bid so

Bid - OrderClosePrice()

can only be > a negative number

 
I also explain my reasoning.
My goal is to eliminate a pending order, when a previous order has reached the take profit.
As written in the EA, taking into consideration is that the previous candle, ie: i = OrdersTotal () - 1, right?
Well, then when the difference between the BID and OrderClosePrice (which is the closing level of the previous candle, right?) Is greater than the TakeProfit of my order, the currently pending order should be eliminated. Perchèin this case my previous order has reached the Take Profit.
I hope that my reasoning is clear.
Now I have two questions.
The first is that: because this does not work?
The second: for example, let's pretend that it works, if the Take Profit, always open the order, was not taken in the current timeframe, I'll explain if I'm working in H4, I open a market order (1) and at the same time also they place a pending order (# 2) at 16:00, if # 1 does not reach the Take Profit before 19:59, but let's say 22:00,
The EA for the difference between Bid and OrderClosePrice, OrderClosePrice which takes into account the closure of the 24:00 or the 16:00 candle.
Because the right to consider closing is 12:00 but, and this is my question, if the EA keep HAVE REGARD TO the previous candle that is, i = OrdersTotal () - 1, be wrong?
 
jupp80:
I also explain my reasoning.
My goal is to eliminate a pending order, when a previous order has reached the take profit.
As written in the EA, taking into consideration is that the previous candle, ie: i = OrdersTotal () - 1, right?
Well,then when the difference between the BID and OrderClosePrice (which isthe closing level of the previous candle, right?) Is greater than theTakeProfit of my order, the currently pending order should beeliminated. Perchèin this case my previous order has reached the Take Profit.
I hope that my reasoning is clear.
Now I have two questions.
The first is that: because this does not work?
Thesecond: for example, let's pretend that it works, if the Take Profit,always open the order, was not taken in the current timeframe, I'llexplain if I'm working in H4, I open a market order (1) and at the same time also they place a pending order (# 2) at 16:00,if # 1 does not reach the Take Profit before 19:59, but let's say 22:00,
The EA for the difference between Bid and OrderClosePrice,OrderClosePrice which takes into account the closure of the 24:00 or the16:00 candle.
Becausethe right to consider closing is 12:00 but, and this is my question, ifthe EA keep HAVE REGARD TO the previous candle that is, i = OrdersTotal() - 1, be wrong?

OrdersTotal() is nothing to do with the previous candle

OrderClosePrice() has nothing to do with the previous candle

Sorry, but I have no idea what you are asking,

 
GumRai:

Your logic doesn't make sense

For a sell stop order OrderClosePrice()=Bid so

can only be > a negative number


I'm sorry but I do not understand, OP_SELLSTOP, is the type of pending order that I want to delete.
I give you an example, I have a bear candle, ok? I buy in the market to 0.71500, this is the first order (1), and at the same time I place a SELL STOP at 0.71200, this is the second order (2). I wish that when the bid was greater than my Take Profit, for example 200, and therefore the bid was 0.71710 for example, the pending order (2) is deleted.
So my reasoning is OrderClosePrice = 0.71500 and then when the bid is 0.71710, we Bid - OrdeClosePrice =
(0.71710 - 0.71500) = 210, ok?
210> 200 (my Take Profit), in this case the pending order (2) is deleted.
I hope I was clear.
 
OK, I must have misunderstood the use of certain functions.
I ask you then this thing, in short, I want that when a particular order is closed because it reached its Take Profit, another specific pending order is closed.
An example, if I buy in the market to 0.6400 and put Take Profit at 0.6500, well this is the first order (1).
Well the same time I place a pending order, in 6400, ok this is the second order (2).
My question is very simple how can I eliminate the second order (2), when the first (1) has reached the Take Profit?
 
No one can help me?
 
jupp80: So my reasoning is OrderClosePrice = 0.71500 and then when the bid is 0.71710, we Bid - OrdeClosePrice = (0.71710 - 0.71500) = 210, ok?
210> 200 (my Take Profit), in this case the pending order (2) is deleted.

If an order has opened then OrderClosePrice is either Bid or Ask depending on the direction, so no, not ok.

Perhaps you want to compare the open order's OrderOpenPrice() to Bid (or its OrderClosePrice().)

 
WHRoeder:

If an order has opened then OrderClosePrice is either Bid or Ask depending on the direction, so no, not ok.

Perhaps you want to compare the open order's OrderOpenPrice() to Bid (or its OrderClosePrice().)

What I want is that when I place an order, call # 1, reaches its take profit, another pending order, named # 3, it is eliminated.
Well, to do this, my reasoning was:
when the difference between the current price, ie the Bid (the bid should indicate the current price on the graph, right?) and the aprtura price of the order # 1, is greater than a certain value, the pending order, n .3 shall be elimato.
For example, if I open a Buy order at 0.6500 Take Profit at 0.6700 and fixed. Well, when the price (Bid) reaches 0.6701,
the difference between Bid - OpenPrice is 201, right? So it's more of Take Profit = 200.
The formula designed by me is:
TAkeProfit*PipValue*Point. ">Bid - OpenPrice (order 1)> * PipValue TakeProfit * Point.

The question that I would like answered is:
What should I write to indicate the difference between the current price and the purchase price of the order number 1?

What is the term for the one specific order opening price?

For example, if you are open two orders, one number and another number # 222222 # 111111, how do I indicate that the price of the EA aprtura the order I want is the # 11111 and not another? That is, how can I make sure she is right?
I hope I was clear.
Anyway thanks for u help.
 
Perhaps the images can make you understand better.
Let's pretend that I find myself in the situation below, I have 3 open orders in the market and one pending order, ok?
Well I wish that when the order number # 4372889 reaches its Take Profit (in this case is not shown but never mind), the pending order, that is, # 4372930 is eliminated.

How can I make that happen?


 
A small clarification, the open order and the pending order have the same currency, so in this case make feints that the pending order is not USDCHF but EURUSD.
Reason: