OGT Owl Group Trading by Dr. Ken Long
Home About Learn The Loop Code Courses Essays Store Partners FAQ
Python · Indicator Code

The Dragon (spine, belly & northern skin) in Python

A fast +/-0.5 SD band on the 10-period mean of RL10. The spine is the centerline, the belly is the lower (southern) skin, and the northern skin is the upper band.

Concept: what DRAGON means →

Verified. Python and JavaScript implementations agree to 7.11e-14 on a 60-bar reference price series (Python vs JavaScript across the Dragon spine (centerline), belly (lower skin), and northern skin (upper) - float64 round-off only).

Python

import numpy as np

def _rl(values, n=10):                     # RL10 endpoint (see the RL10 page)
    v = np.asarray(values, float); out = np.full(len(v), np.nan)
    if n <= 0 or len(v) < n: return out
    x = np.arange(n); xm = (n - 1) / 2.0; xd = x - xm
    denom = float(np.sum(xd ** 2))
    if denom == 0: return out
    w = 1.0 / n + xm * xd / denom
    out[n - 1:] = np.correlate(v, w, mode="valid")
    return out

def _sma(values, n):
    v = np.asarray(values, float); out = np.full(len(v), np.nan)
    for i in range(n - 1, len(v)):
        win = v[i - n + 1:i + 1]
        if not np.isnan(win).any(): out[i] = win.mean()
    return out

def _rolling_std(values, n):
    v = np.asarray(values, float); out = np.full(len(v), np.nan)
    for i in range(n - 1, len(v)):
        win = v[i - n + 1:i + 1]
        if not np.isnan(win).any(): out[i] = win.std()   # population std
    return out

def dragon(closes):
    """The Dragon - a fast +/-0.5 SD band on the 10-period mean of RL10.

      spine         = the centerline itself, SMA(10) of RL10
      belly         = spine - 0.5 SD   (lower / southern skin)
      northern_skin = spine + 0.5 SD   (upper skin)

    The Dragon hugs price as a noise boundary during trends and flips about six
    times faster than the River at trend inflection points."""
    spine = _sma(_rl(closes, 10), 10)             # centerline
    sd = _rolling_std(spine, 10)
    return {"spine": spine,                         # centerline
            "belly": spine - 0.5 * sd,              # lower / southern skin
            "northern_skin": spine + 0.5 * sd}      # upper skin