Files
QuanTAlib/lib/numerics/jerk/jerk.pine
T

30 lines
822 B
Plaintext
Raw Normal View History

// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("Third Derivative / Jerk (JERK)", "JERK", overlay=false, precision=8)
//@function Calculates the third finite difference (jerk): Jerk = V[t] - 3*V[t-1] + 3*V[t-2] - V[t-3]
//@param src Source series
//@returns Third difference. Returns 0.0 until 4 bars are available.
//@optimized Uses direct history access and binomial coefficients [1,-3,3,-1].
jerk(series float src) =>
float v0 = src
float v1 = src[1]
float v2 = src[2]
float v3 = src[3]
if na(v1) or na(v2) or na(v3)
0.0
else
v0 - 3.0 * v1 + 3.0 * v2 - v3
// ---------- Main loop ----------
// Inputs
i_source = input.source(close, "Source")
// Calculation
j = jerk(i_source)
// Plot
plot(j, "Jerk", color=color.yellow, linewidth=2)