Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

Price_Compare - MetaTrader 4 Library | MT4 EA Download - MetaTrader 4 Resources

author EAcpu | 3 reads | 0 comments |

Price_Compare - library for MetaTrader 4

This small cross-platform library allows for easy and fast comparison of "double" values ​​of "price".

For example, before setting SellLimit, it is sometimes useful to check if the open price is lower than the current bid price.

 // if (NormalizeDouble(OpenPrice, Digits()) >= NormalizeDouble(Bid, Digits())) // This method is the most commonly used method
If (CP(opening price) >= bid ) // Now you can do this and the order is sent ...;

Not only is this cleaner and more concise than standard type checking, but it also performs several times faster! This efficient use of computing resources sometimes results in significant improvements to the tester/optimizer.

You can also set the precision with which "double" values ​​are compared. For example

 If ((CP(lot, 0.01 ) >= minimum lot) && ((CP(lot, 0.01 ) <= maximum lot))) // Compare the order to the second decimal place after the decimal point to send ...;

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

This library contains faster methods for normalized double precision execution. In order to improve the execution speed of standard functions, just add the following content at the beginning

 // Almost four times faster than the corresponding standard function (build 1395)
#Define normalized double PRICE_COMPARE::MyNormalizeDouble

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

Price_Compare - library for MetaTrader 4


Attachment download

📎 examplecompare.mq4 (1.02 KB)

📎 price_compare.mqh (2.5 KB)

Source: MQL5 #16177

Verification code Refresh