Hi Dear Charless,
Thank you and all the friends for your sincere cooperation
In this description, all the examples are about buy positions
Yes, I want to close all orders when the sum of all open orders (buy separately and sell separately) reaches a certain “total profit”.
Provided that it is equal to the opening price of one of the high positions
But the new thing I want to do is before the price reaches the total profit
Expert examines which of the above open positions in the opening price of all our purchase orders will reach the total profit
Regarding the number of orders opened, I must say that this is unlimited, but this code must do these calculations from position number 2 onwards.
Note the opposite. Before the price reached the order number 2, we calculated that if the price reaches the order number 2, our total profit will reach +$50.
So before the price reaches the order number 2, we must transfer our TP to the order number 2.
I hope my explanation was complete
Thanks for your friendly follow up.
//±-----------------------------------------------------------------+
void BuyOrdersInfo1()
{
PriceOfHigherBuy=-99999;
SumOfBuyOrders=0;
//—
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if((OrderSymbol()==“GBPUSD”) && (OrderMagicNumber()==Magic3) && (OrderType()==OP_BUY))
{
SumOfBuyOrders++;
PriceOfHigherBuy=MathMax(OrderOpenPrice(),PriceOfHigherBuy);
}
}
}
}
//±-----------------------------------------------------------------+
void Trail()
{
for(int i=OrdersTotal()-1;i>=0;i–)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderMagicNumber()==Magic3)
BuyOrdersInfo1();
{
if((SumOfBuyOrders>0)&&((Ask-PriceOfHigherBuy>=Distance*Point)))
{
if(OrderTakeProfit()<(Ask-MathPow(10,-Digits)*PriceOfHigherBuy))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask-MathPow(10,-Digits)*PriceOfHigherBuy,OrderTakeProfit(),0,Green);
}
}
}
}
}