콘텐츠로 이동

로깅 & 알림 (Logging & Notifications)

QuantiqDSL은 디버깅과 모니터링을 위한 로깅 함수와, 외부 알림 전송 함수를 제공합니다.

log()

스튜디오 로그 패널에 메시지를 출력합니다. 디버깅과 전략 분석에 사용합니다.

log(*args)

파라미터:

이름 타입 설명
*args any 출력할 값들 (공백으로 구분됨)

예제:

c = chart("1D")
rsi = ta.rsi(c.close, 14)

log("현재 종가:", c.close[0])
log("RSI:", rsi[0])
log("이벤트:", event, "바 인덱스:", c.bar_index[0])

포맷팅된 로그

f-string을 사용하면 깔끔한 로그를 작성할 수 있습니다.

c = chart("1D")
rsi = ta.rsi(c.close, 14)
sma20 = ta.sma(c.close, 20)
atr = ta.atr(c.high, c.low, c.close, 14)

log(f"[{symbol}] 종가={c.close[0]:.0f} RSI={rsi[0]:.1f} SMA20={sma20[0]:.0f} ATR={atr[0]:.0f}")

출력 예시:

[005930] 종가=72500 RSI=45.3 SMA20=71200 ATR=1520

print()

log()와 동일한 기능입니다. Python 사용자의 편의를 위해 제공됩니다.

print(*args)
print("Hello, QuantiqDSL!")
print("가격:", price, "거래량:", volume)

notify()

외부 알림을 전송합니다. 중요한 매매 시그널이나 이벤트 발생 시 사용합니다.

notify(*args)

파라미터:

이름 타입 설명
*args any 알림 메시지 내용

예제:

c = chart("1D")
rsi = ta.rsi(c.close, 14)

if rsi[0] < 20:
    notify(f"[긴급] {symbol} RSI 극단적 과매도: {rsi[0]:.1f}")
    buy(tag="극단적 과매도")

if rsi[0] > 80:
    notify(f"[경고] {symbol} RSI 극단적 과매수: {rsi[0]:.1f}")
    sell(tag="극단적 과매수")

notify vs log

구분 log / print notify
출력 위치 스튜디오 로그 패널 외부 알림 채널
용도 디버깅, 분석 중요 이벤트 알림
빈도 자유롭게 사용 중요 시그널에만 사용 권장

로깅 패턴

전략 상태 요약

version("1.0")
description("로깅 예제 전략")

c = chart("1D")
rsi = ta.rsi(c.close, 14)
sma20 = ta.sma(c.close, 20)

# 전략 상태 요약 로그
log("=" * 40)
log(f"종목: {symbol} ({symbol_name})")
log(f"이벤트: {event}")
log(f"종가: {c.close[0]:.0f}")
log(f"RSI(14): {rsi[0]:.1f}")
log(f"SMA(20): {sma20[0]:.0f}")
log(f"가격 vs SMA: {'위' if c.close > sma20 else '아래'}")
log(f"포지션 보유 여부: {bool(position)}")
log("=" * 40)

if rsi[0] < 30:
    buy(tag="RSI 과매도")
    log(">>> 매수 결정!")
elif rsi[0] > 70:
    sell(tag="RSI 과매수")
    log(">>> 매도 결정!")
else:
    hold()
    log(">>> 관망")

조건부 디버그 로그

param("debug", "debug", 0)

c = chart("1D")
rsi = ta.rsi(c.close, 14)

# debug=1일 때만 상세 로그 출력
if script_params["debug"] == 1:
    log(f"[DEBUG] close[0]={c.close[0]}, close[1]={c.close[1]}")
    log(f"[DEBUG] rsi[0]={rsi[0]:.2f}, rsi[1]={rsi[1]:.2f}")

관련 문서