MT5 Lot size for non-forex when broker specifies tick val incorrectly

For instance a USD account and a  GDAXI trade....

It is not rare that brokers enter in the tick value incorrectly expressed as the profit currency instead of the account currency for commodities and 

indexes.  It is known that it is best for MQL5 programmers to calculate non-forex tick value themselves instead of using this

SymbolInfoDouble ("",SYMBOL_TRADE_TICK_VALUE);


https://www.mql5.com/en/forum/227407#comment_6534392
"Must always be deposit currency.

However it's set by the broker and is not rare they provide wrong values, mainly for CFDs."

So to calculate ourselves we basically start with:

initial_calculated_tick_value = contract_size * tick_size
(We can get tick_size and contract_size with SymbolInfoDouble )

Then depending on the account currency and profit currency, we adjust from there. For instance, if the account currency matches the profit currency then we do not need to adjust anything the tick value is the initial calculated tick value.

If the account currency is USD and the profit currency is EUR then:
calculated_tick_value = initial_calculated_tick_value  * EURUSD_price

If the account currency is USD and the profit currency is JPY then:
calculated_tick_value = initial_calculated_tick_value  / USDJPY_price

If the account currency is BTC and the profit currency is USD then:
calculated_tick_value = initial_calculated_tick_value / BTCUSD_price

I hope you get the idea now. It is ideal if all popular combo of account currency (EUR,GBP,BTC,USD etc accounts) and profit currency is accounted for in the code 


Here is what my tick val calc function looks like from my non SQX EA but I only have what I need here:



void c7calc::CalcTickV(void)   {    if((csyms[ccy.getsymn()].symcalcm==SYMBOL_CALC_MODE_FOREX || csyms[ccy.getsymn()].symcalcm==SYMBOL_CALC_MODE_FOREX_NO_LEVERAGE ||        csyms[ccy.getsymn()].SymbolCurrencyProfit==AccountCurrency)) //&& SymbolInfoString(ccy.cursym,SYMBOL_SECTOR_NAME) != "Crypto")       // if its forex or if account currency  is the same as symbol profit currency, just reutnr the standard tick value      {       csyms[ccy.getsymn()].symtcval = SymbolInfoDouble(ccy.cursym,SYMBOL_TRADE_TICK_VALUE);       return;      } // if its not forex we calculate this ourselves    double pticv = csyms[ccy.getsymn()].symcnsz * csyms[ccy.getsymn()].symtcsz;    if(AccountCurrency!=csyms[ccy.getsymn()].SymbolCurrencyProfit)      {       if(AccountCurrency=="USD")         {          if(csyms[ccy.getsymn()].SymbolCurrencyProfit=="EUR")             pticv *= SymbolInfoDouble("EURUSD",SYMBOL_BID);          else             if(csyms[ccy.getsymn()].SymbolCurrencyProfit=="GBP")                pticv *= SymbolInfoDouble("GBPUSD",SYMBOL_BID);             else                if(csyms[ccy.getsymn()].SymbolCurrencyProfit=="JPY")                   pticv /= SymbolInfoDouble("USDJPY",SYMBOL_BID);                else                   if(csyms[ccy.getsymn()].SymbolCurrencyProfit=="AUD")                      pticv *= SymbolInfoDouble("AUDUSD",SYMBOL_BID);                   else                     {                      Alert(omagic,cb,ccy.cursym," Unknown account and profit currency combo ",AccountCurrency,cb,csyms[ccy.getsymn()].SymbolCurrencyProfit);                     }         }       else          if(AccountCurrency=="BTC")            {             if(csyms[ccy.getsymn()].SymbolCurrencyProfit=="USD")                pticv /= SymbolInfoDouble("BTCUSD",SYMBOL_BID);             else                if(csyms[ccy.getsymn()].SymbolCurrencyProfit=="EUR")                   pticv /= SymbolInfoDouble("BTCEUR",SYMBOL_BID);                else                   if(csyms[ccy.getsymn()].SymbolCurrencyProfit=="GBP")                      pticv *= SymbolInfoDouble("GBPUSD",SYMBOL_BID) / SymbolInfoDouble("BTCUSD",SYMBOL_BID);                   else                      if(csyms[ccy.getsymn()].SymbolCurrencyProfit=="JPY")                         pticv /= SymbolInfoDouble("BTCUSD",SYMBOL_BID) * SymbolInfoDouble("USDJPY",SYMBOL_BID);                      else                         if(csyms[ccy.getsymn()].SymbolCurrencyProfit=="HKD")                            pticv /= SymbolInfoDouble("BTCUSD",SYMBOL_BID) * SymbolInfoDouble("USDHKD",SYMBOL_BID);                         else                           {                            Alert(omagic,cb,ccy.cursym," Unknown account and profit currency combo ",AccountCurrency,cb,csyms[ccy.getsymn()].SymbolCurrencyProfit);                           }            }          else             Alert(omagic,cb,ccy.cursym," Unknown account currency ",AccountCurrency,cb,csyms[ccy.getsymn()].SymbolCurrencyProfit);      }    csyms[ccy.getsymn()].symtcval = pticv;    return;   }


Anyways, it could be a lot of code to cover all the combos but I thought I'd open an official ticket to open discussion. In the meantime maybe just an input dropdown to select either divide or multiply and then a string input for the adjustment symbol would be OK in the EA settings?

Attachments
No attachments
  • Votes +3
  • Project StrategyQuant X
  • Type Bug
  • Status New
  • Priority Normal

History

b
#1

bentra

20.04.2022 07:44

Task created

b
#2

bentra

20.04.2022 07:46
Voted for this task.
E
#3

Emmanuel

20.04.2022 12:21
Voted for this task.
Cc
#4

Cyber

28.04.2022 02:27
Voted for this task.

Votes: +3

Drop files to upload

or

choose files

Max size: 5MB

Not allowed: exe, msi, application, reg, php, js, htaccess, htpasswd, gitignore

...
Wait please