Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1169

 
BillionerClub:

Ono, ahaha, been looking for that file for so long. SPC.

The search fails because it's all in a hidden AppData folder.

 

Nowhere have I found how to round a double to the nearest smallest

Example:

   double part1=1.9/12;
   double part2=NormalizeDouble(part1,2);
   
   Comment(part1,"\n", // 0.1583333333
           part2); // 0.16

As a result rounded to 0.16, if we count: 0.16 * 12 = 1.92, i.e. overshoot by 0.02 from 1.9

How to round 0.15833333 to 0.15

 
Vitaly Muzichenko:

Nowhere have I found how to round a double to the nearest smallest

Example:

As a result rounded to 0.16, if we count: 0.16 * 12 = 1.92, i.e. overshoot by 0.02 from 1.9

How to round 0.15833333 to 0.15

For clarity

  int n=0.15833333*100;
  double m=n/100.0;
  string s=DoubleToString(m,2);
 
Alexey Viktorov:

For clarity

Thanks, it works as it should!

 
Sorry for dumb question, but what to do if spread is fractional? TheCopySpread function has int type and if the spread is 0.8 it returns 1
 
VANDER:
Sorry for dumb question, but what if spread is fractional? The CopySpread function has int type and if the spread is 0.8, for example, it returns 1

Should return an '8'. Doing something wrong

 
Now clarified, the spread on the instrument is around 0.02 what should return in this case?
 
VANDER:
Now clarified, the spread on the instrument is around 0.02 what should be returned in this case?

Who did you check with?

 
VANDER:
Now clarified, the spread on the instrument is around 0. 02 what should it return in this case?

It doesn't work like that

 

Like this for example

//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
MqlTick Last;
int sp1[1];
double sp2;
//+------------------------------------------------------------------+
int OnInit()
  {return(INIT_SUCCEEDED);}
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  { }
//+------------------------------------------------------------------+
void OnTick()
  {
   CopySpread("BR-2.20",PERIOD_CURRENT,0,1,sp1);
   SymbolInfoTick("BR-2.20",Last);
   sp2=Last.ask-Last.bid;
   Print((string)sp1[0]+", "+(string)sp2);
  }
//+------------------------------------------------------------------+

2020.01.03 21:16:32.818 Spred (BR-2.20,M1) 1, 0.0100000000000000512

2020.01.03 21:16:32.824 Spred (BR-2.20,M1) 1, 0.02000000000001023

2020.01.03 21:16:33.830 Spred (BR-2.20,M1) 1, 0.020000000001023

2020.01.03 21:16:34.371 Spred (BR-2.20,M1) 1, 0.0100000000000000512

2020.01.03 21:16:34.466 Spred (BR-2.20,M1) 1, 0.010000000000512

2020.01.03 21:16:34.570 Spred (BR-2.20,M1) 1, 0.0099999999999905

2020.01.03 21:16:34.585 Spred (BR-2.20,M1) 1, 0.00999999999999990905

2020.01.03 21:16:34.591 Spred (BR-2.20,M1) 1, 0.0199999999999999602

2020.01.03 21:16:34.629 Spred (BR-2.20,M1) 1, 0.00999999999999990905

2020.01.03 21:16:35.321 Spred (BR-2.20,M1) 1, 0.0199999999999999602

2020.01.03 21:16:35.335 Spred (BR-2.20,M1) 1, 0.0199999999999999602

2020.01.03 21:16:35.352 Spred (BR-2.20,M1) 1, 0.0199999999999999602

2020.01.03 21:16:35.684 Spred (BR-2.20,M1) 1, 0.0199999999999999602

2020.01.03 21:16:35.790 Spred (BR-2.20,M1) 1, 0.00999999999999990905

2020.01.03 21:16:35.981 Spred (BR-2.20,M1) 1, 0.00999999999999990905

2020.01.03 21:16:36.220 Spred (BR-2.20,M1) 1, 0.010000000000000000512

2020.01.03 21:16:36.235 Spred (BR-2.20,M1) 1, 0.0199999999999999602

2020.01.03 21:16:36.311 Spred (BR-2.20,M1) 1, 0.00999999999999990905

2020.01.03 21:16:36.769 Spred (BR-2.20,M1) 1, 0.00999999999999990905

2020.01.03 21:16:37.373 Spred (BR-2.20,M1) 1, 0.0199999999999999602

2020.01.03 21:16:38.049 Spred (BR-2.20,M1) 1, 0.0199999999999999602


Reason: