OrderProfit() of the First Trade

To add comments, please log in or register
dundale
31
dundale  

Hi everone,


I have a Question. I need the OrderProfit() of the first open Trade of the Buys and also of the Sells.

But I have no Idea, how to program this.

Can somebody help me?


bye,

tom

William Roeder
20233
William Roeder  
  1. Help you with what? You haven't stated a problem. Show us your attempt (using CODE button) and state the nature of your problem.
              No free help
              urgent help.

  2. OrderSelect loop through your orders. Find the one with the earliest OrderOpenPrice and remember it's profit.

  3. Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum
dundale
31
dundale  

I tried this and it lokks like it works.

double FindProfitOfFirstOrder(int dir)
{
   double Profit = 0;
   datetime EarliestOrder = D'2099/12/31';
   
   for (int i = 0; i < OrdersTotal(); i++) {
      if (OrderSelect(i, SELECT_BY_POS)) {
         if (OrderType() == dir) {
            if (EarliestOrder > OrderOpenTime()) {
               EarliestOrder = OrderOpenTime();
               Profit = OrderProfit();
            }
         }  
      }
   }      
   return (Profit);
}

I had a Function, who give the FirstOrderOpenPrice, I changed Profit and Price, and so it gave me the Profit of the FirstOrder.

Or is something wrong? Or is there a better way?

To add comments, please log in or register