CGO (Center of Gravity Oscillator)는 피셔 트랜스폼(Fisher Transform), CTI(Correlation Trend Indicator), 상대 활력 지수(RVI, Relative Vigor Index)에서 소개했던 존 엘러스(John Ehlers)에 의해 만들어진 지표로 대부분 후행성을 가지고 있는 다른 지표들의 단점을 보완하기 위해 가중평균을 이용해 비교적 지표가 표시하는 값의 현행성을 높이기 위해 고안된 지표이다.
현재와 가까운 가격에 가중치를 주고 가중평균을 한 후 그것을 같은 구간 가격의 합으로 나눈 것을 사용하며 이것을 1 단위 lagging 시킨 것과 같이 사용하여 오실레이터를 만든다.
기본적인 사상은 가격의 중심을 잡고 그 위아래로 움직이는 지표의 움직임을 보고 모멘텀을 파악하고 매수, 매도 타이밍을 포착하여 거래를 수행하는 전형적인 오실레이터 지표이다. 비교적 단기 거래에 걸맞고 박스권이나 가격변동이 많이 심하지 않은 종목 및 시장 상황에 잘 맞는 것으로 알려져 있다.
CGO가 위나 아래로 크게 치우치면 추세 전환이 발생한다고 예측할 수 있다. CGO와 CGO가 래깅된 신호선과의 크로스 오버를 이용해 추세 전환을 판단할 수 있다. 마지막은 전략에는 적용하기 어려우나 지표 측면에서, CGO 라인의 기울기로 추세의 강도를 판단하는 용도로 사용할 수 있다.
마지막으로 CGO (Center of Gravity Oscillator)의 트레이딩 뷰 파인 스크립트 소스와 pandas-ta 소스를 공유하며 마친다.
- CGO (Center of Gravity Oscillator) 트레이딩 뷰 파인 스크립트 지표 소스
//@version=5
indicator(title="Center of Gravity Oscillator", shorttitle="CGO", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
import TradingView/ta/7 as ta7
import blackcat1402/pandas_ta/7 as pta
ma(source, length, _type) =>
switch _type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"DEMA" => ta7.dema(source,length)
"TEMA" => ta7.tema(source,length)
"FRAMA" => ta7.frama(source,length)
"T3" => ta7.t3(source,length)
"TRIMA" => ta7.trima(source,length)
"RMA" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"HMA" => ta.hma(source, length)
"VWMA" => ta.vwma(source * volume, length)
"ALMA" => pta.alma(source, length)
"JMA" => pta.jma(source, length)
"SINWMA" => pta.sinwma(source, length)
"FWMA" => pta.fwma(source, length)
"LINREG" => pta.linreg(source, length)
"SWMA" => pta.swma(source)
"YIDYA" => pta.vidya(source, length)
"VWAP" => pta.vwap(source)
"ZLMA" => pta.zlma(source, length)
sourceInput = input(defval=close, title="Source")
lengthInput = input.int(10, minval=1, title="Length")
maTypeInput = input.string("WMA", title="MA Type", options=["SMA", "EMA", "DEMA", "TEMA", "FRAMA", "T3", "TRIMA", "RMA", "WMA", "HMA", "VWMA", "ALMA", "JMA", "SINWMA", "FWMA", "LINREG", "SWMA", "VIDYA", "VWAP", "ZLMA"], group="RVI Settings")
num=ma(sourceInput,lengthInput,maTypeInput)*lengthInput*(lengthInput+1)/2
den=math.sum(sourceInput,lengthInput)
cg=num/den
plot(cg,title="CG",color=color.blue,linewidth=2)
plot(cg[1],title="Signal",color=color.red,linewidth=2)
- CGO (Center of Gravity Oscillator) 트레이딩 뷰 파인 스크립트 전략 소스
//@version=5
strategy(title="Center of Gravity Oscillator", shorttitle="CGO", margin_long=100, margin_short=100, default_qty_type=strategy.percent_of_equity, default_qty_value=50, commission_type=strategy.commission.percent, commission_value=0.2, pyramiding=0)
import TradingView/ta/7 as ta7
import blackcat1402/pandas_ta/7 as pta
ma(source, length, _type) =>
switch _type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"DEMA" => ta7.dema(source,length)
"TEMA" => ta7.tema(source,length)
"FRAMA" => ta7.frama(source,length)
"T3" => ta7.t3(source,length)
"TRIMA" => ta7.trima(source,length)
"RMA" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"HMA" => ta.hma(source, length)
"VWMA" => ta.vwma(source * volume, length)
"ALMA" => pta.alma(source, length)
"JMA" => pta.jma(source, length)
"SINWMA" => pta.sinwma(source, length)
"FWMA" => pta.fwma(source, length)
"LINREG" => pta.linreg(source, length)
"SWMA" => pta.swma(source)
"YIDYA" => pta.vidya(source, length)
"VWAP" => pta.vwap(source)
"ZLMA" => pta.zlma(source, length)
sourceInput = input(defval=close, title="Source")
lengthInput = input.int(10, minval=1, title="Length")
maTypeInput = input.string("WMA", title="MA Type", options=["SMA", "EMA", "DEMA", "TEMA", "FRAMA", "T3", "TRIMA", "RMA", "WMA", "HMA", "VWMA", "ALMA", "JMA", "SINWMA", "FWMA", "LINREG", "SWMA", "VIDYA", "VWAP", "ZLMA"], group="RVI Settings")
num=ma(sourceInput,lengthInput,maTypeInput)*lengthInput*(lengthInput+1)/2
den=math.sum(sourceInput,lengthInput)
cg=num/den
plot(cg,title="CG",color=color.blue,linewidth=2)
plot(cg[1],title="Signal",color=color.red,linewidth=2)
startDate = input.time(defval=timestamp("01 Jan 1970 00:00 +0000"), group = "Test Range")
finishDate = input.time(defval=timestamp("31 Dec 2025 24:00 +0000"), group = "Test Range")
time_condition = time >= startDate and time <= finishDate
if(time_condition)
if ta.crossover(cg, cg[1])
strategy.entry("매수", strategy.long, oca_type=strategy.oca.cancel, comment="매수")
if ta.crossunder(cg[1], cg)
strategy.close_all('매도')
bgcolor(strategy.position_size > 0 ? color.new(color.yellow,90) : na)
- CGO (Center of Gravity Oscillator) pandas-ta 소스
import pandas as pd
import pandas_ta as ta
import FinanceDataReader as fdr
data = fdr.DataReader('005930')
cg = ta.cg(close=data['Close'], length=10)
data = pd.concat([data, cg], axis=1)
data.dropna(inplace=True)