Orderselect problem

 

Hello,

I am having problems with part of my code. the breakeven part of the code is working how it should, however the takeprofit modify part is not working correctly.

Here is what I want the following code to perform.

If I have more then 1 open order I want the loop to modify all orders to the new orders takeprofit value.

recentpricebuy() is a function that obtains the most recent price's orderopenprice.

recentpricesell() is the same function except for sell orders.

void MonitorTrades()

{

int ticket;

  int total = OrdersTotal();

  for(int i=total-1;i>=0;i--)

  {

  OrderSelect(i, SELECT_BY_POS);

      {

      if (OrderType()==OP_BUY)

         {

         if (Bid >= (OrderOpenPrice()+(BreakEven*Point)) && OrderStopLoss()<OrderOpenPrice())

            {

               ticket = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+(BreakEvenProfit*Point),OrderTakeProfit(),0,CLR_NONE);

               if (ticket>0 && ShowAlerts==true) Alert("Breakeven set on ", OrderSymbol(), " ticket no ", OrderTicket());

            }

         if (OrderTakeProfit()<recentpricebuy()+(TakeProfit*Point))

            {

              ticket = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),recentpricebuy()+(TakeProfit*Point),0,CLR_NONE);

            if (ticket>0 && ShowAlerts==true) Alert("TakeProfit set on ", OrderSymbol(), " ticket no ", OrderTicket());

            }

       }                                 

      if (OrderType()==OP_SELL)

         {

           if (Ask <= (OrderOpenPrice()-(BreakEven*Point)) && OrderStopLoss()>OrderOpenPrice()) 

            {

               ticket = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-(BreakEvenProfit*Point),OrderTakeProfit(),0,CLR_NONE);

               if (ticket>0 && ShowAlerts==true) Alert("Breakeven set on ", OrderSymbol(), " ticket no ", OrderTicket());

            }

      if (OrderTakeProfit()>recentpricesell()-(TakeProfit*Point))

            {

            ticket = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),recentpricesell()-(TakeProfit*Point),0,CLR_NONE);

            if (ticket>0 && ShowAlerts==true) Alert("TakeProfit set on ", OrderSymbol(), " ticket no ", OrderTicket());

            }    

         }

      }

   }

}
 
I think, it's very stupid to use this code, just put TakeProfit=0, because  you never reach it any case.
 
Roger:
I think, it's very stupid to use this code, just put TakeProfit=0, because you never reach it any case.

Sorry you are wrong..

you will reach take profit if the EA does not place a new trade...

every time it places a new trade I want the EA to adjust all open trades to the same takeprofit value that the newest trade, or most recent trade has.

Take profit would never be reached if the EA kept placing new trades, but this would only happen if the trend never ended.

Reason: