챗 GPT로 짠 코드인데 한번만 체크 부탁드립니다.
// =============================================// DailyPL_Logger : 계좌 일별 손익 로그 전략// - Account1 전체 평가금액 기준// - 일별 손익 <= MaxLossToday 이면 로그 1회 기록// =============================================// ---- 전역 변수 ----var StartEquity = 0; // 오늘 시작 기준 계좌 평가금액var StartDate = 0; // YYYYMMDD 형태 정수var AlertLogged = false; // 오늘 경고 로그 남겼는지 여부// ---- 외부변수 기본값 (외부변수 안 쓰면 이 값 사용) ----// MaxLossToday : 오늘 허용 손실 한도 (음수 값)// LogFileName : 로그 파일 이름 또는 전체 경로if (typeof MaxLossToday === "undefined") { MaxLossToday = -3000000; // 예: -3,000,000원}if (typeof LogFileName === "undefined") { // 파일명만 쓰면 Spot\\Export 폴더에 생성됨 (예스스팟 매뉴얼 설명) LogFileName = "DailyLossAlert.log";}// ---- 날짜 정수(YYYYMMDD) 만들기 ----function getTodayInt() { var now = new Date(); var y = now.getFullYear(); var m = now.getMonth() + 1; var d = now.getDate(); return y * 10000 + m * 100 + d;}// ---- 로그에 찍을 타임스탬프 문자열 만들기 ----function getTimestampString() { var now = new Date(); var y = now.getFullYear(); var m = now.getMonth() + 1; var d = now.getDate(); var hh = now.getHours(); var mm = now.getMinutes(); var ss = now.getSeconds(); function pad(n) { return (n < 10 ? "0" : "") + n; } return y + "-" + pad(m) + "-" + pad(d) + " " + pad(hh) + ":" + pad(mm) + ":" + pad(ss);}// ---- 하루 시작 기준값 초기화 ----function initDailyEquity() { // Account1 전체 잔고 평가금액 합 (0,0 = 전체/전체) // 예스스팟 매뉴얼: Account.GetTotalAmount(nCategory, nTradeKind) :contentReference[oaicite:1]{index=1} StartEquity = Account1.GetTotalAmount(0, 0); StartDate = getTodayInt(); AlertLogged = false; Main.MessageLog("DailyPL_Logger init : StartEquity=" + StartEquity + ", StartDate=" + StartDate);}// ---- 예스스팟 시작 이벤트 ----function OnStart() { // 하루 기준값 세팅 initDailyEquity(); // 1초(1000ms)마다 OnTimer(1) 호출 Main.SetTimer(1, 1000);}// ---- 타이머 이벤트 ----function OnTimer(nEventID) { if (nEventID != 1) { return; } // 날짜 바뀌었으면 새로 하루 시작으로 보고 기준값 재설정 var today = getTodayInt(); if (today != StartDate) { initDailyEquity(); } // 현재 계좌 전체 평가금액 var currentEquity = Account1.GetTotalAmount(0, 0); var dailyPL = currentEquity - StartEquity; // 조건: 일별 손익 <= MaxLossToday 이고, 아직 로그 안 남겼을 때 if (!AlertLogged && dailyPL <= MaxLossToday) { var msg = getTimestampString() + " DailyPL=" + dailyPL + " (StartEquity=" + StartEquity + ", CurrentEquity=" + currentEquity + ")"; // 파일에 한 줄 출력 // 예스스팟 문서: Main.PrintOnFile(파일, 메시지...) :contentReference[oaicite:2]{index=2} Main.PrintOnFile(LogFileName, msg); // 디버깅창에도 출력 (테스트용) Main.MessageLog("DailyPL_Logger ALERT : " + msg); AlertLogged = true; // 오늘은 한 번만 알림 }}
자동매매 로직 부탁드립니다.
1. NH선물 해외옵션 중 제로데이옵션(CBOE S&P500 Weekly Option)거래2. 진입시점 : 콜, 풋 양매수 전략으로 예를 들면, 16시에 제로데이옵션 콜 가격 10에 1개 매수 진입 풋 가격 10에 1개 매수 진입 했다고 가정하고이 양매수 진입 포지션의 손익의 합계가 -400불 인경우, 자동으로 그 당시 콜, 풋 가격으로 시장가 진입수익청산은 실제 진입후 수익이 +500불인경우 자동 시장가 청산 손절은 실제 진입후 손실이 -500불인 경우 자동 시장가 청산위 그림에서 A지점이 콜, 풋 대략 10정도 지점으로 사용자가 행사가를 정해서 입력을 해두고B지점 같이 해당 콜, 풋 양매수 손익이 -400불(사용자가 설정 가능하게)인경우 자동으로 시장가 양매수 진입(위 그림에서 대략 콜7.5 풋 8.5라고 가정)C지점에서 즉 진입후 500불(사용자가 설정 가능하게) 수익인경우 자동 시장가 청산(위 그림에서는 C지점 이전에 막대가 +100불인 경우 자동청산)
답변완료
수식문의
input : length(22); input : mult(3.0); input : useClose(1);#1:종가, 0:고가/저가 var : alpha(0),atrv(0),a(0); var : longStop(0),longStopPrev(0),shortStop(0),shortStopPrev(0),dir(1); var : Buysignal(False),Sellsignal(False),tx(0); alpha = 1 / length ; atrv = IFf(IsNan(ATRV[1]) == true, ma(TrueRange,length) , alpha * TrueRange + (1 - alpha) * IFf(isnan(ATRV[1])==true,0,ATRV[1])); a = mult * atrv; longStop = IFF(useClose == 1,highest(close, length), highest(H,length)) - a; longStopPrev = iff(isnan(longStop[1])==true, longStop,longStop[1]); longStop = iff(close[1] > longStopPrev , max(longStop, longStopPrev) , longStop); shortStop = IFF(useClose == 1,lowest(close, length), lowest(L,length)) + a; shortStopPrev = iff(IsNan(shortStop[1])==true, shortStop[1], shortStop); shortStop = iff(close[1] < shortStopPrev , min(shortStop, shortStopPrev) , shortStop); dir = iff(close > shortStopPrev , 1 , iff(close < longStopPrev , -1 , dir)); buySignal = dir == 1 and dir[1] == -1; sellSignal = dir == -1 and dir[1] == 1; if buySignal == true then Find(1);위 수식은 트레이딩뷰의 Chandelier exit을 예스트레이드 수식으로 변환요청해서 받은 것입니다. 받고보니 의문이 있어 글 올립니다. -예스스팟에서 위 수식을 넣고 + 마지막 줄의 if buySignal == true then을 sellSignal로 바꿔 추가로 넣으면 buy/sell 신호시 매수매도가 가능한지요? -선물같이 한종목이 아닌 여러종목이라 불가하다면 한종목만(예.삼성전자 또는 sk하이닉스) 지정해서 할 방법은 없는지요? -느낌에는 buy용 수식하나, sell용 별도 수식하나를 작성하고 예스스팟도 각 수식을 넣은 두개로 돌리면 될거같은데요.