possible loss of data due to type conversion

 
//+------------------------------------------------------------------+
//|  Price Span,High,Low                                                                |
//+------------------------------------------------------------------+
int priceS(double priceH,double priceL)
  {
   int s=MathAbs(NormalizeDouble(priceH,_Digits)-NormalizeDouble(priceL,_Digits))/_Point;
   return(s);
  }

possible loss of data due to type conversion (MQL5)


i have a couple days to google with this problem but no to avail. Anybody help to correct my own code. thanks in advance!


Documentation on MQL5: Language Basics / Data Types / Typecasting
Documentation on MQL5: Language Basics / Data Types / Typecasting
  • www.mql5.com
Often a necessity occurs to convert one numeric type into another. Not all numeric types can be converted into another. Here is the scheme of allowed casting: Solid lines with arrows indicate changes that are performed almost without any loss of information. Instead of the char type, the bool type can be used (both take 1 byte of memory...
 
MikelDavao:

possible loss of data due to type conversion

Try

 int s=(int)(MathAbs(NormalizeDouble(priceH,_Digits)-NormalizeDouble(priceL,_Digits))/_Point);
 
MikelDavao:

possible loss of data due to type conversion


i have a couple days to google with this problem but no to avail. Anybody help to correct my own code. thanks in advance!


Hi

The result of your function is a double but your casting it to an int implicitly. 

You can fix it this way:

double priceS(double priceH,double priceL)
{
   double s=MathAbs(NormalizeDouble(priceH,_Digits)-NormalizeDouble(priceL,_Digits))/_Point;
   return(s);
}

or

int priceS(double priceH,double priceL)
{
   int s = (int)(MathAbs(NormalizeDouble(priceH,_Digits)-NormalizeDouble(priceL,_Digits))/_Point);
   return(s);
}
 
Keith Watford:

Try

same error.

 
Ehsan Tarakemeh:

Hi

The result of your function is a double but your casting it to an int implicitly. 

You can fix it this way:

or

same error

 
Ehsan Tarakemeh:

Hi

The result of your function is a double but your casting it to an int implicitly. 

You can fix it this way:

or

when I change to double, it creates 49 errors. but at this time of writing i try to fix affected lines. i post it again if error is continue. tnx.

 
Ehsan Tarakemeh:

Hi

The result of your function is a double but your casting it to an int implicitly. 

You can fix it this way:

or

when I change affected lines, it result back to error. the issue is unresolved. any ideas why i encountered that error? is there a solution of getting "Difference" between two Price involved in my coding and produce int result?

 
MikelDavao:

when I change affected lines, it result back to error. the issue is unresolved. any ideas why i encountered that error? is there a solution of getting "Difference" between two Price involved in my coding and produce int result?

Solutions given to you in posts #1 and #2 should work.

If not, please show more of your code.


edit:

personally, I do prefer this... 

int priceS(double priceH,double priceL)
  {
   int s = int(MathAbs(NormalizeDouble(priceH-priceL,_Digits)/_Point));
   return(s);
  }
 
Seng Joo Thio:

Solutions given to you in posts #1 and #2 should work.

If not, please show more of your code.


edit:

personally, I do prefer this... 

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2018, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
int iMN1C1us=0, iMN1C1rb=0, iMN1C1ls=0, iMN1C1cl=0;
int priceS(double priceH,double priceL)
  {
   int s = MathAbs(NormalizeDouble(priceH,_Digits)-NormalizeDouble(priceL,_Digits))/_Point;
   return(s);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   if(iOpen(Symbol(),PERIOD_MN1,1)<iClose(Symbol(),PERIOD_MN1,1))
     {
      //Pd1T="Bl";
      iMN1C1us=priceS(iHigh(Symbol(),PERIOD_MN1,1),iClose(Symbol(),PERIOD_MN1,1));
      iMN1C1rb=priceS(iClose(Symbol(),PERIOD_MN1,1),iOpen(Symbol(),PERIOD_MN1,1));
      iMN1C1ls=priceS(iOpen(Symbol(),PERIOD_MN1,1),iLow(Symbol(),PERIOD_MN1,1));
      iMN1C1cl=priceS(iHigh(Symbol(),PERIOD_MN1,1),iLow(Symbol(),PERIOD_MN1,1));
     }
   else
      if(iOpen(Symbol(),PERIOD_MN1,1)>iClose(Symbol(),PERIOD_MN1,1))
        {
         //Pd1T="Br";
         iMN1C1us=priceS(iHigh(Symbol(),PERIOD_MN1,1),iOpen(Symbol(),PERIOD_MN1,1));
         iMN1C1rb=priceS(iOpen(Symbol(),PERIOD_MN1,1),iClose(Symbol(),PERIOD_MN1,1));
         iMN1C1ls=priceS(iClose(Symbol(),PERIOD_MN1,1),iLow(Symbol(),PERIOD_MN1,1));
         iMN1C1cl=priceS(iHigh(Symbol(),PERIOD_MN1,1),iLow(Symbol(),PERIOD_MN1,1));
        }
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {

  }
//+------------------------------------------------------------------+

please consider the algo of the program. it result same errors " possible loss of data due to type conversion "

"

 
MikelDavao:

please consider the algo of the program. it result same errors " possible loss of data due to type conversion "

"

Of course.

Because it doesn't contain the fix recommended in posts #1 and #2.

 
Seng Joo Thio:

Of course.

Because it doesn't contain the fix recommended in posts #1 and #2.

do you have any ideas to fix the warning? 


Reason: