Usually oscillators compare the smoothened price of a financial tool
and its value n periods ago. Larry Williams once noticed that the
efficiency of such oscillator can vary and depends on the number of single
periods you take for the calculation. So he created the Ultimate Oscillator
that uses a weighted total of three oscillators with different calculation
periods.

Larry Williams first described the oscillator in 1985 in the
Technical Analysis of Stocks and Commodities magazine.
The values of the indicator vary in a range from zero to 100 and the center is the 50 value.
Values below 30 correspond with the overbought zone, and values between 70 and 100 - with the oversold zone.

The oscillator uses three time spaces that you can set manually. On default, they are
equal to 7, 14 and 28 periods. Mind that longer periods comprise shorter ones.
That means that 28-period values discount 14-period and 7-period values. Therefore,
we use the values of the shortest period three times, so these values influence the
result of the oscillator most of all.

Larry Williams recommended that you should open a position when a divergence appears. You should buy if:

Define current "True Low" (TL) — the least of two values: the current minimum and the precious closing price.

TL (i) = MIN (LOW (i) || CLOSE (i - 1))

Find current "Buying Pressure" (BP).
It is equal to the difference between current closing price and current True Low.

BP (i) = CLOSE (i) - TL (i)

Define the "True Range" (TR). It is the greatest of the
following differences: current maximum and minimum; current maximum and previous closing
price; current minimum and previous closing price.

TR (i) = MAX (HIGH (i) - LOW (i) || HIGH (i) - CLOSE (i - 1) || CLOSE (i - 1) - LOW (i))

Find the sum of BP values for all three periods of calculation:

BPSUM (N) = SUM (BP (i), i)

Find the sum of TR values for all three periods of calculation:

TRSUM (N) = SUM (TR (i), i)

Calculate the "Raw Ultimate Oscillator" (RawUO)

RawUO = 4 * (BPSUM (1) / TRSUM (1)) + 2 * (BPSUM (2) / TRSUM (2)) + (BPSUM (3) / TRSUM (3))

Calculate the "Ultimate Oscillator" (UO) value according to the formula:

UO = ( RawUO / (4 + 2 + 1)) * 100