How to get BID upto 6 Digit?

 

How to get Bid upto 6 Digits?
Please help me with this.

I know I can get it by 

DoubleToStr(Bid,6);

but this is in string format which cannot be used within any other formula.
I want to use it in different formula.

Any help will be really apreciated.

Actually, I am working on get MACD values using formula
Calculating EMA : 

double EMA(int period, int shift)
{
double k = 2./(period+1.),E0 = Close[Bars]*k,EN,EC;
for(int i=1; i<Bars-shift; i++)
 {
  EN = (Close[Bars-i]*k)+(E0*(1-k));
  E0=EN;
 }
EC = (Close[shift]*k)+(E0*(1-k));
return(EC);
}

Calculating MACD Main Line Value:

double MACD(int Period_Slow_EMA, int Period_Fast_EMA, int Shift)
{
 double MACD = EMA(Period_Fast_EMA,Shift)-EMA(Period_Slow_EMA,Shift);
return(MACD);
}

 

but this gives value with 4 decimal points like 0.0003.
But MACD value needs more decimal points to be compared with other MACD Value but with just 4 decimals, that won't be accurate.

And If you are thinking that why I am not using iMACD,

The Reason is I want MACD for Heikin Ashi not normal Candles.
plus I have already calculated Heikin Ashi Open, Low, Close, High using formula.

Can someone please help me with this Issue?

 
Kailash Bai Mina: How to get Bid upto 6 Digits? Please help me with this. I know I can get it by but this is in string format which cannot be used within any other formula. I want to use it in different formula. Any help will be really apreciated. Actually, I am working on get MACD values using formula Calculating EMA : Calculating MACD Main Line Value: but this gives value with 4 decimal points like 0.0003. But MACD value needs more decimal points to be compared with other MACD Value but with just 4 decimals, that won't be accurate. And If you are thinking that why I am not using iMACD, The Reason is I want MACD for Heikin Ashi not normal Candles. plus I have already calculated Heikin Ashi Open, Low, Close, High using formula.

You are mixing apples and oranges. Internally all floating point calculations are done with double precision which has many more digits than 6. It is only when the value is printed that it seems like it has less.

You are probably referring to the value that appears in the data window which by default is set to 4 digits, but you can change that as follows:

Forum on trading, automated trading systems and testing trading strategies

How to trim to i.e. 2 decimal places in the Data window?

Fernando Carreiro, 2021.05.03 12:49

Wrong! To change the number of digits in the Data windows for Inidcator Output, you have to specifically tell the Indicator the number of digits to display! You can't just use rounding or normalising. The correct solution is something like this (as mentioned in post #3):

// Set Number of Significant Digits (Precision)
IndicatorSetInteger( INDICATOR_DIGITS, _Digits );
 
Fernando Carreiro:

You are mixing apples and oranges. Internally all floating point calculations are done with double precision which has many more digits than 6. It is only when the value is printed that it seems like it has less.

You are probably referring to the value that appears in the data window which by default is set to 4 digits, but you can change that as follows:

No, I was using Alert.

 

Floating-point has an infinite number of decimals, it's you, not understanding floating-point and that some numbers can't be represented exactly. (like 1/10.s)
          Double-precision floating-point format - Wikipedia

See also The == operand. - MQL4 programming forum 2013.06.07

If you want to see the correct number of digits, convert it to a string with the correct/wanted accuracy.
          question about decima of marketinfo() - MQL4 programming forum 2016.05.18

 
Kailash Bai Mina: No, I was using Alert.

Then you have to use the Double to String conversion just as you did in your post.

 
Fernando Carreiro:

Then you have to use the Double to String conversion just as you did in your post.

but String Format cannot be used in Formula.

 
Kailash Bai Mina:but String Format cannot be used in Formula.

But you don't use it in the formula! I've already explained that. You only use the conversion when you want to output the final value on the screen or to a file. Not in calculations as it already is using high precision. Unless however, your problem is something else, like accidentally doing integer division.

So, show the specific code that you are having trouble with.

 
Fernando Carreiro:

But you don't use it in the formula! I've already explained that. You only use the conversion when you want to output the final value on the screen or to a file. Not in calculations as it already is using high precision. Unless however, your problem is something else, like accidentally doing integer division.

So, show the specific code that you are having trouble with.


I Want precise value of MACD Main Line Using Formula.

Are you saying that the Alert is showing me 0.0003 (just 4 decimal places)
But in reality if there are 2 value say one is 0.00037 and other is 0.00035 will be compared accurately?

Please note that these values (0.00035 and 0.00037) are calculated by below Functions.

 

Calculating EMA : 

double EMA(int period, int shift)
{
double k = 2./(period+1.),E0 = Close[Bars]*k,EN,EC;
for(int i=1; i<Bars-shift; i++)
 {
  EN = (Close[Bars-i]*k)+(E0*(1-k));
  E0=EN;
 }
EC = (Close[shift]*k)+(E0*(1-k));
return(EC);
}



Calculating MACD Main Line : 

double MACD(int Period_Slow_EMA, int Period_Fast_EMA, int Shift)
{
 double MACD = EMA(Period_Fast_EMA,Shift)-EMA(Period_Slow_EMA,Shift);
return(MACD);
}
The == operand.
The == operand.
  • 2013.06.07
  • www.mql5.com
Hi, can anyone help? This seems a simple task but it does not work...
 
Fernando Carreiro:

But you don't use it in the formula! I've already explained that. You only use the conversion when you want to output the final value on the screen or to a file. Not in calculations as it already is using high precision. Unless however, your problem is something else, like accidentally doing integer division.

So, show the specific code that you are having trouble with.

Problem Solved.

Actually, There was no problem.

It was me who was creating it.

Now I got it.
Thanks you very much.

 

If Someone is reading this Who needs Help in Calculating MACD Values from formula then Below is the Code to do it : 

You can contact me if you need any help.

//+------------------------------------------------------------------+
//|Calculating EMA for MACD Main and Signal Line Calculations        |
//+------------------------------------------------------------------+
double EMA(int period, int shift)
  {
   double k = 2./(period+1.),E0 = Close[Bars]*k,EN,EC;
   for(int i=1; i<Bars-shift; i++)
     {
      EN = (Close[Bars-i]*k)+(E0*(1-k));
      E0=EN;
     }
   EC = (Close[shift]*k)+(E0*(1-k));
   return(EC);
  }

//+------------------------------------------------------------------+
//|Calculating MACD Main Line                                        |
//+------------------------------------------------------------------+
double MACD_Main_Line(int Period_Slow_EMA, int Period_Fast_EMA, int Shift)
  {
   double MACD_Main_Line = EMA(Period_Fast_EMA,Shift)-EMA(Period_Slow_EMA,Shift);
   return(MACD_Main_Line);
  }

//+------------------------------------------------------------------+
//|Calculating MACD Signal Line                                      |
//+------------------------------------------------------------------+
double MACD_Signal_Line_MT(int Period_Slow_EMA,int Period_Fast_EMA, int MACD_SMA_Period, int Shift)
  {
//MT Refers to MeteTrader as Metatrader MACD offers SMA Period for Signal Line but Trading View Offer EMA, So, This is for Metatrader SMA
   double Sum=0;
   for(int i=0; i<MACD_SMA_Period; i++)
      Sum += MACD_Main_Line(Period_Slow_EMA,Period_Fast_EMA,i+Shift);
   double MACD_Signal_Line = Sum/MACD_SMA_Period;
   return(MACD_Signal_Line);
  }
//+------------------------------------------------------------------+
 
You are welcome!
Reason: