Swap Calculation issues - page 2

 
Dwaine Hinds:
Moved to https://www.mql5.com/en/forum/309871

Again a new discussion. 
Complicate to see then which one to follow  😥
Moreover, no one followed or responded to either of the two discussions, which is a pity because it would have been interesting to get feedback on your work which I find interesting.

 

Hi, I  want to calculate swap rates for current day, and this is what I came to... One question is it correct...

Why I'm asking - because there is little information on this subject and I'm not sure.. .  If it is wrong please show right direction - thank You...

   string BaseCurrency = SymbolInfoString(_Symbol, SYMBOL_CURRENCY_BASE);
   string ProfitCurrency = SymbolInfoString(_Symbol, SYMBOL_CURRENCY_PROFIT);
   string accountCurrency = AccountCurrency();
   double pValue = PointValue(1.0);
   double swapPointsLong = SymbolInfoDouble(_Symbol, SYMBOL_SWAP_LONG);
   double swapPointsShort = SymbolInfoDouble(_Symbol, SYMBOL_SWAP_SHORT);
   int swapType = MarketInfo(_Symbol, MODE_SWAPTYPE);
   double exchangeRate;
   if(accountCurrency == ProfitCurrency)
   {
      exchangeRate = 1;
   }
   else
   {
      exchangeRate = MarketInfo(accountCurrency + ProfitCurrency, MODE_ASK);
   }
   double swapLong;
   double swapShort;
   
   switch(swapType)
   {
      case 0 :
         swapLong = swapPointsLong / exchangeRate;
         swapShort = swapPointsShort / exchangeRate;
         break;
      case 1 :
         exchangeRate = (accountCurrency == BaseCurrency) ? 1;
         swapLong = swapPointsLong / exchangeRate;
         swapShort = swapPointsShort / exchangeRate;
         break;
       case 2 :
         exchangeRate = (accountCurrency == "USD") ? 1 : MarketInfo(accountCurrency + "USD", MODE_ASK);
         swapLong = ((swapPointsLong / 360) * pValue) / exchangeRate;
         swapShort = ((swapPointsShort / 360) * pValue) / exchangeRate;
         break;
      case 3 :
         swapLong = swapPointsLong;
         swapShort = swapPointsShort;
         break;
   }