Margin calculation modes

 

This seem like it was easy to accomplish by laying out all the different kinds of the margin assessments for MT4 that could be called 

by market info as integer and translated as string but turned out to be different results as compared with different brokers.

None of these were accurate across various brokers.


string SymbolCalcMode(int Mode)
 {
 switch(Mode)
  {
  case 0: return("Forex");
  case 1: return("Forex(no leverage)");
  case 2: return("Futures");
  case 3: return("CFD");
  default: return("Unknown Margin Calc.");
  }
 return("tried");
 }
string SymbolCalcMode(int Mode)
 {
 switch(Mode)
  {
  case 0: return("Forex");
  case 1: return("Forex(no leverage)");
  case 2: return("Futures");
  case 3: return("CFD");
  case 4: return("CFD Index");
  case 5: return("CFD Leverage");
  case 6: return("Exch Stocks");
  case 7: return("Exch Futures");
  case 8: return("Exch Future Forts");
  case 9: return("Exch Bonds");
  case 10: return("Exch Stocks MoEx");
  case 11: return("Exch Bonds MoEx");
  case 12: return("Serv Collateral");
  default: return("Unknown Margin Calc.");
  }
 return("tried");
 }
 
Brian Lillard:

This seem like it was easy to accomplish by laying out all the different kinds of the margin assessments for MT4 that could be called 

by market info as integer and translated as string but turned out to be different results as compared with different brokers.

None of these were accurate across various brokers.


Hi, this will help with "universality" ;) https://www.mql5.com/en/docs/convert/stringformat

int calc_mode=(int)SymbolInfoInteger(symbol,SYMBOL_TRADE_CALC_MODE);
   string str_calc_mode;
   switch(calc_mode)
     {
      case SYMBOL_CALC_MODE_FOREX:str_calc_mode="SYMBOL_CALC_MODE_FOREX (Forex)";break;
      case SYMBOL_CALC_MODE_FOREX_NO_LEVERAGE:str_calc_mode="SYMBOL_CALC_MODE_NO_LEVERAGE (Forex No Leverage)";break;
      case SYMBOL_CALC_MODE_FUTURES:str_calc_mode="SYMBOL_CALC_MODE_FUTURES (Futures)";break;
      case SYMBOL_CALC_MODE_CFD:str_calc_mode="SYMBOL_CALC_MODE_CFD (CFD)";break;
      case SYMBOL_CALC_MODE_CFDINDEX:str_calc_mode="SYMBOL_CALC_MODE_CFDINDEX (CFD Index)";break;
      case SYMBOL_CALC_MODE_CFDLEVERAGE:str_calc_mode="SYMBOL_CALC_MODE_CFDLEVERAGE (CFD Leverage)";break;
      case SYMBOL_CALC_MODE_EXCH_STOCKS:str_calc_mode="SYMBOL_CALC_MODE_EXCH_STOCKS (Stocks)";break;
      case SYMBOL_CALC_MODE_EXCH_FUTURES:str_calc_mode="SYMBOL_CALC_MODE_EXCH_FUTURES (Exchange Futures)";break;
      case SYMBOL_CALC_MODE_EXCH_FUTURES_FORTS:str_calc_mode="SYMBOL_CALC_MODE_EXCH_FUTURES_FORTS (FORTS Futures)";break;
      case SYMBOL_CALC_MODE_EXCH_BONDS:str_calc_mode="SYMBOL_CALC_MODE_EXCH_BONDS (Bonds)";break;
      case SYMBOL_CALC_MODE_EXCH_STOCKS_MOEX:str_calc_mode="SYMBOL_CALC_MODE_EXCH_STOCKS_MOEX (MOEX Stocks)";break;
      case SYMBOL_CALC_MODE_EXCH_BONDS_MOEX:str_calc_mode="SYMBOL_CALC_MODE_EXCH_BONDS_MOEX (MOEX Bonds)";break;
      case SYMBOL_CALC_MODE_SERV_COLLATERAL:str_calc_mode="SYMBOL_CALC_MODE_SERV_COLLATERAL (Collateral)";break;
      
     }
Documentation on MQL5: Conversion Functions / StringFormat
Documentation on MQL5: Conversion Functions / StringFormat
  • www.mql5.com
"   SYMBOL_TRADE_STOPS_LEVEL = %d (minimal indention in points for Stop orders)\n"                                                                                        "SYMBOL_SWAP_MODE_INTEREST_CURRENT (as the specified annual interest from the instrument price at calculation of swap...
 
This is a fault in the enum, i postet this already in the russian forum with the release notes