Technical analysis without external libraries

Calculating indicators and oscillators

November 22 2023

JJ BrosnanJJ BrosnanDeveloper Relations Engineer @Deephaven
AI prompt: graph of a moving average, multiple wavy lines, isolated dark blue background

In my last blog, I discussed the use of Bollinger Bands in financial analysis, as well as showed an implementation in Deephaven that took only two table operations.

Deephaven makes implementing technical indicators easy without any third-party integrations.

Effective trading strategies typically require more than one technical indicator. Bollinger Bands are a great place to start, but how are others implemented in a tool like Deephaven? Many of the most popular and useful indicators are also easy to implement with Deephaven alone.

Data

All examples in this blog will use a cryptocurrency history dataset of trade data from September 22, 2021. The calculations will be done on a per-instrument-exchange pair basis.

Quick analysis shows that this data has 17 unique instrument/exchange pairs. There are 4 unique instruments and 7 different exchanges.

Indicators

Each of the following sections will briefly discuss an indicator and show how to implement it in Deephaven. Because each indicator's implementations share many similarities, things are kept simple.

Moving average convergence divergence (MACD)

MACD) is calculated by subtracting a longer-term EMA from a shorter-term EMA. It's compared with a signal line, which is the MACD's moving average. This indicator is used to evaluate current market conditions.

A one-minute bar is used for this calculation. The shorter-period EMA uses 12 bars, the longer-period EMA uses 26 bars, and the signal line is calculated using 9 bars. The MACD calculation is enclosed in comments in the code. It only takes three table operations: two update_by statements and an update.

Stochastic oscillator

The Stochastic oscillator is a momentum indicator that's useful for identifying if an asset is overbought or oversold. The stochastic oscillator requires keeping track of the highest and lowest trade prices of an asset over 14 periods.

In the code below, a one-minute bar is used.

Absolute price oscillator (APO)

APO is yet another indicator that gives insight into bullish or bearish behavior of an asset. It requires keeping track of two EMAs: one for a shorter period, and one for a longer period. The longer is subtracted from the shorter. The example below uses a 5-minute and 15-minute EMA, respectively.

Reach out

Our Community documentation has all of the resources you need to become a Deephaven power user. Our Slack community continues to grow, and we'd love to have you join us! If you have any questions, comments, or suggestions, please reach out to us there.