know the profit of two overlapping contrary orders on the same underlying, for example eurusd.

 

Hello, I want to know the profit of my current order, but I can not to know the profit when I have two contrary orders open on the same underlying. For example to find the profit of a buy order in the eurusd use the function:

int retorno_profit_buy(int NMagb)
{
 int resultprofitb;
 
 RefreshRates();
 if( OrdersTotal()==0 ) return;
 for ( int i=0; i<OrdersTotal(); i++)   
  {OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
  double InfASK=NormalizeDouble(MarketInfo(Symbol(),MODE_ASK),Digits);
  double InfBID=NormalizeDouble(MarketInfo(Symbol(),MODE_BID),Digits);
  double InfPoint=MarketInfo(Symbol(),MODE_POINT);
  double infStopLEVEL=MarketInfo(Symbol(),MODE_STOPLEVEL)*InfPoint;
  int Slippage=((InfASK-InfBID)/InfPoint)+1;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==NMagb && OrderType()==OP_BUY)
         {
         resultprofitb=OrderProfit();
         }
         return(resultprofitb);
} }

and when I want to know the profit of a sell order use the function:

int retorno_profit_sell(int NMags)
{
 int resultprofits;
 
 RefreshRates();
 if( OrdersTotal()==0 ) return;
 for ( int j=0; j<OrdersTotal(); j++)
  {OrderSelect(j, SELECT_BY_POS, MODE_TRADES);
  double InfASK=NormalizeDouble(MarketInfo(Symbol(),MODE_ASK),Digits);
  double InfBID=NormalizeDouble(MarketInfo(Symbol(),MODE_BID),Digits);
  double InfPoint=MarketInfo(Symbol(),MODE_POINT);
  double infStopLEVEL=MarketInfo(Symbol(),MODE_STOPLEVEL)*InfPoint;
  int Slippage=((InfASK-InfBID)/InfPoint)+1;
     if(OrderSymbol()==Symbol() && OrderMagicNumber()==NMags && OrderType()==OP_SELL)
         { 
         resultprofits=OrderProfit();
         }
         return(resultprofits);
} }
But the system I'm implementing, two orders can be overlapped on the same underlying, ie I can have a buy order and a sell order in the eurusd overlapped for 10 or 20 pips, and in this case I would like to know the profit of each them.

The question is:

How I can get this?

Thanks.

 
jdcabezas:

Hello, I want to know the profit of my current order, but I can not to know the profit when I have two contrary orders open on the same underlying. For example to find the profit of a buy order in the eurusd use the function:

and when I want to know the profit of a sell order use the function:

But the system I'm implementing, two orders can be overlapped on the same underlying, ie I can have a buy order and a sell order in the eurusd overlapped for 10 or 20 pips, and in this case I would like to know the profit of each them.

The question is:

How I can get this?

Thanks.

Why are you using RefreshRates() ?  you are not using any Predefined variables in these functions so there is no need for RefreshRates() . . .  your functions simply return the values returned by OrderProfit(),  and OrderProfit() returns a double . . .   but your functions are of type int . . .

You don't need different magic Numbers for Buys and Sells . . .  OrderType() tells you if the Order is a Buy or Sell.   So you can rationalise and turn your 2 functions into one function . . . .

double return_order_profit(int ticket)
   {
   if(OrderSelect(ticket, SELECT_BY_TICKET))
      return( OrderProfit() )
   else Print("Error in return_order_profit # ", GetLastError());
   }

 . . . .  do the order selection and validation outside of the Function.

 

Why not just call OrderProfit() for the Buy and the Sell and add the values ?

 
RaptorUK:

Why are you using RefreshRates() ?  you are not using any Predefined variables in these functions so there is no need for RefreshRates() . . .  your functions simply return the values returned by OrderProfit(),  and OrderProfit() returns a double . . .   but your functions are of type int . . .

You don't need different magic Numbers for Buys and Sells . . .  OrderType() tells you if the Order is a Buy or Sell.   So you can rationalise and turn your 2 functions into one function . . . .

 . . . .  do the order selection and validation outside of the Function.

 

Why not just call OrderProfit() for the Buy and the Sell and add the values ?

Hi, thanks for your help, but I have the same problem.

As you can see, my system can overlap a sell order with a purchase (shown in the picture below).

Using the functions below ("retorno_profit_buy" and "retorno_profit_sell") I only get the profit of the last order, I need to get the profit of the two separate orders, then subtract it and know the total profit in those entries whole.

double retorno_profit_buy(int NMagb)
{
 double resultprofitb;
 
 if( OrdersTotal()==0 ) return;
 for ( int i=0; i<OrdersTotal(); i++)   
  {OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
  double InfASK=NormalizeDouble(MarketInfo(Symbol(),MODE_ASK),Digits);
  double InfBID=NormalizeDouble(MarketInfo(Symbol(),MODE_BID),Digits);
  double InfPoint=MarketInfo(Symbol(),MODE_POINT);
  double infStopLEVEL=MarketInfo(Symbol(),MODE_STOPLEVEL)*InfPoint;
  int Slippage=((InfASK-InfBID)/InfPoint)+1;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==NMagb && OrderType()==OP_BUY)
         {
         resultprofitb=OrderProfit();
         }
         return(resultprofitb);
} }
double retorno_profit_sell(int NMags)
{
 double resultprofits;
 
 if( OrdersTotal()==0 ) return;
 for ( int j=0; j<OrdersTotal(); j++)
  {OrderSelect(j, SELECT_BY_POS, MODE_TRADES);
  double InfASK=NormalizeDouble(MarketInfo(Symbol(),MODE_ASK),Digits);
  double InfBID=NormalizeDouble(MarketInfo(Symbol(),MODE_BID),Digits);
  double InfPoint=MarketInfo(Symbol(),MODE_POINT);
  double infStopLEVEL=MarketInfo(Symbol(),MODE_STOPLEVEL)*InfPoint;
  int Slippage=((InfASK-InfBID)/InfPoint)+1;
     if(OrderSymbol()==Symbol() && OrderMagicNumber()==NMags && OrderType()==OP_SELL)
         { 
         resultprofits=OrderProfit();
         }
         return(resultprofits);
} }
 
jdcabezas:

Using the functions below ("retorno_profit_buy" and "retorno_profit_sell") I only get the profit of the last order, I need to get the profit of the two separate orders, then subtract it and know the total profit in those entries whole.

Total profit is the SUM. do not subtract. If on is loosing, that doesn't mean the total profit is bigger.

Why are you getting only the profit of the last order, loop through all orders and sum them.

double totalProfit=0;
for ( int i=OrdersTotal()-1; i >= 0; i--)   
 if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)
 &&  OrderMagicNumber() == NMags
 &&  OrderSymbol()      == Symbol() 
)  totalProfit += OrderProfit();
 
jdcabezas:

Hi, thanks for your help, but I have the same problem.

As you can see, my system can overlap a sell order with a purchase (shown in the picture below).

Using the functions below ("retorno_profit_buy" and "retorno_profit_sell") I only get the profit of the last order, I need to get the profit of the two separate orders, then subtract it and know the total profit in those entries whole.


Perhaps you should do what I suggested instead of doing what you think I suggested . . .
Reason: