예스스탁
예스스탁 답변
2025-09-22 11:00:20.0
안녕하세요
예스스탁입니다.
Inputs:
UseTimeFilter(True),
AM_Start(090000), AM_End(130000),
PM_Start(131000), PM_End(143000),
DeadZonePt(0.30), // VWAP 근접 회피 폭 (pt)
Confirm5mBars(1), // 5분 방향 확인 필요 봉 수
TickConfirmBars(2), // 500틱 재안착 확인(1~2 권장)
UseTypicalPrice(True); // VWAP용 가격소스 (True: (H+L+C)/3)
Vars:
// ---------- Data1: 500틱 VWAP ----------
tpT(0,Data1), pvT(0,Data1), cumPVT(0,Data1), cumVT(0,Data1), vwapTick(0,Data1),
firstDayT(False,Data1), barCountT(0,Data1),
// ---------- Data2: 5분 VWAP ----------
tp5(0,Data2), pv5(0,Data2), cumPV5(0,Data2), cumV5(0,Data2), vwap5m(0,Data2),
firstDay5(False,Data2), barCount5(0,Data2),
// ---------- Data3: 8분 VWAP ----------
tp8(0,Data3), pv8(0,Data3), cumPV8(0,Data3), cumV8(0,Data3), vwap8m(0,Data3),
firstDay8(False,Data3), barCount8(0,Data3),
// ---------- 상태/신호 ----------
inTime(False),
longBias(False), shortBias(False),
confirm8Long(False), confirm8Short(False),
trigLong(False), trigShort(False),
distT(0);
// ================== 공통 초기/카운터 ================== //
barCountT = barCountT + 1;
// ================== 세션 리셋(일자 기준) ================== //
// Data1(500틱)
firstDayT = (Date <> Date[1]);
If firstDayT then
Begin
cumPVT = 0; cumVT = 0;
barCountT = 1;
End;
// Data2(5분)
firstDay5 = (data2(Date) <> data2(Date[1]));
If firstDay5 then
Begin
cumPV5 = 0; cumV5 = 0; barCount5 = 0;
End;
// Data3(8분)
firstDay8 = (data3(Date) <> data3(Date[1]));
If firstDay8 then
Begin
cumPV8 = 0; cumV8 = 0; barCount8 = 0;
End;
// ================== VWAP 계산 ================== //
// --- 가격소스 ---
If UseTypicalPrice then
Begin
tpT = (High + Low + Close) / 3;
tp5 = (data2(High) + data2(Low) + data2(Close)) / 3;
tp8 = (data3(High) + data3(Low) + data3(Close)) / 3;
End
Else
Begin
tpT = Close;
tp5 = data2(Close);
tp8 = data3(Close);
End;
// --- Data1: 500틱 (매 바) ---
pvT = tpT * Volume;
cumPVT = cumPVT + pvT;
cumVT = cumVT + Volume;
If cumVT > 0 then vwapTick = cumPVT / cumVT; Else vwapTick = tpT;
// --- Data2: 5분 (바 마감시에만 누적) ---
pv5 = tp5 * Data2(Volume);
cumPV5 = cumPV5 + pv5;
cumV5 = cumV5 + Data2(Volume);
If cumV5 > 0 then vwap5m = cumPV5 / cumV5; Else vwap5m = tp5;
barCount5 = barCount5 + 1;
pv8 = tp8 * data3(Volume);
cumPV8 = cumPV8 + pv8;
cumV8 = cumV8 + data3(Volume);
If cumV8 > 0 then vwap8m = cumPV8 / cumV8; Else vwap8m = tp8;
barCount8 = barCount8 + 1;
// ================== 시간 필터 ================== //
inTime = True;
If UseTimeFilter then
inTime = ( (Time >= AM_Start and Time <= AM_End)
or (Time >= PM_Start and Time <= PM_End) );
// ================== 5분 방향 필터 ================== //
// 조건: 5분 종가가 5분 VWAP 위/아래이고, Confirm5mBars 이전에는 반대였음(돌파/이탈)
If Confirm5mBars < 1 then Confirm5mBars == 1;
longBias = False;
shortBias = False;
If barCount5 > Confirm5mBars then
Begin
longBias = (data2(Close) > vwap5m) and (data2(Close[Confirm5mBars]) <= data2(vwap5m[Confirm5mBars]));
shortBias = (data2(Close) < vwap5m) and (data2(Close[Confirm5mBars]) >= data2(vwap5m[Confirm5mBars]));
End;
// ================== 8분 확인(컨펌) ================== //
// 단순: 현재 8분 종가가 8분 VWAP 위/아래
confirm8Long = (data3(Close) > vwap8m);
confirm8Short = (data3(Close) < vwap8m);
// ================== 500틱 트리거(되돌림 후 재안착) ================== //
// TickConfirmBars: 1 또는 2 권장
#If TickConfirmBars < 1 then TickConfirmBars = 1;
#If TickConfirmBars > 2 then TickConfirmBars = 2;
trigLong = False;
trigShort = False;
// VWAP 근접 데드존 회피
distT = AbsValue(Close - vwapTick);
// 롱 트리거: 현재 Close > vwapTick 이고, 직전(TickConfirmBars)에는 경계/아래 → 재안착
If barCountT > TickConfirmBars then
Begin
If TickConfirmBars == 1 then
trigLong = (Close > vwapTick) and (distT > DeadZonePt);
Else
trigLong = (Close > vwapTick) and (Close[1] <= vwapTick[1]) and (distT > DeadZonePt);
// 숏 트리거: 현재 Close < vwapTick 이고, 직전에는 경계/위 → 재이탈
If TickConfirmBars == 1 then
trigShort = (Close < vwapTick) and (distT > DeadZonePt);
Else
trigShort = (Close < vwapTick) and (Close[1] >= vwapTick[1]) and (distT > DeadZonePt);
End;
// ================== 최종 진입 신호(Trigger = 실행 조건) ================== //
// 롱 실행: 5분 롱 바이어스 AND 8분 컨펌 AND 500틱 롱 트리거
If inTime and longBias and confirm8Long and trigLong then
Begin
Buy();
Alert("TRIGGER LONG: 5m dir + 8m confirm + 500T re-anchor");
End;
// 숏 실행: 5분 숏 바이어스 AND 8분 컨펌 AND 500틱 숏 트리거
If inTime and shortBias and confirm8Short and trigShort then
Begin
Sell();
Alert("TRIGGER SHORT: 5m dir + 8m confirm + 500T re-anchor");
End;
즐거운 하루되세요
> 드림365 님이 쓴 글입니다.
> 제목 : 어떻게 고쳐야 할까요?
> 수고 많으십니다.
자꾸만 에러가 떠서요
수정 좀 부탁드립니다.
Inputs:
UseTimeFilter(True),
AM_Start(090000), AM_End(130000),
PM_Start(131000), PM_End(143000),
DeadZonePt(0.30), // VWAP 근접 회피 폭 (pt)
Confirm5mBars(1), // 5분 방향 확인 필요 봉 수
TickConfirmBars(2), // 500틱 재안착 확인(1~2 권장)
UseTypicalPrice(True); // VWAP용 가격소스 (True: (H+L+C)/3)
Vars:
// ---------- Data1: 500틱 VWAP ----------
tpT(0), pvT(0), cumPVT(0), cumVT(0), vwapTick(0),
firstDayT(False), barCountT(0),
// ---------- Data2: 5분 VWAP ----------
tp5(0), pv5(0), cumPV5(0), cumV5(0), vwap5m(0),
firstDay5(False), barCount5(0),
// ---------- Data3: 8분 VWAP ----------
tp8(0), pv8(0), cumPV8(0), cumV8(0), vwap8m(0),
firstDay8(False), barCount8(0),
// ---------- 상태/신호 ----------
inTime(False),
longBias(False), shortBias(False),
confirm8Long(False), confirm8Short(False),
trigLong(False), trigShort(False),
distT(0);
// ================== 공통 초기/카운터 ================== //
barCountT = barCountT + 1;
// ================== 세션 리셋(일자 기준) ================== //
// Data1(500틱)
firstDayT = (Date <> Date[1]);
If firstDayT then
Begin
cumPVT = 0; cumVT = 0;
barCountT = 1;
End;
// Data2(5분)
firstDay5 = (Date of Data2 <> Date[1] of Data2);
If firstDay5 then
Begin
cumPV5 = 0; cumV5 = 0; barCount5 = 0;
End;
// Data3(8분)
firstDay8 = (Date of Data3 <> Date[1] of Data3);
If firstDay8 then
Begin
cumPV8 = 0; cumV8 = 0; barCount8 = 0;
End;
// ================== VWAP 계산 ================== //
// --- 가격소스 ---
If UseTypicalPrice then
Begin
tpT = (High + Low + Close) / 3;
tp5 = (High of Data2 + Low of Data2 + Close of Data2) / 3;
tp8 = (High of Data3 + Low of Data3 + Close of Data3) / 3;
End
Else
Begin
tpT = Close;
tp5 = Close of Data2;
tp8 = Close of Data3;
End;
// --- Data1: 500틱 (매 바) ---
pvT = tpT * Volume;
cumPVT = cumPVT + pvT;
cumVT = cumVT + Volume;
If cumVT > 0 then vwapTick = cumPVT / cumVT Else vwapTick = tpT;
// --- Data2: 5분 (바 마감시에만 누적) ---
If BarStatus(2) = 2 then
Begin
pv5 = tp5 * (Volume of Data2);
cumPV5 = cumPV5 + pv5;
cumV5 = cumV5 + (Volume of Data2);
If cumV5 > 0 then vwap5m = cumPV5 / cumV5 Else vwap5m = tp5;
barCount5 = barCount5 + 1;
End;
// --- Data3: 8분 (바 마감시에만 누적) ---
If BarStatus(3) = 2 then
Begin
pv8 = tp8 * (Volume of Data3);
cumPV8 = cumPV8 + pv8;
cumV8 = cumV8 + (Volume of Data3);
If cumV8 > 0 then vwap8m = cumPV8 / cumV8 Else vwap8m = tp8;
barCount8 = barCount8 + 1;
End;
// ================== 시간 필터 ================== //
inTime = True;
If UseTimeFilter then
inTime = ( (Time >= AM_Start and Time <= AM_End)
or (Time >= PM_Start and Time <= PM_End) );
// ================== 5분 방향 필터 ================== //
// 조건: 5분 종가가 5분 VWAP 위/아래이고, Confirm5mBars 이전에는 반대였음(돌파/이탈)
If Confirm5mBars < 1 then Confirm5mBars = 1;
longBias = False;
shortBias = False;
If barCount5 > Confirm5mBars then
Begin
longBias = (Close of Data2 > vwap5m) and (Close[Confirm5mBars] of Data2 <= vwap5m[Confirm5mBars] of Data2);
shortBias = (Close of Data2 < vwap5m) and (Close[Confirm5mBars] of Data2 >= vwap5m[Confirm5mBars] of Data2);
End;
// ================== 8분 확인(컨펌) ================== //
// 단순: 현재 8분 종가가 8분 VWAP 위/아래
confirm8Long = (Close of Data3 > vwap8m);
confirm8Short = (Close of Data3 < vwap8m);
// ================== 500틱 트리거(되돌림 후 재안착) ================== //
// TickConfirmBars: 1 또는 2 권장
If TickConfirmBars < 1 then TickConfirmBars = 1;
If TickConfirmBars > 2 then TickConfirmBars = 2;
trigLong = False;
trigShort = False;
// VWAP 근접 데드존 회피
distT = AbsValue(Close - vwapTick);
// 롱 트리거: 현재 Close > vwapTick 이고, 직전(TickConfirmBars)에는 경계/아래 → 재안착
If barCountT > TickConfirmBars then
Begin
If TickConfirmBars = 1 then
trigLong = (Close > vwapTick) and (distT > DeadZonePt)
Else
trigLong = (Close > vwapTick) and (Close[1] <= vwapTick[1]) and (distT > DeadZonePt);
// 숏 트리거: 현재 Close < vwapTick 이고, 직전에는 경계/위 → 재이탈
If TickConfirmBars = 1 then
trigShort = (Close < vwapTick) and (distT > DeadZonePt)
Else
trigShort = (Close < vwapTick) and (Close[1] >= vwapTick[1]) and (distT > DeadZonePt);
End;
// ================== 최종 진입 신호(Trigger = 실행 조건) ================== //
// 롱 실행: 5분 롱 바이어스 AND 8분 컨펌 AND 500틱 롱 트리거
If inTime and longBias and confirm8Long and trigLong then
Begin
Buy();
Alert("TRIGGER LONG: 5m dir + 8m confirm + 500T re-anchor");
End;
// 숏 실행: 5분 숏 바이어스 AND 8분 컨펌 AND 500틱 숏 트리거
If inTime and shortBias and confirm8Short and trigShort then
Begin
Sell();
Alert("TRIGGER SHORT: 5m dir + 8m confirm + 500T re-anchor");
End;
// ================== 보조 플롯 ================== //
Plot1(vwapTick, "VWAP_500T");
수고하세요