Summary: This indicator script is a smoothed oscillator with essentially zero lag, it measures the center of gravity price for a window of bar prices. Calculation: Complex, see script. Developer: John F. Ehlers Interpretation: 1. Upwards Trend: When the indicator script is moving upwards, the underlying indicator is in an upwards trend. 2. Downwards Trend: When the indicator script is moving downwards, the underlying indicator is in a downwards trend. 3. Positive Divergence: When the underlying indicator is moving downwards, but the indicator script is moving upwards, the underlying indicator is likely to reverse direction and move upwards. 4. Negative Divergence: When the underlying indicator is moving upwards, but the indicator script is moving downwards, the underlying indicator is likely to reverse direction and move downwards. 5. Overbought: When the underlying indicator is moving upwards, but the indicator script is approaching its upper bound, the underlying indicator is likely to reverse direction and move downwards. 6. Oversold: When the underlying indicator is moving downwards, but the indicator script is approaching its lower bound, the underlying indicator is likely to reverse direction and move upwards.
' Assign the parameters to script variables. _indicatorKey = indicatorKey _periods = periods
' Get the values of the underlying indicator, indexed by bar index. Define values() As Number = IndicatorValues(_indicatorKey, barIndex, length + _periods) ' Use for the indicator formula numerator value. Define numerator As Number ' Use for the indicator formula denominator value. Define denominator As Number ' Use for the Center Of Gravity values, indexed by bar index. Define results(length - 1) As Number ' Calculate the Center Of Gravity values for the specified bar range. For i As Integer = length - 1 To 0 Step -1 numerator = 0 denominator = 0 ' Calculate the Center Of Gravity value for the current bar. For j As Integer = i + _periods - 1 To i Step -1 numerator += values(j) * (j - i + 1) denominator += values(j) Next ' Assign the Center Of Gravity value for the current bar. results(i) = -1 * (numerator / denominator) Next Return results