Files
QuanTAlib/quantower/lib/cg.pine
T
Miha Kralj 3dd05f23e4 Refactor indicators to include "Ehlers" in names and descriptions for clarity
- Updated the name and description of the Hilbert Trendline (HTIT) to "Ehlers Hilbert Transform Instantaneous Trend (HTIT)".
- Changed the name and description of the MESA Adaptive Moving Average (MAMA) to "Ehlers MESA Adaptive Moving Average".
- Modified the Center of Gravity (CG) indicator to "Ehlers Center of Gravity (CG)".
- Renamed the Detrended Synthetic Price (DSP) to "Ehlers Detrended Synthetic Price (DSP)".
- Updated the Autocorrelation Periodogram (EACP) to "Ehlers Autocorrelation Periodogram (EACP)".
- Changed the Homodyne Discriminator (HOMOD) to "Ehlers Homodyne Discriminator (HOMOD)".
- Updated the Hilbert Transform Dominant Cycle Period and Phase indicators to include "Ehlers" in their names.
- Renamed the Hilbert Transform Phasor Components to "Ehlers Hilbert Transform Phasor Components (HT_PHASOR)".
- Updated the SineWave indicator to "Ehlers Hilbert Transform SineWave (HT_SINE)".
- Changed the Phasor Analysis indicator to "Ehlers Hilbert Transform Phasor Components (HT_PHASOR)".
- Updated the SSF-Based Detrended Synthetic Price to "Ehlers SSF Detrended Synthetic Price (SSFDSP)".
- Renamed the Ultimate Channel to "Ehlers Ultimate Channel (UCHANNEL)".
- Added new indicators: Moving Average Variable Period (MAVP), Ehlers Predictive Moving Average (PMA), Ehlers Reverse EMA (REVERSEEMA), and Ehlers Trendflex Indicator (TRENDFLEX).
- Updated various SVG badges to reflect changes in classes, comments, source files, lines of code, methods, and public types.
2026-02-18 19:08:15 -08:00

34 lines
1.1 KiB
Plaintext

// The MIT License (MIT)
// © mihakralj
//@version=6
indicator("Ehlers Center of Gravity (CG)", "CG", overlay=false)
//@function Calculates Ehlers' Center of Gravity indicator
//@param src Series to calculate Center of Gravity from
//@param length Period for the Center of Gravity calculation
//@returns Center of Gravity value identifying cycle turning points
//@optimized for performance and dirty data
cg(series float src, simple int length) =>
if length <= 0
runtime.error("Length must be greater than 0")
float num = 0.0, float den = 0.0
for count = 1 to length
float price = nz(src[count - 1])
num += count * price
den += price
float result = den != 0 ? num / den : (length + 1) / 2.0
result - (length + 1) / 2.0
// ---------- Main loop ----------
// Inputs
i_length = input.int(10, "Length", minval=1, tooltip="Period for Center of Gravity calculation")
i_source = input.source(close, "Source")
// Calculation
cg_value = cg(i_source, i_length)
// Plot
plot(cg_value, "CG", color=color.yellow, linewidth=2)
hline(0, "Zero Line", color.gray, linestyle=hline.style_dashed)