OrderCalcProfit MODE_TICKVALUE

 

I try to have in MT4 the same function has we have in MT5, but for some future (SP500) it does not work. The challenge is to calculate correctly the pip value : just using MarketInfo(Symbol(), MODE_TICKVALUE) does not work. any idea?

Regards,

OrderCalcProfit

The function calculates the profit for the current account, in the current market conditions, based on the parameters passed. The function is used for pre-evaluation of the result of a trade operation. The value is returned in the account currency.

bool OrderCalcProfit(
ENUM_ORDER_TYPE action, // type of the order (ORDER_TYPE_BUY or ORDER_TYPE_SELL)
string symbol, // symbol name
double volume, // volume
double price_open, // open price
double price_close, // close price
double& profit // variable for obtaining the profit value
);

 
Any ideas? Yes, stick to MT4. The forex brokers are sticking to MT4. So should you.
 
perLotPerPoint  = PointValuePerLot();
for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
    OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
&&  OrderMagicNumber()  == magic.number             // my magic number
&&  OrderSymbol()       == Symbol() ){              // and my pair.
        double  DIRection = Direction( OrderType() );
        eRisk   = (OrderClosePrice()-OrderStopLoss()) * DIRection;
        equity.at.risk += eRisk* OrderLots() * perLotPerPoint;
}
=================================================
double  Direction(int op_xxx){  return( 1. - 2. * (op_xxx%2) );                }
double  PointValuePerLot() { // Value in account currency of a Point of Symbol.
    /* In tester I had a sale: open=1.35883 close=1.35736 (0.00147)
     * gain$=97.32/6.62 lots/147 points=$0.10/point or $1.00/pip.
     * IBFX demo/mini       EURUSD TICKVALUE=0.1 MAXLOT=50 LOTSIZE=10,000
     * IBFX demo/standard   EURUSD TICKVALUE=1.0 MAXLOT=50 LOTSIZE=100,000
     *                                  $1.00/point or $10.00/pip.
     *
     * https://www.mql5.com/en/forum/127584 CB: MODE_TICKSIZE will usually return the
     * same value as MODE_POINT (or Point for the current symbol), however, an
     * example of where to use MODE_TICKSIZE would be as part of a ratio with
     * MODE_TICKVALUE when performing money management calculations which need
     * to take account of the pair and the account currency. The reason I use
     * this ratio is that although TV and TS may constantly be returned as
     * something like 7.00 and 0.00001 respectively, I've seen this
     * (intermittently) change to 14.00 and 0.00002 respectively (just example
     * tick values to illustrate). */
    return(  MarketInfo(Symbol(), MODE_TICKVALUE)
           / MarketInfo(Symbol(), MODE_TICKSIZE) ); // Not Point.
}
 
WHRoeder:


Thanks a lot for your reply, I found the same kind of trick wich is working quit fine for all currency pairs. The issue I have is to find a formula which works for currencies, indice,index and metal. I am using fxPro to test as they are offering metals (SILVER and GOLD) futures (SP500 and CAC40) and of course currencies.

Regards,

 
William Roeder #:

Hi William,

Just found this post of yours.  I am hoping that this is what I need.

I would like to calculate the profit banked per day / per symbol to display .

Looking at your post above, can you tell me where I would place this in my EA.?

Currently I am using this

BankedDaily=AccountBalance()-GetBalance()               //GetBalance is the Opening balance of the day

But this gives me the profit for all Symbols.  I want to only display the current symbols profit per chart.



UPDATE:

i got the Profit working, which displays the current profit for open trades per symbol.  

Now I want to display only the Banked profit per symbol.

double OrdersProfit()
  {
   double _total_profit = 0;
   for(int cnt = OrdersTotal() - 1; cnt >= 0; cnt--)
//---
   if ( OrderSelect(cnt, SELECT_BY_POS)                 // Only my orders w/
      &&  OrderMagicNumber()  == MagicNumber             // my magic number
      &&  OrderSymbol()       == Symbol() )
      //---
      
     {
      bool select = OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol())
        {
         _total_profit += OrderProfit() + OrderSwap() + OrderCommission();
         
        }
     }
   return(_total_profit);
  }
  

I managed to updated 

BankedDaily on close of an order per the EA, but if it hits a SL, then it doesn't add the profit.

any direction would help.  thanks

Reason: