Do I have to NormalizeDouble Everything ? - page 3

 
@Fernando Carreiro #:

Now that I read your post again, I now see that you don't want to use DoubleToString.

However, you can not limit a floating point to only 4 digits, because floating point numbers are not decimal. They are binary.

Thank you very much for your prompt response. Yes, because I need this value further in my code to do more calculations, I cannot convert it to string.


I was wondering if I can't limit the digits to 4, is there some kind of function I can call to get the value with 4 digits, or any other solution/calculation that will allow me to get my desired value?


Appreciate any help and Thanks for reading :)

 
Loddy the Redeemed #:

I find it ridiculous that you want to use 4 decimal places. In practice (unless you want to do HFT) decimals are worthless in the case of RSI. If 2 is already too many... 4 is a fantasy.

 
Miguel Angel Vico Alba #:

I find it ridiculous that you want to use 4 decimal places. In practice (unless you want to do HFT) decimals are worthless in the case of RSI. If 2 is already too many... 4 is a fantasy.

Thank you for your prompt response. Yes, I agree 2 digits are enough to get RSI value, but I need this solution for many other functions/calculations in my code, hence I cannot convert it to string & was wondering if there's some kind of function I can call to get the value with 4 digits, or any other solution/calculation that will allow me to get my desired value?


Appreciate any help and Thanks for reading :)

 
Loddy the Redeemed #: I was wondering if I can't limit the digits to 4, is there some kind of function I can call to get the value with 4 digits, or any other solution/calculation that will allow me to get my desired value?

As already explained, floating point numbers are represented in binary form, not in decimal form. It is impossible to limit the number of "decimal" digits internally.

All you can do is approximate it, which is what NormaliseDouble already does, but you can never get to an exact decimal place because it is binary, not decimal.

 
Loddy the Redeemed #:

Thank you for your prompt response. Yes, I agree 2 digits are enough to get RSI value, but I need this solution for many other functions/calculations in my code, hence I cannot convert it to string & was wondering if there's some kind of function I can call to get the value with 4 digits, or any other solution/calculation that will allow me to get my desired value?


Appreciate any help and Thanks for reading :)

double RSI = iRSI(NULL,0,14,0,0);
Alert("RSI : " + RSI);
double NormRSI = NormalizeDouble(RSI, 4);
Alert("Normalized RSI : " + (string)NormRSI);

Where before you put a "Digits", now simply put the number of decimals (4).

 
Fernando Carreiro #:

As already explained, floating point numbers are represented in binary form, not in decimal form. It is impossible to limit the number of "decimal" digits internally.

All you can do is approximate it, which is what NormaliseDouble already does, but you can never get to an exact decimal place because it is binary, not decimal.

Thanks, that is sad to know :(

Miguel Angel Vico Alba #:

Where before you put a "Digits", now simply put the number of decimals (4).

Thank you for your prompt response, But as mentioned earlier I don't want to use NormalizeDouble, as it doesn't work sometimes.
 
Loddy the Redeemed #Thank you for your prompt response, But as mentioned earlier I don't want to use NormalizeDouble, as it doesn't work sometimes.

What do you mean, sometimes it doesn't work? Please argue that.

It works perfectly. Please read carefully what I said above.

https://www.mql5.com/en/forum/135572/page2#comment_47926093

 
Miguel Angel Vico Alba #:

What do you mean, sometimes it doesn't work? Please argue that.

It works perfectly. Please read carefully what I said above.

https://www.mql5.com/en/forum/135572/page2#comment_47926093

So, Here's a part of My Code that is perfectly correct (or at least what I've been thinking) but still get this wired output(attached) with NormalizeDouble 

Code

#property copyright "Loddy the Redeemed"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

#property show_inputs
#include <CustomFunctions001.mqh>

input int URSIBand=60;
input int LRSIBand=40;

input int bbperiod=50;
input int TPBand=1;
input int EntryBand=2;
input int SLBand=6;

