커뮤니티
일봉전략을 5분봉전략으로의 변환 코드 검토 부탁 드립니다. (수정)
얼마 전 올렸던 질문(글번호: 194570) 관련 추가질문입니다.
아래와 같이 코드를 변경했는데, 이게 맞나 싶네요... 결과가 너무 달라요.
그리고, 날짜변경시 Daily~로 시작되는 변수들을 업데이트 하도록 했는데,
한국투자증권 나스닥 선물 시간상 한국자정에 날짜가 바뀌는 거 같은데
미국시장 기준으로 바꾸도록 하려면 어떻게 하나요?
검토 좀 부탁 드립니다.
늘 감사 드립니다.
============= 원본코드 =============
// --- 원본 전략 로직 시작 (문법 수정 적용) ---
PcntChange = Close / DayClose(PChng) * 100;
If PcntChange < 100 - OverRange then Begin OS = TRUE; HighBand = Highest( High , Bands ); End;
If PcntChange > 100 + OverRange then Begin OB = TRUE; LowBand = Lowest( Low, Bands); End;
if EntriesToday(sDate) < 1 and NoContract > 0 and TradeAllowed then {
If OS and MarketPosition <> 1 Then Buy("B", AtStop, HighBand, NoContract);
If OB and MarketPosition <> -1 then Sell("S", AtStop, LowBand, NoContract);
}
If marketposition == 1 and C > entryprice + profit then ExitLong("LX_Profit", AtMarket);
if marketposition == -1 and C < entryprice - profit then ExitShort("SX_Profit", AtMarket);
if MRO( OS == false, MRO_Length, MRO_Threshold ) == -1 then OS = false;
if MRO( OB == false, MRO_Length, MRO_Threshold ) == -1 then OB = false;
ExitLong("EL_Trail", AtStop, lowest(low,exitperiod));
ExitShort("ES_Trail", AtStop, highest(high,exitperiod));
SetStopLoss(stopPer, PercentStop);
// --- 원본 전략 로직 종료 ---
============= 수정코드 =============
Array:
DailyReturns[100](0),
DailyOpenArray[100](0),
DailyHighArray[100](0),
DailyLowArray[100](0),
DailyCloseArray[100](0);
// ================== 로직 시작 ==================
// 1. 5분봉을 일봉으로 집계
CurrentDate = sDate;
if Index == 0 then begin
PrevDate = CurrentDate;
DailyOpen = Open;
DailyHigh = High;
DailyLow = Low;
DailyBarCount = 0;
end
// 날짜가 바뀌었을 때 (새로운 거래일 시작)
if CurrentDate != PrevDate then begin
// 전일 일봉 데이터를 배열에 저장
For Value1 = 99 DownTo 1 begin
DailyOpenArray[Value1] = DailyOpenArray[Value1-1];
DailyHighArray[Value1] = DailyHighArray[Value1-1];
DailyLowArray[Value1] = DailyLowArray[Value1-1];
DailyCloseArray[Value1] = DailyCloseArray[Value1-1];
end;
DailyOpenArray[0] = PrevDailyOpen;
DailyHighArray[0] = PrevDailyHigh;
DailyLowArray[0] = PrevDailyLow;
DailyCloseArray[0] = PrevDailyClose;
// 새로운 일봉 시작
DailyOpen = Open;
DailyHigh = High;
DailyLow = Low;
DailyBarCount = DailyBarCount + 1;
PrevDate = CurrentDate;
end
// 같은 날 내에서 고가/저가 업데이트
if High > DailyHigh then DailyHigh = High;
if Low < DailyLow then DailyLow = Low;
DailyClose = Close;
// 이전 일봉 데이터 저장
PrevDailyOpen = DailyOpen;
PrevDailyHigh = DailyHigh;
PrevDailyLow = DailyLow;
PrevDailyClose = DailyClose;
.......... 생략 ..........
if CurrentDate != PrevDate and DailyBarCount > 1 then begin
if DailyOpenArray[1] > 0 then
DailyReturn = (DailyOpenArray[0] - DailyOpenArray[1]) / DailyOpenArray[1]
else
DailyReturn = 0;
For Value1 = VaR_Period - 1 DownTo 1 begin
DailyReturns[Value1] = DailyReturns[Value1-1];
end;
DailyReturns[0] = DailyReturn;
end
.......... 생략 ..........
// 5. 원본 전략 로직 (일봉 기준 계산)
if DailyBarCount >= Pchng and DailyCloseArray[Pchng-1] > 0 then
PcntChange = DailyClose / DailyCloseArray[Pchng-1] * 100
else
PcntChange = 100;
If PcntChange < 100 - OverRange then begin
OS = true;
// 최근 Bands개 일봉의 최고가
HighBand = DailyHighArray[0];
For Value1 = 1 to Bands-1 begin
if DailyHighArray[Value1] > HighBand then
HighBand = DailyHighArray[Value1];
end;
end
else
OS = false;
If PcntChange > 100 + OverRange then begin
OB = true;
// 최근 Bands개 일봉의 최저가
LowBand = DailyLowArray[0];
For Value1 = 1 to Bands-1 begin
if DailyLowArray[Value1] < LowBand then
LowBand = DailyLowArray[Value1];
end;
end
else
OB = false;
// 6. 주문 실행 (5분봉에서 즉시 실행)
if EntriesToday(sDate) < 1 and NoContract > 0 and TradeAllowed then begin
If OS and MarketPosition <> 1 then
Buy("B", AtStop, HighBand, NoContract);
If OB and MarketPosition <> -1 then
Sell("S", AtStop, LowBand, NoContract);
end
If MarketPosition == 1 and C > EntryPrice + profit then
ExitLong("LX_Profit", AtMarket);
if MarketPosition == -1 and C < EntryPrice - profit then
ExitShort("SX_Profit", AtMarket);
if MRO(OS == false, MRO_Length, MRO_Threshold) == -1 then OS = false;
if MRO(OB == false, MRO_Length, MRO_Threshold) == -1 then OB = false;
// exitperiod도 일봉 기준으로 계산
Var: ExitLowBand(99999), ExitHighBand(0);
ExitLowBand = DailyLowArray[0];
ExitHighBand = DailyHighArray[0];
For Value1 = 1 to exitperiod-1 begin
if DailyLowArray[Value1] < ExitLowBand then
ExitLowBand = DailyLowArray[Value1];
if DailyHighArray[Value1] > ExitHighBand then
ExitHighBand = DailyHighArray[Value1];
end;
ExitLong("EL_Trail", AtStop, ExitLowBand);
ExitShort("ES_Trail", AtStop, ExitHighBand);
SetStopLoss(stopPer, PercentStop);
답변 1

예스스탁 예스스탁 답변
2025-10-16 17:37:18.0