Download MetaTrader 5

double to integer

To add comments, please log in or register
jshumaker
507
jshumaker  

I am getting a bunch of warnings 'possible loss of data due to type conversion'.  I am trying to convert my macd values to integers so that when I print data on my charts it is easier to read.  That is why I multiply by the MACD by 10,000.  Is there a way to do this such that I do not get all of these warning?

bool CIndicatorPool::InitMacd(int fastEMA,int slowEMA,int signalEMA,ENUM_APPLIED_PRICE appliedPrice)
{
   macdh = iMACD(m_symbol, m_period, fastEMA, slowEMA, signalEMA, appliedPrice);
   if (macdh == INVALID_HANDLE) return (false);
   else return (true);
}
//+------------------------------------------------------------------+
int CIndicatorPool::MacdBar(int shift)
{
   double buf[1];
   if (macdh == INVALID_HANDLE) return (0);
   else
   {
     if (CopyBuffer(macdh, 0, shift, 1, buf) == 1)
        return (StringToInteger(DoubleToString (10000 * buf[0])));
     else
        return (0);
   }
}
Documentation on MQL5: Language Basics / Data Types / Typecasting
Documentation on MQL5: Language Basics / Data Types / Typecasting
  • www.mql5.com
Language Basics / Data Types / Typecasting - Documentation on MQL5
Alain Verleyen
Moderator
31476
Alain Verleyen  
jshumaker:

I am getting a bunch of warnings 'possible loss of data due to type conversion'.  I am trying to convert my macd values to integers so that when I print data on my charts it is easier to read.  That is why I multiply by the MACD by 10,000.  Is there a way to do this such that I do not get all of these warning?

Replace

        return (StringToInteger(DoubleToString (10000 * buf[0])));

by

        return ((int)(10000.0 * buf[0]));
To add comments, please log in or register