Instrument.Compare

Description

The Instrument.Compare function compares two market prices whilst taking into account the correct number of decimal points. The smallest possible price change is displayed by the value TickSize. This function simplifies the otherwise time-consuming comparison using floating-point operations.

Parameter

double value1 double value2

Return value

Type int

1 - value1 is bigger than value2 -1 - value1 is smaller than value2 0 - value1 and value2 are equal

Usage

Instrument.Compare(double Value1, double Value2)

More Information

Be aware this function compares prices based on TickSize. If the tick size of your instrument is 0.01 these prices will be rounded and compared on 2 decimal digits. If you want a regular compration of two numbers, you should use the operator "greater than" (>) or the operator "smaller than" (<).

More infomation about [math.round()](https://msdn.microsoft.com/en-us//library/75ks3aby(v=vs.110).aspx)

If the tick size is 0,00001 – as it usually is with FX values – then the following will be displayed:

Compare(2, 1.99999) a 1, meaning 2 is bigger than 1.99999 Compare(2, 2.000001) a 0, meaning the values are equal Compare(2, 1.999999) a 0, meaning the values are equal Compare(2, 2.00001) a -1, meaning 2 is smaller than 2.00001

Example

Print(Instrument.Compare(2, 1.999999));

Last updated