Double vs FLOAT - unclear MathFloor error

 

Hi all, I'm getting tired of the accuracy of the quotes. Normalisations and so on.

      float AUTOPRICE;
      float askP=NormalizeDouble(Ask,Digits)/NormalizeDouble(Point,Digits);
      float bidP=NormalizeDouble(Bid,Digits)/NormalizeDouble(Point,Digits);
      float Averab=((askP+bidP))/2.0;
      AUTOPRICE=MathFloor(Averab)*Point;
      Print("FLOAT  "+"  askP="+askP+" bidP="+bidP+" Averab="+DoubleToString(Averab,10)+" AUTOPRICE="+DoubleToString(AUTOPRICE,10));

      double AUTOPRICE2;
      double askP2=NormalizeDouble(Ask,Digits)/NormalizeDouble(Point,Digits);
      double bidP2=NormalizeDouble(Bid,Digits)/NormalizeDouble(Point,Digits);
      double Averab2=((askP2+bidP2))/2.0;
      AUTOPRICE2=MathFloor(Averab2)*Point;
      Print("DOUBLE  "+"  askP2="+askP2+" bidP2="+bidP2+" Averab2="+DoubleToString(Averab2,10)+" AUTOPRICE="+DoubleToString(AUTOPRICE2,10));

spread:2

2017.02.26 09:56:54.475 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30:DOUBLE askP2=105143 bidP2=105141 Averab2=105142.000000 AUTOPRICE=1.0514200000

2017.02.26 09:56:54.475 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30:FLOAT askP=105143 bidP=105141 Averab=105142.0000000000 AUTOPRICE=1.0514199734




spread:3

2017.02.26 09:57:47.832 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30:DOUBLE askP2=105144 bidP2=105141 Averab2=105142.5000000000 AUTOPRICE=1.0514200000

2017.02.26 09:57:47.832 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30:FLOAT askP=105144 bidP=105141 Averab=105142.5000000000 AUTOPRICE=1.0514199734


spread:4

2017.02.26 09:58:05.813 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30:DOUBLE askP2=105145 bidP2=105141 Averab2=105143.000000 AUTOPRICE=1.0514200000

2017.02.26 09:58:05.813 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30:FLOAT askP=105145 bidP=105141 Averab=105143.0000000000 AUTOPRICE=1.0514299870

spread:5

2017.02.26 09:58:39.495 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30:DOUBLE askP2=105146 bidP2=105141 Averab2=105143.5000000000 AUTOPRICE=1.0514300000

2017.02.26 09:58:39.495 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30:FLOATaskP=105146 bidP=105141 Averab=105143.5000000000 AUTOPRICE=1.0514299870

Those extra signs are somewhere at the end of the tunnel..........

 
      double askP=NormalizeDouble(Ask,Digits)/NormalizeDouble(Point,Digits);
      double bidP=NormalizeDouble(Bid,Digits)/NormalizeDouble(Point,Digits);

      double Averab=((askP+bidP)*1)/2.0;
      Print("askP="+askP+" bidP="+bidP+" Averab="+Averab+" MathFloor((int)Averab)="+MathFloor((int)Averab));

at spread=2

askP=105143 bidP=105141 Averab=105142 MathFloor((int)Averab)=105142

at spread=3

askP=105144 bidP=105141 Averab=105142.5 MathFloor((int)Averab)=105142

at 4!!!! spread

askP=105545 bidP=105141 Averab=105143 MathFloor((int)Averab)=105142

why ?

 
Vladislav Andruschenko:

Hi all, I'm getting tired of the accuracy of the quotes. Normalisations and so on.

You should somehow be able to understand what double and int are. How type conversion works.

I've never used MathMod and MathFloor. Your code screams a lot that you don't understand at all what is behind what you've written.

The printout of the double number is about nothing. If you want to print the true value of double, you need to look at its bytes.

 

priming only to avoid having to write it manually,

