My Bad Maths :(

 

Hi All,

I wonder if someone can put me on the right track for something that should and probably is very straightforward. However, my maths is not good so, here it is.

I'm trying to take the close of two different bars and see whether the difference falls in or out of the scope of a "reversal" value.

Last bar close: 1.25148

Current bar close: 1.2515

Difference: 0.00002

Reversal value: 10 pips

Using the following code:

double lastBarHighClose=_lastBarHigh.BarClose();
double barClose=bar.BarClose();
double result=NormalizeDouble(lastBarHighClose-barClose,Digits); // result == -2e-05.0

Without using NormalizeDouble, the value is: 2.000000000013102e-05

The broker I am using is a 5 digit broker.

I don't understand these long numbers with the scientific notation. I want to work out whether the difference between two close values is inside, equal to, or outside of the reversal pip value.

Can anyone very kindly give me an example of the kind of expression I would need to achieve this?

Thanks in advance.

 
Geester: Reversal value: 10 pips.  Without using NormalizeDouble, the value is: 2.000000000013102e-05
  1. Using Points means code breaks on 4 digit brokers, exotics (e.g. USDZAR where spread is over 500 points,) and metals. Compute what a PIP is and use it, not points.
              How to manage JPY pairs with parameters? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Slippage defined in index points - Currency Pairs - Expert Advisors and Automated Trading - MQL5 programming forum

  2. Print out your values to the precision you want. Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong

 
whroeder1:
  1. Using Points means code breaks on 4 digit brokers, exotics (e.g. USDZAR where spread is over 500 points,) and metals. Compute what a PIP is and use it, not points.
              How to manage JPY pairs with parameters? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Slippage defined in index points - Currency Pairs - Expert Advisors and Automated Trading - MQL5 programming forum

Many thanks @whroeder1 for these links. That's a lot of really helpful information! :)

Could you please explain what Digits.pips is all about? I put that code in a class and the compiler says:

'.' - variable expected

Is the notation of "pips" being a property of "Digits" an EA thing only? 

EDIT: Added into an EA and got the message:

'.' - semicolon expected WWaves.mq4 23 11


 
Geester:

Hi All,

I wonder if someone can put me on the right track for something that should and probably is very straightforward. However, my maths is not good so, here it is.

I'm trying to take the close of two different bars and see whether the difference falls in or out of the scope of a "reversal" value.

Last bar close: 1.25148

Current bar close: 1.2515

Difference: 0.00002

Reversal value: 10 pips

Using the following code:

Without using NormalizeDouble, the value is: 2.000000000013102e-05

The broker I am using is a 5 digit broker.

I don't understand these long numbers with the scientific notation. I want to work out whether the difference between two close values is inside, equal to, or outside of the reversal pip value.

Can anyone very kindly give me an example of the kind of expression I would need to achieve this?

Thanks in advance.

Could you please add a printf() to check high/close values ? I'm not sure it's correctly handled since the difference isn't 2 in the example you gave :/

 
Geester: Could you please explain what Digits.pips is all about?
Pre-Build 600 code (February 3, 2014) Can't use periods in variable names. Just rename it (DigitsPips, or Digits_pips.)
 
whroeder1:
Pre-Build 600 code (February 3, 2014) Can't use periods in variable names. Just rname it (DigitsPips, or Digits_pips.)

Ah, thanks for confirming. I'd already done what you suggested but just wondered whether I was missing something! :)

 

It's not necessary to work with the instrument's "pip" step. I mostly use the tick-size as the MQL built-ins all use tick-size. eg. Tick Value. In any regards, since you like to use OOP I made a class library for easily rounding doubles to the correct values so you don't have to constantly call the functions associated with floating point rounding. 


CDouble lastBarHighClose =_lastBarHigh.BarClose();
CDouble barClose         = bar.BarClose();
CDouble result           = lastBarHighClose-barClose;
printf("Result = %s",DoubleToString(result.AsRoundedTick()));

or

double lastBarHighClose =_lastBarHigh.BarClose();
double barClose         = bar.BarClose();
CDouble result(PRECISION_TICK_SIZE);           
result = lastBarHighClose-barClose;
printf("Result = %s",result.ToString());
 
nicholishen:

It's not necessary to work with the instrument's "pip" step. I mostly use the tick-size as the MQL built-ins all use tick-size. eg. Tick Value. In any regards, since you like to use OOP I made a class library for easily rounding doubles to the correct values so you don't have to constantly call the functions associated with floating point rounding. 


or

Hey @nicholishen - the library looks fantastic! Thanks for pointing it out and it's now in my build :)

Cheers --G

 
nicholishen:

It's not necessary to work with the instrument's "pip" step. I mostly use the tick-size as the MQL built-ins all use tick-size. eg. Tick Value. In any regards, since you like to use OOP I made a class library for easily rounding doubles to the correct values so you don't have to constantly call the functions associated with floating point rounding. 


or

Hey @nicholishen - just a quick question. If as a result of using (CDouble) result.ToString(), I get a value of, say, 0.00025 - is there a method on CDouble that will convert that value into 2.5 (pips)? 

 
Geester:

Hey @nicholishen - just a quick question. If as a result of using (CDouble) result.ToString(), I get a value of, say, 0.00025 - is there a method on CDouble that will convert that value into 2.5 (pips)?

I thought about it and then decided that I didn't want to own that functionality if you know what I mean. You can easily make a subclass to handle that...

Reason: