How to get Lot size in the DEPOSIT currency?? - page 2

 

Exactly what I posted above ;)

 
nicholishen: Exactly what I posted above ;)

Instead of using a fixed value, you can get the Contract size with SymbolInfoDouble( ..., SYMBOL_TRADE_CONTRACT_SIZE )

Also, instead of using String manipulation you can obtain the Base, Profit and Margin Currencies using SymbolInfoString() and SYMBOL_CURRENCY_BASESYMBOL_CURRENCY_PROFIT and SYMBOL_CURRENCY_MARGIN

EDIT: By the way, you can also covert it into a "pip" equivalent if you prefer:

Forum on trading, automated trading systems and testing trading strategies

Question about Tester Commisions and Swaps

Fernando Carreiro, 2017.01.12 23:25

Commissions can be represented as an equivalent value in pips yes, but not swaps as that is dependent on how long the order remains open and if it is hit by the triple swap day or not.

Here is an example (but will differ depending on some factors, for which you will have to change depending on your case):

The number of Pips that your commission ($ per million) represents in the case of GBP/USD and a USD Account Balance can be calculated as follows:

Pip Equivalent = Currency Price * Commission Rate * 2 Operations / 100

For example, if your GBP/USD Price is 1.62012 and your commission is $35 per million, then
Pip Equivalent = 1.62012 * 35 * 2 / 100 = 1.134084 ~ 1.2 pips (after ceiling adjustment)

If your average spread is 0.94 pips and commission is 1.2 pips, then total cost is 2.14 pips average.

EDIT: More details:
The "100" has nothing to do with percentage but rather the resultant value after factoring Contract Size and Pip Value for a Standard Lot of volume.

Here is the correct calculation in detail:
Contract Size = 100000 (Standard Lot Contract Size)
Pip Value = $10.00 (for Standard Lot of ???/USD and USD Account Balance)
Currency Price = 1.62012 (example for GBP/USD)
Value = Currency Price x Contract Size = $162012.00
Turnover = Value x 2 (open & close) = $324024.00
Commission Value = $35.00
Commission Scale = $1000000.00 (Million $)
Commission Rate = Commission Value / Commission Scale = 0.000035
Commission per Trade = Turnover x Commission Rate = $11.34084
Commission in Pips = Commission per Trade / Pip Value = 1.134084 pips

Thus the resultant simplified calculation is as follows:
Commission in Pips = Currency Price * Commission Value * 2 / 100
Commission in Pips = Currency Price * Commission Value / 50

EDIT2:
However, please note that this is an approximation, as we are using the same Currency Price for both the Open and Close of the Trade. To be exact, we would have to calculate separate commissions for the opening price and closing price, but the resulting difference from the above calculation is negligible. But if you wish, just use the average price between the opening and closing prices, in the calculation, for a better approximation.
Please note that this is only an example and depends on how commission is defined by your broker and in what currency it is expressed.

EDIT: Do a search as well. I found the following:



 
Fernando Carreiro:

Instead of using a fixed value, you can get the Contract size with SymbolInfoDouble( ..., SYMBOL_TRADE_CONTRACT_SIZE )

Also, instead of using String manipulation you can obtain the Base, Profit and Margin Currencies using SymbolInfoString() and SYMBOL_CURRENCY_BASESYMBOL_CURRENCY_PROFIT and SYMBOL_CURRENCY_MARGIN


Thanks for the tips, but...

SYMBOL_CURRENCY_BASE doesn't work properly on CFD symbols eg. SPXUSD hence the string find.

I used MODE_LOTSIZE instead of SYMBOL_CONTRACT_SIZE which can be found in the UnitsDepositCurrency conversion function (updated for MQL5 compatibility). Also, the fixed number of 100,000.0 is a const factor in the commission calculation. 

I tweaked it to make it more compatible with ECN brokers who offer multiple symbols. eg. EURUSD, EURUSDecn 

void OnStart()
{
   string symbol  = "CADCHFecn";
   double commish = CommissionCalc(symbol,1,2);
   Print("Commission = ",commish);
}
#include <suffix.mqh>
#include <multi_symbol_timeframe.mqh>

double CommissionCalc(string symbol, double lots, double commission_per_100k_units)
{
   double res = (double)UnitsDepositCurrency(symbol);
   if(res<=0)
      return -1.;
   res = res/100000.0*commission_per_100k_units*lots;
   return MathCeil(res*100)/100;
}

int UnitsDepositCurrency(const string symbol)
{
   string currency_account = AccountInfoString(ACCOUNT_CURRENCY);
   string currency_base    = StringSubstr(symbol,0,3);
   string currency_counter = StringSubstr(symbol,3,3);
   int    contract_units   = (int)SymbolInfoDouble(symbol,SYMBOL_TRADE_CONTRACT_SIZE);
   if(contract_units <= 0)
      return -1;
   if(currency_account==currency_base)
      return contract_units;
   if(currency_account==currency_counter)
   {
      double bid = iBid(symbol);
      if(bid <= 0.)
      {
         Print(__FUNCTION__," ",ErrorDescription(GetLastError()));
         return -1;
      }
      return int((double)contract_units*bid);
   }
   string suffix = AssumedSuffix();
   int    total  = SymbolsTotal(false);
   for(int i=0;i<total;i++)
   {
      string mw_symbol  = SymbolName(i,false);
      if(suffix!="" && StringFind(mw_symbol,suffix)<0)
         continue;
      if(StringFind(mw_symbol,currency_account)>=0 && StringFind(mw_symbol,currency_base)>=0)
      {
         double bid = iBid(mw_symbol);
         if(bid <= 0.)
         {
            Print(__FUNCTION__," ",ErrorDescription(GetLastError()));
            return -1;
         }
         string mw_base    = StringSubstr(mw_symbol,0,3);
         string mw_counter = StringSubstr(mw_symbol,3,3);
         if(mw_base==currency_base)
            return int(double(contract_units)*bid);
         if(mw_counter==currency_base)
         {
            int mw_units      = (int)SymbolInfoDouble(mw_symbol,SYMBOL_TRADE_CONTRACT_SIZE);
            int counter_units = int((double)mw_units*bid);
            if(counter_units <= 0)
               return -1;
            return int(((double)contract_units * (double)mw_units) / (double)counter_units);
         }
         break;
      }
   }
   return -1;
}
 

Hi, I have a challenge. I'd like to create an input where I set the percentage of my account equity I want to use for each trade and calculate the volume size for each order.

My problem is that I do not know the formula to convert deposit currecy value to lot size.

I apperciate any help.

 
Andre Tavares:

Hi, I have a challenge. I'd like to create an input where I set the percentage of my account equity I want to use for each trade and calculate the volume size for each order.

My problem is that I do not know the formula to convert deposit currecy value to lot size.

I apperciate any help.

I finally found what I needed. Anyoune who needs thake a look. The article is in portuguese, but you may translate it at google.


<Link Removed>

Moderator: Please do not post links to other websites

 
Andre Tavares:

I finally found what I needed. Anyoune who needs thake a look. The article is in portuguese, but you may translate it at google.


<Link Removed>

Moderator: Please do not post links to other websites

Please you can send me the link in a private message.

Reason: