PIP value in account currency

 

Hi

I wrote this code after reading online, not sure how to do the "JPY" part of the code, please help and correct me if there is something wrong with it.

Thanks

// PIP value for standard lot 100,000 units
double getPipValue(){
  string symbol = Symbol();
  int usd = StringFind(symbol, "USD");
  int jpy = StringFind(symbol, "JPY");
  int aud = StringFind(symbol, "AUD");  //account currency
  double valueInUSD;
  double result;

  if(usd == 0){
    valueInUSD = 10/Bid;
  } else if(usd == 3){
    valueInUSD = 10.00;
  } else if (jpy == 0){
    // <<<<<<<<<<<<<<<< NEED HELP
  } else if (jpy == 3){
    // <<<<<<<<<<<<<<<< NEED HELP
  } else {  // pair with no jpy or usd in their symbol
    string qCurr = StringSubstr(symbol, 3); // quote currency
    valueInUSD = MarketInfo(StringConcatenate(qCurr, "USD"), MODE_BID) * 10;
  }
  
  // convert pip value to account currency
  if(aud == 0){
    result = valueInUSD / MarketInfo("AUDUSD", MODE_BID);
  } else {
    result = valueInUSD;
  }
  return result;
}
 
samjesse:

Hi

I wrote this code after reading online, not sure how to do the "JPY" part of the code, please help and correct me if there is something wrong with it.

Thanks

Hi sanjesse

follow my code for you

//+------------------------------------------------------------------+
//
//+------------------------------------------------------------------+
int SymbolsListGet(string &pSymbolsRef[], bool pOnlyOnMarketWatch = false)
{
   int iSymbolNumber = SymbolsTotal(false);
   for ( int i = 0; i < iSymbolNumber; i++ )
   {
      string iSymbolName = SymbolName(i, false);
      int x = ArrayResize(pSymbolsRef, ArraySize(pSymbolsRef) + 1) - 1;
      if ( pOnlyOnMarketWatch )
      {
         if ( SymbolInfoInteger(iSymbolName, SYMBOL_VISIBLE) )
            pSymbolsRef[x] = iSymbolName;
      }
      else
         pSymbolsRef[x] = iSymbolName;
   }
   return ArraySize(pSymbolsRef);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double SymbolPointValue(string pSymbol = NULL, datetime pDt = 0)
{
   pSymbol = pSymbol == NULL || pSymbol == "" ? Symbol() : pSymbol;
   if ( MQLInfoInteger(MQL_TESTER) )
      return SymbolInfoDouble(pSymbol, SYMBOL_TRADE_TICK_VALUE) * 10.0;
   double iPoint = SymbolInfoDouble(pSymbol, SYMBOL_POINT);
   switch( (int) SymbolInfoInteger(pSymbol, SYMBOL_TRADE_CALC_MODE) )
   {
      case 0: //Forex
         if ( Digits == 3 || Digits == 5 )
            iPoint *= 10;   
      break;
      case 1: //Cfd
         if ( (1.0 / SymbolInfoDouble(pSymbol, SYMBOL_TRADE_TICK_SIZE)) != 100.0 )
            iPoint = 1;
      break;
   }
   double iPipValue = SymbolInfoDouble(pSymbol, SYMBOL_TRADE_CONTRACT_SIZE) * iPoint;
   string iAccountCurrency = AccountInfoString(ACCOUNT_CURRENCY);
   string iProfitCurrency = SymbolInfoString(pSymbol, SYMBOL_CURRENCY_PROFIT);
   if ( iAccountCurrency != iProfitCurrency )
   {
      string iAccountAndProfitSymbol = iAccountCurrency + iProfitCurrency;
      string iMarketSymbol = "";
      string iaSymbol[];
      SymbolsListGet(iaSymbol);
      for ( int i = 0; i < ArraySize(iaSymbol); i++ )
      {
         if ( StringFind(iaSymbol[i], iAccountCurrency, 0) >= 0 && StringFind(iaSymbol[i], iProfitCurrency, 0) >= 0 )
            iMarketSymbol = iaSymbol[i];
      }
      double iBid = SymbolInfoDouble(iMarketSymbol, SYMBOL_BID);
      if ( pDt != 0 )
      {
         int iShift = iBarShift(iMarketSymbol, PERIOD_M1, pDt, false);
         iBid = iClose(iMarketSymbol, PERIOD_M1, iShift);
      }
      if ( iAccountAndProfitSymbol != iMarketSymbol )
      {
         iAccountAndProfitSymbol = iMarketSymbol;
         iBid = SymbolInfoDouble(iAccountAndProfitSymbol, SYMBOL_BID) != 0.0 ? 1.0 / SymbolInfoDouble(iAccountAndProfitSymbol, SYMBOL_BID) : 0.0;
         if ( pDt != 0 )
         {
            int iShift = iBarShift(iAccountAndProfitSymbol, PERIOD_M1, pDt, false);
            iBid = iClose(iAccountAndProfitSymbol, PERIOD_M1, iShift) != 0.0 ? 1.0 / iClose(iAccountAndProfitSymbol, PERIOD_M1, iShift) : 0.0;
         }
      }
      iPipValue = iBid == 0 ? 0 : iPipValue / iBid;
   }
   return iPipValue;
}

Eugenio

Reason: