Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 106
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Please advise on a solution to the rounding problem!
I need to get rid of the decimal point without a remainder - rounding and exponentiation do not solve the whole problem - what should I do?
For example it was 1.44430 and I need 144430.
Part of the code - as is
NormalizeDouble(Low[1],Digits)*MathPow(10,(Digits+1)*1-1)
Just divide by _Point.
Wrong result prints, the original is 161188 (1.61188) your method 161187 print gives 1.6119 (why rounding up does it do when print Low[1] if five decimal places?), my version is 161188.
But if we complicate the problem.
long Calc=
NormalizeDouble(Close[1],Digits)*MathPow(10,(Digits+1)*3-1)+
NormalizeDouble(High[1],Digits)*MathPow(10,(Digits+1)*2-1)+
NormalizeDouble(Low[1],Digits)*MathPow(10,(Digits+1)*1-1);
That is, the last part of the number 161184 - ie divergence of 4 units.
Your Variant of this expression produces the same value
NormalizeDouble(Close[1],Digits)*MathPow(10,(Digits+1)*3-1)+
NormalizeDouble(High[1],Digits)*MathPow(10,(Digits+1)*2-1)+
Low[1]/Point;
Any idea what the error is and how to fix it?
Wrong result prints, the original is 161188 (1.61188) your method 161187 print gives 1.6119 (why rounding up does it do when print Low[1] if five decimal places?), my version is 161188.
But if we complicate the problem.
long Calc=
NormalizeDouble(Close[1],Digits)*MathPow(10,(Digits+1)*3-1)+
NormalizeDouble(High[1],Digits)*MathPow(10,(Digits+1)*2-1)+
NormalizeDouble(Low[1],Digits)*MathPow(10,(Digits+1)*1-1);
That is, the last part of the number 161184 - ie divergence of 4 units.
Your variant in this expression gives the same value
NormalizeDouble(Close[1],Digits)*MathPow(10,(Digits+1)*3-1)+
NormalizeDouble(High[1],Digits)*MathPow(10,(Digits+1)*2-1)+
Low[1]/Point;
Any idea what the error is and how to fix it?
void OnStart()
{
string i = DoubleToString(SymbolInfoDouble(_Symbol, SYMBOL_BID)/_Point, 0);
Print(i);
Print(SymbolInfoDouble(_Symbol, SYMBOL_BID)/_Point);
}/*******************************************************************/
Run it like this.
void OnStart()
{
string i = DoubleToString(SymbolInfoDouble(_Symbol, SYMBOL_BID)/_Point, 0);
Print(i);
Print(SymbolInfoDouble(_Symbol, SYMBOL_BID)/_Point);
}/*******************************************************************/
Yes, the string variable gets the correct number (preliminarily), but zeros 161188.00000000 are added, how do I get rid of them?
Yes, the string variable gets the correct number (preliminarily), but zeros 161188.00000000 are added, how do I get rid of them?
There are no zeros in my code. Look how it is written.
Thank you - I missed a zero.
This is the construction.
DoubleToString(Close[1]/_Point,0)+
DoubleToString(High[1]/_Point,0)+
DoubleToString(Low[1]/_Point,0);
Print("CalcX=",CalcX);
Now I need to decompose these numbers back into their components.
When I try to convert the string to a number, I again get the wrong number 161184 instead of 161188
Print("testX=",testX);
I should probably cut the string, but how can I do it optimally?
Yes, the string variable gets the correct number (preliminarily), but zeros 161188.00000000 are added, how do I get rid of them?
So... show me the pattern. How do you know what's in there?
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
Thank you - I missed the zero.
It came up with this construction
DoubleToString(Close[1]/_Point,0)+
DoubleToString(High[1]/_Point,0)+
DoubleToString(Low[1]/_Point,0);
Print("CalcX=",CalcX);
Now I need to decompose these numbers back to their components.
When I try to convert the string to a number, I again get wrong number 161184 instead of 161188
Print("testX=",testX);
I should probably cut the string, but how can I do it optimally?
Well, if you have an overwhelming desire to make a mess, convert the string back to a number StringToDouble() and multiply by _Point with normalization to the desired number of digits, probably _Digits