[가상화폐] MACD 계산

LONGNEW·2024년 1월 16일
0

자동화

목록 보기
2/4

MACD 또한 Bollinger Band (BB)와 비슷하다.

과거의 Price 가져오기

MACD에서의 함수와 동일한데 interval만 원하는 값으로 교체한다.
해당 price의 "Open" 값을 이용하는 것이 BB와 다른 점이다.

12, 26 이동평균선 구하기.

pandas의 도움을 받아서 값을 구하자.

    prices = get_prices(symbol, "30m", "open")
    df = pd.DataFrame({'open': prices})
    df2 = df['open'].to_numpy()

    now_price = temp_bingx.real_time_price(symbol)
    df2 = numpy.append(df2, [now_price])

    df = pd.DataFrame(df2, columns=['open'])
	
    # 이평선 값 구하기.
    exp1 = df['open'].ewm(span=12, adjust=False).mean()
    exp2 = df['open'].ewm(span=26, adjust=False).mean()
    macd = exp1 - exp2
    macd = macd.values

    macd2, macd1 = macd[-3], macd[-2]
    print(f"1시간 전 : {macd[-3]}, 30분 전 : {macd[-2]}")

현재는 30분 봉에대한 MACD를 구하기 때문에 idx가 가장 큰것이 현재다.
그래서 {max_idx} - 1이 30분 전, -2가 1시간 전이다.

0개의 댓글