The variable itself doesn't give the result I expect from it.

Type conversion, int normalisation and dubbing are what I've been doing without help.

At the moment I'm desperate as I've tried all the options. and put up a piece of 1 in 1000 code that doesn't work as it should.

But thanks for the help.

Try to do what I want: don't show me the code afterwards, just tell me if it works or not.

Take Ask and Bid.

and calculate the average price.

If the spread is odd (3,5,7,9, etc.) then equate the average price closer to Bid.

For example:

Bid=1.55555 Ask=1.55557 Average price=1.55556 Spread=2

Bid=1.5555 Ask=1.55558 Average price=1.55556 Spread=3

and you will get it right.

But when the spread is 4,5,6,7 - you will have that accuracy going into the unknown. And the numbers will swim the wrong way.

 
Vladislav Andruschenko:
      double askP=NormalizeDouble(Ask,Digits)/NormalizeDouble(Point,Digits);
      double bidP=NormalizeDouble(Bid,Digits)/NormalizeDouble(Point,Digits);

      double Averab=((askP+bidP)*1)/2.0;
      Print("askP="+askP+" bidP="+bidP+" Averab="+Averab+" MathFloor((int)Averab)="+MathFloor((int)Averab));

at spread=2

askP=105143 bidP=105141 Averab=105142 MathFloor((int)Averab)=105142

at spread=3

askP=105144 bidP=105141 Averab=105142.5 MathFloor((int)Averab)=105142

at 4!!!! spread

askP=105545 bidP=105141 Averab=105143 MathFloor((int)Averab)=105142

why ?

Once I had a similar situation - my mind was boiling with indignation. Replacing double for float helped , I still don't know why.

 
sibirqk:
I had a similar situation once - my mind was boiling with indignation at the time. Replacing double with float helped , I still don't know why.

Thanks, I'll give it a try........ I'm getting my mind blown too.

YES!!! That's exactly how it works! it's ok.

float askP=NormalizeDouble(Ask,Digits)/NormalizeDouble(Point,Digits);
float bidP=NormalizeDouble(Bid,Digits)/NormalizeDouble(Point,Digits);
float Averab=((askP+bidP))/2.0;

Thanks!!! I don't know what I'd do anymore........

 
#define ALPHA 0.1

int askP = (int)(Ask / Point + ALPHA);
int bidP = (int)(Bid / Point + ALPHA);

This is how MathFloor works

int MyMathFloor( const double Num )
{
  return((int)((Num > 0) ? Num : Num - 1));
}
 
double Averab = NormalizeDouble ((Ask + Bid)/(2.0 * Point), Digits);
 
fxsaber:
#define ALPHA 0.1

int askP = (int)(Ask / Point + ALPHA);
int bidP = (int)(Bid / Point + ALPHA);

This is how MathFloor works

int MyMathFloor( const double Num )
{
  return((int)((Num > 0) ? Num : Num - 1));
}

for different spreads? including 2,3,4,5,6,7 ?

Because I tried your way before (without+ ALPHA). 2,3 spread is ok, but 4,5 is already a glitch

Andrey Dik:
double Averab = NormalizeDouble ((Ask + Bid)/2.0, Digits);

Normalization, this is the first thing I did in the function, but unfortunately at certain spreads, it starts to glitch

 
Vladislav Andruschenko:

normalisation is the first thing I did in the function, but unfortunately at certain spreads, it starts to glitch

I fixed it, try it now.
 
Vladislav Andruschenko:

take the Ask and Bid.

and calculate the average price.

If the spread is odd (3,5,7,9 etc.) then equate the average price closer to the Bid.

#define ALPHA 0.1

int DoubleToInt( const double Num )
{
  return((int)(Num + ALPHA));
}

void OnStart()
{
  double NewPrice = DoubleToInt((Ask + Bid) / (2 * Point)) * Point;

  Print(NewPrice);
}
Reason: