Using the CQG Modulus Function

One of the simplest examples for this function is to find out whether a value is an even number.

Modulus (Close(@),2) = 0

In other words, the result of the formula above would give us the remainder of the operation Closing Price/2. If the result is different than 0, the Closing Price of the bar in question is not an even number. If the remainder of the operation is 0, then the Closing Price is an even number.

The best example for this function would be to find out whether a year is a leap year. The definition of a leap year is a year that is divisible by 4, but not by 100, unless it is divisible by 400. This would translate in CQG code as:

(Modulus(LocalYear(@),4)=0 AND  (Modulus(LocalYear(@),100)>0) OR Modulus(LocalYear(@),400) =0);

We can see the result on an annual chart of the Dow Jones Index back in 1900 where every year is a leap year, except for 1900, which was not (as divisible by 4 and 100 but not 400).

At the bottom of the post is a downloadable PAC to install this study in CQG.

Downloads

Disclaimer

Trading and investment carry a high level of risk, and CQG, Inc. does not make any recommendations for buying or selling any financial instruments. We offer educational information on ways to use our sophisticated CQG trading tools, but it is up to our customers and other readers to make their own trading and investment decisions or to consult with a registered investment advisor. The opinions expressed here are solely those of the author and do not reflect the opinions of CQG, Inc. or its affiliates.