[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 319

 
drknn:

You can convert a number to a string and write a function to process the characters in that string. It's not complicated here - we only round a number if it has more than one digit after the decimal point.
OK, I'll really try it. Thank you very much for the idea!
 
okvseok:

there is a function "double MathRound( double value)", but I need the rounding to a larger decimal fraction, and if the number is integer or already decimal, then leave it alone.

For example: 1) 0.744 round to 0.8; 1.233 round to 1.3

2) 0.9 or 3 or 1.5 do not touch.

double MathRoundDec(double dValue) 
 {
  if (dValue == NormalizeDouble(dValue, 1)) return(dValue);
  return(MathRound(10 * dValue) / 10);  
 }
I haven't checked, but that's about it.
 
Zhunko:
Didn't check it, but somehow.


Completely useless gesture enough double res=NormalizeDouble(res,1) mathematically still handle double res = 3; or double res = 3.0;

The difference will only be visible in printout (graph), but this is not in the author's description of the problem.

 
FAQ:


Completely useless gesture enough double res=NormalizeDouble(res,1) mathematically still handle double res = 3; or double res = 3.0;

The difference will only be visible in the printout (graph), but this is not in the author's description of the problem.

Well, you can do it this way:

double MathRoundDec(double dValue) 
 {
  return(MathRound(10 * dValue) / 10);  
 }
I think the first variant is better. It will work faster.
 
Zhunko:

Well, you could go like this:

I think the first option is best. It will work faster.


This option.

 double res=NormalizeDouble(res,1);

should be the fastest

 
Thank you all. I'll report back on Monday - I'll try all the options!
 
Vadim's version is 20-25% faster, but the effect starts to show up steadily when the number of iterations exceeds a million. (checked)
 
FAQ:
Vadim's version is 20-25% faster, but the effect starts to show up steadily when the number of iterations exceeds a million. (checked)

Show me the code, how did you check it
 
FAQ:
Vadim's version is 20-25% faster, but the effect starts to show up steadily when the number of iterations exceeds a million. (tested)
Thank you very much!
 
okvseok:

the correct way to write it: if (OrderSelect (OrdersHistoryTotal()-1, SELECT_BY_POS, MODE_HISTORY) == OrderTakeProfit() == OrderClosePrice()) Stop=false // i.e. if the last order from the end closed at Take Profit (taking profit upon reaching a certain level), the Stop=false? (Stop in global variables)

this question has arisen because the order opens by a condition if((iClose(NULL,0,1)<ma) && Stop==True)...