extern double OrderUpdateDistanceinPips=3;
input double mxrisk=0.02;
input int MagicNo=25802580;
int OrderID;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   Alert("----------EA STARTED-----------");
   double RSI = NormalizeDouble(iRSI(NULL,0,14,0,0),Digits);
   double MidBand = NormalizeDouble(iBands(NULL,0,bbperiod,1,0,0,0,0),Digits);
   double UBand1 = NormalizeDouble(iBands(NULL,0,bbperiod,TPBand,0,0,1,0),Digits);
   double LBand1 = NormalizeDouble(iBands(NULL,0,bbperiod,TPBand,0,0,2,0),Digits);
   double UBand2 = NormalizeDouble(iBands(NULL,0,bbperiod,EntryBand,0,0,1,0),Digits);
   double LBand2 = NormalizeDouble(iBands(NULL,0,bbperiod,EntryBand,0,0,2,0),Digits);
   double UBand3 = NormalizeDouble(iBands(NULL,0,bbperiod,SLBand,0,0,1,0),Digits);
   double LBand3 = NormalizeDouble(iBands(NULL,0,bbperiod,SLBand,0,0,2,0),Digits);
   Alert("1 SD Lower Band : "+LBand1);
   Alert("1 SD Upper Band : "+UBand1);
   Alert("6 SD Lower Band : "+LBand3);
   Alert("6 SD Upper Band : "+UBand3);
   Alert("2 SD Lower Band : "+LBand2);
   Alert("2 SD Upper Band : "+UBand2);
   Alert("Mid Band : "+MidBand); 
   Alert("RSI : " + RSI);
  }

Any Help to why would be appreciated, Thanks

Files:
Output.png  10 kb
 
Loddy the Redeemed #:
#property copyright "Loddy the Redeemed"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

#property show_inputs
#include <CustomFunctions001.mqh>

input int URSIBand=60;
input int LRSIBand=40;

input int bbperiod=50;
input int TPBand=1;
input int EntryBand=2;
input int SLBand=6;

extern double OrderUpdateDistanceinPips=3;
input double mxrisk=0.02;
input int MagicNo=25802580;
int OrderID;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   Alert("----------EA STARTED-----------");
   double RSI = NormalizeDouble(iRSI(NULL,0,14,0,0),4);
   double MidBand = NormalizeDouble(iBands(NULL,0,bbperiod,1,0,0,0,0),4);
   double UBand1 = NormalizeDouble(iBands(NULL,0,bbperiod,TPBand,0,0,1,0),4);
   double LBand1 = NormalizeDouble(iBands(NULL,0,bbperiod,TPBand,0,0,2,0),4);
   double UBand2 = NormalizeDouble(iBands(NULL,0,bbperiod,EntryBand,0,0,1,0),4);
   double LBand2 = NormalizeDouble(iBands(NULL,0,bbperiod,EntryBand,0,0,2,0),4);
   double UBand3 = NormalizeDouble(iBands(NULL,0,bbperiod,SLBand,0,0,1,0),4);
   double LBand3 = NormalizeDouble(iBands(NULL,0,bbperiod,SLBand,0,0,2,0),4);
   Alert("1 SD Lower Band : "+(string)LBand1);
   Alert("1 SD Upper Band : "+(string)UBand1);
   Alert("6 SD Lower Band : "+(string)LBand3);
   Alert("6 SD Upper Band : "+(string)UBand3);
   Alert("2 SD Lower Band : "+(string)LBand2);
   Alert("2 SD Upper Band : "+(string)UBand2);
   Alert("Mid Band : "+(string)MidBand); 
   Alert("RSI : "+(string)RSI);
  }
 
Miguel Angel Vico Alba #:

Below is my simple code to get MA values. Now the output I get is different value on different candles using NormalizeDouble Function, even though I haven't changed the code, but just the shift value to get the value of different candles. The value displayed by NormalizedDouble Function is not consistent. Even if I use Digits or put the number 4 manually in my code.

I've attached the Output of my code as well.

This is what I was referring when I said that the Normalize double function is not working sometimes.

input int HigherMABand=21;
input int LowerMABand=20;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   Alert("----------SCRIPT STARTED-----------");
   
   double FirstHigherBand = iMA(NULL,0,HigherMABand,2,MODE_SMA,PRICE_CLOSE,-1);
   Alert("1stHigherBand "+FirstHigherBand);
   Alert("Normalised Value using digits, 1stHigherBand "+NormalizeDouble(FirstHigherBand,Digits));
   Alert("Normalised Value using no 4 for the 1stHigherBand "+NormalizeDouble(FirstHigherBand,4));
   
  
   Alert("----------SCRIPT CLOSED-----------");
   
  }