Density
Syntax: N density [dataset] , where N represents the number of histogram bars. For example:
![]()
This request takes the frequency distribution of the 5-day changes of SPX (over the last 1000 days), and puts them in 100 bins. The result is a 2-column dataset:

** N.B. The text of all commands is located at the end of this document. That way you can simply copy them over to your own command set, should you wish to duplicate or modify the research
If you then click on the plot tab
you will see a histogram of the distribution:

If you click on the “Show Percentiles” icon (at the right on the icon bar), a pop-up box will appear which will give you the ability to select percentiles and choose a contrasting color.

Here’s the output:

The 5-day price changes seem to be distributed about the mean in a reasonably “normal” manner. Here’s a closer look at the percentile box:

Among other things, this shows you that the mean 5-day gain (the 50 Percentile) is 1.79 points. These values are also visible if you click on the note tab
.
However, let’s look at some conditional probabilities. For example, what is the distribution of 5-day changes of the close if the 25-day moving slope (a smooth measure of market momentum) is moving up? Here’s how to make that request and what the distribution looks like:


Again, we have a distribution that looks reasonably normal. But the 50 percentile is now 12.59 points.

Furthermore, if we highlight just the positive returns you can see how your probability of a subsequent 5-day gain is greatly enhanced by using that momentum indicator. Over 70 percent of the observations are profitable.

-------------------------------
100 density 5 change cl spx last 1000
(5 change cl spx) when ((change (25 movslope cl spx back 1)) gt 0)
100 density temp1
------------------------------------------------------------------------------