0

Backgound:

  • using mt5
  • "swap" (rollover) price is defined in points (0.00001/0.001) - 5-digit broker
  • account currency: USD

The question is: how to calculate the "swap value" in terms of acc. currency in mt5. With other words, how many cents i will paid for one day rollover?

Currently have this "mql5" script:

#include <Trade\SymbolInfo.mqh>

void OnStart() {

   CSymbolInfo sym;  // symbol informations object
   sym.Name( ChartSymbol() ); // get the object for the current chart symbol

   if( sym.SwapMode() == SYMBOL_SWAP_MODE_POINTS) {

      double lot = 0.1;

      double swapUSD_long = sym.SwapLong() * 0;   // need help here
      double swapUSD_short = sym.SwapShort() * 0; // need help here

      PrintFormat(
         "symbol: %s swap_long: %.2f swap_short: %.2f swapUSD_long: %.2f swapUSD_short: %.2f",
         sym.Name(),
         sym.SwapLong(),
         sym.SwapShort(),
         swapUSD_long,
         swapUSD_short
      );
   }
}

When attaching the script to EURAUD, it prints to terminal:

symbol: EURAUD swap_long: -10.80 swap_short: 6.80 swapUSD_long: 0.00 swapUSD_short: 0.00

so: the rollover price is 6.8 points for the short position. How to convert it to USD with current rate? For this need:

  • find the pair with the acc currency (in this case need find AUDUSD)
  • get the rate of AUDUSD sym.Bid() or sym.Ask()
  • and ...

simply need some help ;)

clt60
  • 62,119
  • 17
  • 107
  • 194
cajwine
  • 3,100
  • 1
  • 20
  • 41

1 Answers1

0

If I understand right your question, you can use the TickValueProfit and TickValueLoss. If the swap to some direction is negative (you will pay) use the TickvalueLoss and when positive use TickValueProfit.

You can make a function for this like the next:

double swap_value_currency(double value_point, double tickprofit, double tickloss)
   {
      if( value_point == 0.0 ) { return(0.0); }
      if( value_point < 0.0 ) {
         return( val * tickloss );
      }
      return( value_point * tickprofit);
   }

The swap_value_currency returns the swap value depending on winning or losing for one standard lot.

so your fragment of code can be:

if( sym.SwapMode() == SYMBOL_SWAP_MODE_POINTS)
   {
      double swval_long = swap_value_currency(sym.SwapLong(),   sym.TickValueProfit(), sym.TickValueLoss());
      double swval_short= swap_vallue_currency(sym.SwapShort(), sym.TickValueProfit(), sym.TickValueLoss() );
   }

and because this is for one standard lot, you need multiply it with your lot size...

clt60
  • 62,119
  • 17
  • 107
  • 194