Download MetaTrader 5

Watch how to download trading robots for free

Interesting script?
So post a link to it -
let others appraise it

You liked the script? Try it in the MetaTrader 5 terminal

2016.09.19 12:49

Price_Compare - library for MetaTrader 5

| English Русский 中文 Español Deutsch 日本語 Português

votes: 19

This small cross-platform library allows to compare the 'double' values of the "price" conveniently and quickly.

For example, before placing a SellLimit, it is sometimes useful to check if the opening price is below the current Bid price.

// if (NormalizeDouble(OpenPrice, Digits()) >= NormalizeDouble(Bid, Digits())) // this method was the most frequently used
if (CP(OpenPrice) >= Bid) // now it can be done like this

Not only is this much clearer and more concise than the standard type check, but also the execution speed is several times higher! Such efficient usage of computational resources sometimes grants a noticeable boost in the tester/optimizer.

It is also possible to set the precision for comparing the 'double' values. For example

if ((CP(Lots, 0.01) >= MinLot) && ((CP(Lots, 0.01) <= MaxLot))) // compare with the precision up to the second decimal place

All the comparison operators (==, !=, >=, <=, >, <) are handled in a similar fashion.

The library contains a faster method of the NormalizeDouble implementation. To improve the execution speed of the standard function, it is sufficient to add the following at the beginning

// Almost four times faster than the corresponding standard function (build 1395)
#define NormalizeDouble PRICE_COMPARE::MyNormalizeDouble

As an example, the attached script shows the results of comparison and normalization method for different price values.

Translated from Russian by MetaQuotes Software Corp.
Original code:

Accelerator Oscillator (AC) Accelerator Oscillator (AC)

The Acceleration/Deceleration Indicator (AC) measures acceleration and deceleration of the current driving force.

Average Directional Movement Index (ADX) Average Directional Movement Index (ADX)

The Average Directional Movement Index Indicator (ADX) helps to determine if there is a price trend.

Yen Trader Yen Trader

Expert Advisor to trade Yen Crosses based on Major Pairs and USDJPY divergence/convergence.

Example of MACD Automated Example of MACD Automated

Code example of MACD automated with advanced money management function.