커뮤니티

수정부탁드립니다

프로필 이미지
외국인
2022-11-04 21:58:35
861
글번호 163540
답변완료
변곡점 자리에서 에서 단가표시 및 수직선표시 부탁드립니다 Input:atrLength(60),multi(3),fTetxt10(20); Var:j(0),dayATR(0),sum(0),upTr(100),dnTr(-100),trnd(0), date11(0),date12(0),time11(0),time12(0),TL1(0),tx(0), date21(0),date22(0),time21(0),time22(0),TL2(0), date31(0),date32(0),time31(0),time32(0),TL3(0); Array:hiVal[10](0),loVal[10](0),hiBar[10](0),loBar[10](0); //hiVal[1]은 전고점, hiVal[2]는 전전고점, hiVal[3]은 전전전고점 //hiVal[0]은 변곡점 이후 현재봉까지의 고점. 현재 고점은 진행중이므로 계속 바뀐다. //loVal[0]은 반대 개념 sum = 0; for j = 1 to atrLength { sum = sum + Max(C[j+1],H[j]) - Min(C[j+1],L[j]); } dayATR = sum/atrLength; //일봉기준으로 ATR 산출 for j = 1 to 9 { //전고,전저점을 9개까지 보관 loBar[j] = loBar[j] + 1; //전저점의 위치. 현재 봉으로부터 떨어져 있는 거리 hiBar[j] = hiBar[j] + 1; //전고점의 위치 } if hiVal[0] <= H or hiVal[0] == 0 then { //전고,전저점 이후 현재까지의 고점 hiVal[0] = H; //0을 체크한 이유는 초기에 값이 없는 구간이 생기기 때문 hiBar[0] = 0; //현재 고점의 위치가 0이란 것은 현재봉의 고가가 구간 고점이라는 의미 } else { hiBar[0] = hiBar[0] + 1; //현재 고점의 위치 } if loVal[0] >= L or loVal[0] == 0 then { //전고,전저점 이후 현재까지 저점 loVal[0] = L; loBar[0] = 0; } else { loBar[0] = loBar[0] + 1; //현재 구간 저점의 위치 } if trnd != dnTr && hiVal[0] > H && hiVal[0] - (dayATR * multi) > L then trnd = dnTr; //저가가 고가 대비 변동률보다 밑으로 떨어지면 하락추세로 설정 //단, 현재봉의 고가가 변곡점 이후 최고가이면 상승 추세가 진행중이라고 본다. //그래서 현재봉의 고가가 hiVal[0]보다 작다는 조건이 추가되었다. else if trnd != upTr && loVal[0] < L && loVal[0] + (dayATR * multi) < H then trnd = upTr; //고가가 저가 대비 변동률보다 높으면 상승추세로 설정 if trnd[1] == upTr and trnd == dnTr then { //상승추세였다가 하락추세로 바뀌었다면 for j = 8 downto 1 { //새로운 전고점이 생기는 것이므로 hiVal[j+1] = hiVal[j]; //전고점을 하나씩 뒤로 보낸다. hiBar[j+1] = hiBar[j]; //전고점은 전전고점이 되고, 전전고점은 전전전고점이 된다. } hiVal[1] = hiVal[0]; //새로운 전고점에 현재 고점을 대입 hiBar[1] = hiBar[0]; hiVal[0] = H; //전고점이 확정되었으므로 전고점 이후 최고가는 현재봉의 고가 hiBar[0] = 0; loVal[0] = L; loBar[0] = 0; //전고점이 새로 생긴 것이니까 전저점에서 전고점까지 추세선을 긋는다. date11 = date[loBar[1]]; //추세선 시작일. 전저점의 날짜 time11 = stime[loBar[1]]; //추세선 시작시간 Value11 = loVal[1]; //추세선 시작가격 date12 = date[hiBar[1]]; //추세선 종료일. 전고점의 날짜 time12 = stime[hiBar[1]]; //추세선 종료시간 Value12 = hiVal[1]; //추세선 종료가격 TL1 = TL_New(date11,time11,Value11,date12,time12,Value12); //TL_New는 신규 추세선을 그려주는 함수 } if trnd[1] == dnTr and trnd == dnTr and //추세는 하락 상태에서 바뀌지 않았는데 hiVal[1] < hiVal[0] then { //전고점보다 더 높은 고점이 출현했다면 if loVal[1] <= loVal[0] then { //전저점은 갱신되지 않았다면 hiVal[1] = hiVal[0]; //전고점을 현재의 고점으로 바꿔준다. hiBar[1] = hiBar[0]; hiVal[0] = H; hiBar[0] = 0; loVal[0] = L; loBar[0] = 0; //전고점이 추가된 게 아니고 바뀐 것이므로 종료일,종료시간,종료가격만 바꿔준다. date12 = date[hiBar[1]]; //추세선 종료일 time12 = stime[hiBar[1]]; Value12 = hiVal[1]; TL_SetEnd(TL1, date12,time12,Value12); //TL_SetEnd는 기존추세선의 종료지점을 변경해주는 추세선 함수이다. //TL_Delete 함수를 써서 직전의 추세선을 지우고 다시 TL_New로 추세선을 추가해도 된다. } else { //전저점도 갱신되었다면 for j = 8 downto 1 { //전고점, 전저점을 새로이 추기 hiVal[j+1] = hiVal[j]; //전고점을 하나씩 뒤로 보낸다. hiBar[j+1] = hiBar[j]; //전고점은 전전고점이 되고, 전전고점은 전전전고점이 된다. loVal[j+1] = loVal[j]; //전저점을 하나씩 뒤로 보낸다. loBar[j+1] = loBar[j]; //전저점은 전전저점이 되고, 전전저점은 전전전저점이 된다. } hiVal[1] = hiVal[0]; //새로운 전고점에 현재 고점을 대입 hiBar[1] = hiBar[0]; loVal[1] = loVal[0]; //새로운 전저점에 현재 저점을 대입 loBar[1] = loBar[0]; hiVal[0] = H; //전고점 이후 최고가는 현재봉의 고가 hiBar[0] = 0; loVal[0] = L; loBar[0] = 0; //전저,전고점이 새로 생긴 것이니까 전전고점에서 전저점까지 //그리고 전저점에서 전고점까지 추세선 2개를 생성한다. date11 = date[hiBar[2]]; //추세선 시작일. 전전고점의 날짜 time11 = stime[hiBar[2]]; //추세선 시작시간 Value11 = hiVal[2]; //추세선 시작가격 date12 = date[loBar[1]]; //추세선 종료일. 전저점의 날짜 time12 = stime[loBar[1]]; //추세선 종료시간 Value12 = loVal[1]; //추세선 종료가격 TL1 = TL_New(date11,time11,Value11,date12,time12,Value12); TL_SetSize(TL1,2); date11 = date[loBar[1]]; //추세선 시작일. 전저점의 날짜 time11 = stime[loBar[1]]; //추세선 시작시간 Value11 = loVal[1]; //추세선 시작가격 date12 = date[hiBar[1]]; //추세선 종료일. 전고점의 날짜 time12 = stime[hiBar[1]]; //추세선 종료시간 Value12 = hiVal[1]; //추세선 종료가격 TL1 = TL_New(date11,time11,Value11,date12,time12,Value12); } } if trnd[1] == dnTr and trnd == upTr then { //추세가 하락에서 상승으로 바뀌었을 경우 for j = 8 downto 1 { //이전저점은 전전저점으로, 전전저점은 전전전저점으로 번호를 부여 loVal[j+1] = loVal[j]; loBar[j+1] = loBar[j]; } loVal[1] = loVal[0]; loBar[1] = loBar[0]; loVal[0] = L; loBar[0] = 0; hiVal[0] = H; hiBar[0] = 0; date11 = date[hiBar[1]]; //전저점이 새로이 생긴 것이므로 시작점은 전고점이 된다. time11 = stime[hiBar[1]]; Value11 = hiVal[1]; date12 = date[loBar[1]]; time12 = stime[loBar[1]]; Value12 = loVal[1]; TL1 = TL_New(date11,time11,Value11,date12,time12,Value12); } if trnd[1] == upTr and trnd == upTr and //추세는 상승을 유지하고 있는데 loVal[1] > loVal[0] then { //전저점보다 낮은 저가가 출현했다면 if hiVal[1] >= hiVal[0] then { //고점 갱신이 되지 않았다면 loVal[1] = loVal[0]; //직전의 전저점만 바꿔준다. loBar[1] = loBar[0]; loVal[0] = L; loBar[0] = 0; hiVal[0] = H; hiBar[0] = 0; date12 = date[loBar[1]]; time12 = stime[loBar[1]]; Value12 = loVal[1]; TL_SetEnd(TL1, date12,time12,Value12); } else { //고점도 이전고점보다 높다면 for j = 8 downto 1 { //전고점,전저점을 새로이 생성 hiVal[j+1] = hiVal[j]; hiBar[j+1] = hiBar[j]; loVal[j+1] = loVal[j]; loBar[j+1] = loBar[j]; } hiVal[1] = hiVal[0]; hiBar[1] = hiBar[0]; loVal[1] = loVal[0]; loBar[1] = loBar[0]; loVal[0] = L; loBar[0] = 0; hiVal[0] = H; hiBar[0] = 0; date11 = date[loBar[2]]; //시작점이 전전저점 time11 = stime[loBar[2]]; Value11 = loVal[2]; date12 = date[hiBar[1]]; //종료는 전고점 time12 = stime[hiBar[1]]; Value12 = hiVal[1]; TL1 = TL_New(date11,time11,Value11,date12,time12,Value12); TL_SetSize(TL1,2); date11 = date[hiBar[1]]; //2번째 시작은 전고점이 된다. time11 = stime[hiBar[1]]; Value11 = hiVal[1]; date12 = date[loBar[1]]; //2번째 종료는 전저점 time12 = stime[loBar[1]]; Value12 = loVal[1]; TL1 = TL_New(date11,time11,Value11,date12,time12,Value12); } } /* if loVal[2] < loVal[1] then { if loBar[2][1] + 1 != loBar[2][0] then { date21 = date[loBar[2]]; time21 = stime[loBar[2]]; Value21 = loVal[2]; date22 = date[0]; //추세선이므로 현재 봉까지 그려준다. time22 = stime[0]; Value22 = (loVal[1]-loVal[2])/(loBar[2]-loBar[1])*loBar[2]+LoVal[2]; //종료시점의 가격은 직선의 기울기와 절편을 계산해서 구한다. TL2 = TL_New(date21,time21,Value21,date22,time22,Value22); } else { //전전저점이 바뀌지 않았다면 종료시점만 변경하면 된다. date22 = date[0]; time22 = stime[0]; Value22 = (loVal[1]-loVal[2])/(loBar[2]-loBar[1])*loBar[2]+LoVal[2]; TL_SetEnd(TL2, date22,time22,Value22); //TL_SetExtRight 함수는 추세선을 오른쪽으로 연장하는 함수인데 //이 함수를 사용하면 모든 추세선이 현재봉까지 연장되어 알아볼 수가 없다. } } if hiVal[2] > hiVal[1] then { if hiBar[2][1] + 1 != hiBar[2][0] then { date31 = date[hiBar[2]]; time31 = stime[hiBar[2]]; Value31 = hiVal[2]; date32 = date[0]; time32 = stime[0]; Value32 = (hiVal[1]-hiVal[2])/(hiBar[2]-hiBar[1])*hiBar[2]+hiVal[2]; TL3 = TL_New(date31,time31,Value31,date32,time32,Value32); } else { date32 = date[0]; time32 = stime[0]; Value32 = (hiVal[1]-hiVal[2])/(hiBar[2]-hiBar[1])*hiBar[2]+hiVal[2]; TL_SetEnd(TL3, date32,time32,Value32); } } */ if trnd == upTr and loVal[2] > loVal[1] then TL_SetColor(TL1,BLUE); else if trnd == dnTr and hiVal[2] < hiVal[1] then TL_SetColor(TL1,RED); else TL_SetColor(TL1,BLACK); TL_SetSize(TL1,2); TL_SetColor(TL2,RED); TL_SetColor(TL3,BLUE);
강조
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2022-11-07 09:02:07

안녕하세요 예스스탁입니다. Input:atrLength(60),multi(3),fTetxt10(20); Var:j(0),dayATR(0),sum(0),upTr(100),dnTr(-100),trnd(0), date11(0),date12(0),time11(0),time12(0),TL1(0),tx(0), date21(0),date22(0),time21(0),time22(0),TL2(0), date31(0),date32(0),time31(0),time32(0),TL3(0),tx1(0); Array:hiVal[10](0),loVal[10](0),hiBar[10](0),loBar[10](0); //hiVal[1]은 전고점, hiVal[2]는 전전고점, hiVal[3]은 전전전고점 //hiVal[0]은 변곡점 이후 현재봉까지의 고점. 현재 고점은 진행중이므로 계속 바뀐다. //loVal[0]은 반대 개념 sum = 0; for j = 1 to atrLength { sum = sum + Max(C[j+1],H[j]) - Min(C[j+1],L[j]); } dayATR = sum/atrLength; //일봉기준으로 ATR 산출 for j = 1 to 9 { //전고,전저점을 9개까지 보관 loBar[j] = loBar[j] + 1; //전저점의 위치. 현재 봉으로부터 떨어져 있는 거리 hiBar[j] = hiBar[j] + 1; //전고점의 위치 } if hiVal[0] <= H or hiVal[0] == 0 then { //전고,전저점 이후 현재까지의 고점 hiVal[0] = H; //0을 체크한 이유는 초기에 값이 없는 구간이 생기기 때문 hiBar[0] = 0; //현재 고점의 위치가 0이란 것은 현재봉의 고가가 구간 고점이라는 의미 } else { hiBar[0] = hiBar[0] + 1; //현재 고점의 위치 } if loVal[0] >= L or loVal[0] == 0 then { //전고,전저점 이후 현재까지 저점 loVal[0] = L; loBar[0] = 0; } else { loBar[0] = loBar[0] + 1; //현재 구간 저점의 위치 } if trnd != dnTr && hiVal[0] > H && hiVal[0] - (dayATR * multi) > L then trnd = dnTr; //저가가 고가 대비 변동률보다 밑으로 떨어지면 하락추세로 설정 //단, 현재봉의 고가가 변곡점 이후 최고가이면 상승 추세가 진행중이라고 본다. //그래서 현재봉의 고가가 hiVal[0]보다 작다는 조건이 추가되었다. else if trnd != upTr && loVal[0] < L && loVal[0] + (dayATR * multi) < H then trnd = upTr; //고가가 저가 대비 변동률보다 높으면 상승추세로 설정 if trnd[1] == upTr and trnd == dnTr then { //상승추세였다가 하락추세로 바뀌었다면 for j = 8 downto 1 { //새로운 전고점이 생기는 것이므로 hiVal[j+1] = hiVal[j]; //전고점을 하나씩 뒤로 보낸다. hiBar[j+1] = hiBar[j]; //전고점은 전전고점이 되고, 전전고점은 전전전고점이 된다. } hiVal[1] = hiVal[0]; //새로운 전고점에 현재 고점을 대입 hiBar[1] = hiBar[0]; hiVal[0] = H; //전고점이 확정되었으므로 전고점 이후 최고가는 현재봉의 고가 hiBar[0] = 0; loVal[0] = L; loBar[0] = 0; //전고점이 새로 생긴 것이니까 전저점에서 전고점까지 추세선을 긋는다. date11 = date[loBar[1]]; //추세선 시작일. 전저점의 날짜 time11 = stime[loBar[1]]; //추세선 시작시간 Value11 = loVal[1]; //추세선 시작가격 date12 = date[hiBar[1]]; //추세선 종료일. 전고점의 날짜 time12 = stime[hiBar[1]]; //추세선 종료시간 Value12 = hiVal[1]; //추세선 종료가격 TL1 = TL_New(date11,time11,Value11,date12,time12,Value12); //TL_New는 신규 추세선을 그려주는 함수 tx1 = text_new(date12,time12,Value12,NumToStr(value12,2)); Text_SetStyle(tx1,2,1); tl2 = TL_New(date12,time12,0,date12,time12,99999999); } if trnd[1] == dnTr and trnd == dnTr and //추세는 하락 상태에서 바뀌지 않았는데 hiVal[1] < hiVal[0] then { //전고점보다 더 높은 고점이 출현했다면 if loVal[1] <= loVal[0] then { //전저점은 갱신되지 않았다면 hiVal[1] = hiVal[0]; //전고점을 현재의 고점으로 바꿔준다. hiBar[1] = hiBar[0]; hiVal[0] = H; hiBar[0] = 0; loVal[0] = L; loBar[0] = 0; //전고점이 추가된 게 아니고 바뀐 것이므로 종료일,종료시간,종료가격만 바꿔준다. date12 = date[hiBar[1]]; //추세선 종료일 time12 = stime[hiBar[1]]; Value12 = hiVal[1]; TL_SetEnd(TL1, date12,time12,Value12); //TL_SetEnd는 기존추세선의 종료지점을 변경해주는 추세선 함수이다. //TL_Delete 함수를 써서 직전의 추세선을 지우고 다시 TL_New로 추세선을 추가해도 된다. } else { //전저점도 갱신되었다면 for j = 8 downto 1 { //전고점, 전저점을 새로이 추기 hiVal[j+1] = hiVal[j]; //전고점을 하나씩 뒤로 보낸다. hiBar[j+1] = hiBar[j]; //전고점은 전전고점이 되고, 전전고점은 전전전고점이 된다. loVal[j+1] = loVal[j]; //전저점을 하나씩 뒤로 보낸다. loBar[j+1] = loBar[j]; //전저점은 전전저점이 되고, 전전저점은 전전전저점이 된다. } hiVal[1] = hiVal[0]; //새로운 전고점에 현재 고점을 대입 hiBar[1] = hiBar[0]; loVal[1] = loVal[0]; //새로운 전저점에 현재 저점을 대입 loBar[1] = loBar[0]; hiVal[0] = H; //전고점 이후 최고가는 현재봉의 고가 hiBar[0] = 0; loVal[0] = L; loBar[0] = 0; //전저,전고점이 새로 생긴 것이니까 전전고점에서 전저점까지 //그리고 전저점에서 전고점까지 추세선 2개를 생성한다. date11 = date[hiBar[2]]; //추세선 시작일. 전전고점의 날짜 time11 = stime[hiBar[2]]; //추세선 시작시간 Value11 = hiVal[2]; //추세선 시작가격 date12 = date[loBar[1]]; //추세선 종료일. 전저점의 날짜 time12 = stime[loBar[1]]; //추세선 종료시간 Value12 = loVal[1]; //추세선 종료가격 TL1 = TL_New(date11,time11,Value11,date12,time12,Value12); TL_SetSize(TL1,2); date11 = date[loBar[1]]; //추세선 시작일. 전저점의 날짜 time11 = stime[loBar[1]]; //추세선 시작시간 Value11 = loVal[1]; //추세선 시작가격 date12 = date[hiBar[1]]; //추세선 종료일. 전고점의 날짜 time12 = stime[hiBar[1]]; //추세선 종료시간 Value12 = hiVal[1]; //추세선 종료가격 TL1 = TL_New(date11,time11,Value11,date12,time12,Value12); } } if trnd[1] == dnTr and trnd == upTr then { //추세가 하락에서 상승으로 바뀌었을 경우 for j = 8 downto 1 { //이전저점은 전전저점으로, 전전저점은 전전전저점으로 번호를 부여 loVal[j+1] = loVal[j]; loBar[j+1] = loBar[j]; } loVal[1] = loVal[0]; loBar[1] = loBar[0]; loVal[0] = L; loBar[0] = 0; hiVal[0] = H; hiBar[0] = 0; date11 = date[hiBar[1]]; //전저점이 새로이 생긴 것이므로 시작점은 전고점이 된다. time11 = stime[hiBar[1]]; Value11 = hiVal[1]; date12 = date[loBar[1]]; time12 = stime[loBar[1]]; Value12 = loVal[1]; TL1 = TL_New(date11,time11,Value11,date12,time12,Value12); tx1 = text_new(date12,time12,Value12,NumToStr(value12,2)); Text_SetStyle(tx1,2,0); tl2 = TL_New(date12,time12,0,date12,time12,99999999); } if trnd[1] == upTr and trnd == upTr and //추세는 상승을 유지하고 있는데 loVal[1] > loVal[0] then { //전저점보다 낮은 저가가 출현했다면 if hiVal[1] >= hiVal[0] then { //고점 갱신이 되지 않았다면 loVal[1] = loVal[0]; //직전의 전저점만 바꿔준다. loBar[1] = loBar[0]; loVal[0] = L; loBar[0] = 0; hiVal[0] = H; hiBar[0] = 0; date12 = date[loBar[1]]; time12 = stime[loBar[1]]; Value12 = loVal[1]; TL_SetEnd(TL1, date12,time12,Value12); } else { //고점도 이전고점보다 높다면 for j = 8 downto 1 { //전고점,전저점을 새로이 생성 hiVal[j+1] = hiVal[j]; hiBar[j+1] = hiBar[j]; loVal[j+1] = loVal[j]; loBar[j+1] = loBar[j]; } hiVal[1] = hiVal[0]; hiBar[1] = hiBar[0]; loVal[1] = loVal[0]; loBar[1] = loBar[0]; loVal[0] = L; loBar[0] = 0; hiVal[0] = H; hiBar[0] = 0; date11 = date[loBar[2]]; //시작점이 전전저점 time11 = stime[loBar[2]]; Value11 = loVal[2]; date12 = date[hiBar[1]]; //종료는 전고점 time12 = stime[hiBar[1]]; Value12 = hiVal[1]; TL1 = TL_New(date11,time11,Value11,date12,time12,Value12); TL_SetSize(TL1,2); date11 = date[hiBar[1]]; //2번째 시작은 전고점이 된다. time11 = stime[hiBar[1]]; Value11 = hiVal[1]; date12 = date[loBar[1]]; //2번째 종료는 전저점 time12 = stime[loBar[1]]; Value12 = loVal[1]; TL1 = TL_New(date11,time11,Value11,date12,time12,Value12); } } /* if loVal[2] < loVal[1] then { if loBar[2][1] + 1 != loBar[2][0] then { date21 = date[loBar[2]]; time21 = stime[loBar[2]]; Value21 = loVal[2]; date22 = date[0]; //추세선이므로 현재 봉까지 그려준다. time22 = stime[0]; Value22 = (loVal[1]-loVal[2])/(loBar[2]-loBar[1])*loBar[2]+LoVal[2]; //종료시점의 가격은 직선의 기울기와 절편을 계산해서 구한다. TL2 = TL_New(date21,time21,Value21,date22,time22,Value22); } else { //전전저점이 바뀌지 않았다면 종료시점만 변경하면 된다. date22 = date[0]; time22 = stime[0]; Value22 = (loVal[1]-loVal[2])/(loBar[2]-loBar[1])*loBar[2]+LoVal[2]; TL_SetEnd(TL2, date22,time22,Value22); //TL_SetExtRight 함수는 추세선을 오른쪽으로 연장하는 함수인데 //이 함수를 사용하면 모든 추세선이 현재봉까지 연장되어 알아볼 수가 없다. } } if hiVal[2] > hiVal[1] then { if hiBar[2][1] + 1 != hiBar[2][0] then { date31 = date[hiBar[2]]; time31 = stime[hiBar[2]]; Value31 = hiVal[2]; date32 = date[0]; time32 = stime[0]; Value32 = (hiVal[1]-hiVal[2])/(hiBar[2]-hiBar[1])*hiBar[2]+hiVal[2]; TL3 = TL_New(date31,time31,Value31,date32,time32,Value32); } else { date32 = date[0]; time32 = stime[0]; Value32 = (hiVal[1]-hiVal[2])/(hiBar[2]-hiBar[1])*hiBar[2]+hiVal[2]; TL_SetEnd(TL3, date32,time32,Value32); } } */ if trnd == upTr and loVal[2] > loVal[1] then { TL_SetColor(TL1,BLUE); TL_SetColor(TL2,BLUE); } else if trnd == dnTr and hiVal[2] < hiVal[1] then { TL_SetColor(TL1,RED); TL_SetColor(TL2,RED); } else { TL_SetColor(TL1,BLACK); TL_SetColor(TL2,BLACK); } TL_SetSize(TL1,2); TL_SetColor(TL3,BLUE); 즐거운 하루되세요 > 외국인 님이 쓴 글입니다. > 제목 : 수정부탁드립니다 > 변곡점 자리에서 에서 단가표시 및 수직선표시 부탁드립니다 Input:atrLength(60),multi(3),fTetxt10(20); Var:j(0),dayATR(0),sum(0),upTr(100),dnTr(-100),trnd(0), date11(0),date12(0),time11(0),time12(0),TL1(0),tx(0), date21(0),date22(0),time21(0),time22(0),TL2(0), date31(0),date32(0),time31(0),time32(0),TL3(0); Array:hiVal[10](0),loVal[10](0),hiBar[10](0),loBar[10](0); //hiVal[1]은 전고점, hiVal[2]는 전전고점, hiVal[3]은 전전전고점 //hiVal[0]은 변곡점 이후 현재봉까지의 고점. 현재 고점은 진행중이므로 계속 바뀐다. //loVal[0]은 반대 개념 sum = 0; for j = 1 to atrLength { sum = sum + Max(C[j+1],H[j]) - Min(C[j+1],L[j]); } dayATR = sum/atrLength; //일봉기준으로 ATR 산출 for j = 1 to 9 { //전고,전저점을 9개까지 보관 loBar[j] = loBar[j] + 1; //전저점의 위치. 현재 봉으로부터 떨어져 있는 거리 hiBar[j] = hiBar[j] + 1; //전고점의 위치 } if hiVal[0] <= H or hiVal[0] == 0 then { //전고,전저점 이후 현재까지의 고점 hiVal[0] = H; //0을 체크한 이유는 초기에 값이 없는 구간이 생기기 때문 hiBar[0] = 0; //현재 고점의 위치가 0이란 것은 현재봉의 고가가 구간 고점이라는 의미 } else { hiBar[0] = hiBar[0] + 1; //현재 고점의 위치 } if loVal[0] >= L or loVal[0] == 0 then { //전고,전저점 이후 현재까지 저점 loVal[0] = L; loBar[0] = 0; } else { loBar[0] = loBar[0] + 1; //현재 구간 저점의 위치 } if trnd != dnTr && hiVal[0] > H && hiVal[0] - (dayATR * multi) > L then trnd = dnTr; //저가가 고가 대비 변동률보다 밑으로 떨어지면 하락추세로 설정 //단, 현재봉의 고가가 변곡점 이후 최고가이면 상승 추세가 진행중이라고 본다. //그래서 현재봉의 고가가 hiVal[0]보다 작다는 조건이 추가되었다. else if trnd != upTr && loVal[0] < L && loVal[0] + (dayATR * multi) < H then trnd = upTr; //고가가 저가 대비 변동률보다 높으면 상승추세로 설정 if trnd[1] == upTr and trnd == dnTr then { //상승추세였다가 하락추세로 바뀌었다면 for j = 8 downto 1 { //새로운 전고점이 생기는 것이므로 hiVal[j+1] = hiVal[j]; //전고점을 하나씩 뒤로 보낸다. hiBar[j+1] = hiBar[j]; //전고점은 전전고점이 되고, 전전고점은 전전전고점이 된다. } hiVal[1] = hiVal[0]; //새로운 전고점에 현재 고점을 대입 hiBar[1] = hiBar[0]; hiVal[0] = H; //전고점이 확정되었으므로 전고점 이후 최고가는 현재봉의 고가 hiBar[0] = 0; loVal[0] = L; loBar[0] = 0; //전고점이 새로 생긴 것이니까 전저점에서 전고점까지 추세선을 긋는다. date11 = date[loBar[1]]; //추세선 시작일. 전저점의 날짜 time11 = stime[loBar[1]]; //추세선 시작시간 Value11 = loVal[1]; //추세선 시작가격 date12 = date[hiBar[1]]; //추세선 종료일. 전고점의 날짜 time12 = stime[hiBar[1]]; //추세선 종료시간 Value12 = hiVal[1]; //추세선 종료가격 TL1 = TL_New(date11,time11,Value11,date12,time12,Value12); //TL_New는 신규 추세선을 그려주는 함수 } if trnd[1] == dnTr and trnd == dnTr and //추세는 하락 상태에서 바뀌지 않았는데 hiVal[1] < hiVal[0] then { //전고점보다 더 높은 고점이 출현했다면 if loVal[1] <= loVal[0] then { //전저점은 갱신되지 않았다면 hiVal[1] = hiVal[0]; //전고점을 현재의 고점으로 바꿔준다. hiBar[1] = hiBar[0]; hiVal[0] = H; hiBar[0] = 0; loVal[0] = L; loBar[0] = 0; //전고점이 추가된 게 아니고 바뀐 것이므로 종료일,종료시간,종료가격만 바꿔준다. date12 = date[hiBar[1]]; //추세선 종료일 time12 = stime[hiBar[1]]; Value12 = hiVal[1]; TL_SetEnd(TL1, date12,time12,Value12); //TL_SetEnd는 기존추세선의 종료지점을 변경해주는 추세선 함수이다. //TL_Delete 함수를 써서 직전의 추세선을 지우고 다시 TL_New로 추세선을 추가해도 된다. } else { //전저점도 갱신되었다면 for j = 8 downto 1 { //전고점, 전저점을 새로이 추기 hiVal[j+1] = hiVal[j]; //전고점을 하나씩 뒤로 보낸다. hiBar[j+1] = hiBar[j]; //전고점은 전전고점이 되고, 전전고점은 전전전고점이 된다. loVal[j+1] = loVal[j]; //전저점을 하나씩 뒤로 보낸다. loBar[j+1] = loBar[j]; //전저점은 전전저점이 되고, 전전저점은 전전전저점이 된다. } hiVal[1] = hiVal[0]; //새로운 전고점에 현재 고점을 대입 hiBar[1] = hiBar[0]; loVal[1] = loVal[0]; //새로운 전저점에 현재 저점을 대입 loBar[1] = loBar[0]; hiVal[0] = H; //전고점 이후 최고가는 현재봉의 고가 hiBar[0] = 0; loVal[0] = L; loBar[0] = 0; //전저,전고점이 새로 생긴 것이니까 전전고점에서 전저점까지 //그리고 전저점에서 전고점까지 추세선 2개를 생성한다. date11 = date[hiBar[2]]; //추세선 시작일. 전전고점의 날짜 time11 = stime[hiBar[2]]; //추세선 시작시간 Value11 = hiVal[2]; //추세선 시작가격 date12 = date[loBar[1]]; //추세선 종료일. 전저점의 날짜 time12 = stime[loBar[1]]; //추세선 종료시간 Value12 = loVal[1]; //추세선 종료가격 TL1 = TL_New(date11,time11,Value11,date12,time12,Value12); TL_SetSize(TL1,2); date11 = date[loBar[1]]; //추세선 시작일. 전저점의 날짜 time11 = stime[loBar[1]]; //추세선 시작시간 Value11 = loVal[1]; //추세선 시작가격 date12 = date[hiBar[1]]; //추세선 종료일. 전고점의 날짜 time12 = stime[hiBar[1]]; //추세선 종료시간 Value12 = hiVal[1]; //추세선 종료가격 TL1 = TL_New(date11,time11,Value11,date12,time12,Value12); } } if trnd[1] == dnTr and trnd == upTr then { //추세가 하락에서 상승으로 바뀌었을 경우 for j = 8 downto 1 { //이전저점은 전전저점으로, 전전저점은 전전전저점으로 번호를 부여 loVal[j+1] = loVal[j]; loBar[j+1] = loBar[j]; } loVal[1] = loVal[0]; loBar[1] = loBar[0]; loVal[0] = L; loBar[0] = 0; hiVal[0] = H; hiBar[0] = 0; date11 = date[hiBar[1]]; //전저점이 새로이 생긴 것이므로 시작점은 전고점이 된다. time11 = stime[hiBar[1]]; Value11 = hiVal[1]; date12 = date[loBar[1]]; time12 = stime[loBar[1]]; Value12 = loVal[1]; TL1 = TL_New(date11,time11,Value11,date12,time12,Value12); } if trnd[1] == upTr and trnd == upTr and //추세는 상승을 유지하고 있는데 loVal[1] > loVal[0] then { //전저점보다 낮은 저가가 출현했다면 if hiVal[1] >= hiVal[0] then { //고점 갱신이 되지 않았다면 loVal[1] = loVal[0]; //직전의 전저점만 바꿔준다. loBar[1] = loBar[0]; loVal[0] = L; loBar[0] = 0; hiVal[0] = H; hiBar[0] = 0; date12 = date[loBar[1]]; time12 = stime[loBar[1]]; Value12 = loVal[1]; TL_SetEnd(TL1, date12,time12,Value12); } else { //고점도 이전고점보다 높다면 for j = 8 downto 1 { //전고점,전저점을 새로이 생성 hiVal[j+1] = hiVal[j]; hiBar[j+1] = hiBar[j]; loVal[j+1] = loVal[j]; loBar[j+1] = loBar[j]; } hiVal[1] = hiVal[0]; hiBar[1] = hiBar[0]; loVal[1] = loVal[0]; loBar[1] = loBar[0]; loVal[0] = L; loBar[0] = 0; hiVal[0] = H; hiBar[0] = 0; date11 = date[loBar[2]]; //시작점이 전전저점 time11 = stime[loBar[2]]; Value11 = loVal[2]; date12 = date[hiBar[1]]; //종료는 전고점 time12 = stime[hiBar[1]]; Value12 = hiVal[1]; TL1 = TL_New(date11,time11,Value11,date12,time12,Value12); TL_SetSize(TL1,2); date11 = date[hiBar[1]]; //2번째 시작은 전고점이 된다. time11 = stime[hiBar[1]]; Value11 = hiVal[1]; date12 = date[loBar[1]]; //2번째 종료는 전저점 time12 = stime[loBar[1]]; Value12 = loVal[1]; TL1 = TL_New(date11,time11,Value11,date12,time12,Value12); } } /* if loVal[2] < loVal[1] then { if loBar[2][1] + 1 != loBar[2][0] then { date21 = date[loBar[2]]; time21 = stime[loBar[2]]; Value21 = loVal[2]; date22 = date[0]; //추세선이므로 현재 봉까지 그려준다. time22 = stime[0]; Value22 = (loVal[1]-loVal[2])/(loBar[2]-loBar[1])*loBar[2]+LoVal[2]; //종료시점의 가격은 직선의 기울기와 절편을 계산해서 구한다. TL2 = TL_New(date21,time21,Value21,date22,time22,Value22); } else { //전전저점이 바뀌지 않았다면 종료시점만 변경하면 된다. date22 = date[0]; time22 = stime[0]; Value22 = (loVal[1]-loVal[2])/(loBar[2]-loBar[1])*loBar[2]+LoVal[2]; TL_SetEnd(TL2, date22,time22,Value22); //TL_SetExtRight 함수는 추세선을 오른쪽으로 연장하는 함수인데 //이 함수를 사용하면 모든 추세선이 현재봉까지 연장되어 알아볼 수가 없다. } } if hiVal[2] > hiVal[1] then { if hiBar[2][1] + 1 != hiBar[2][0] then { date31 = date[hiBar[2]]; time31 = stime[hiBar[2]]; Value31 = hiVal[2]; date32 = date[0]; time32 = stime[0]; Value32 = (hiVal[1]-hiVal[2])/(hiBar[2]-hiBar[1])*hiBar[2]+hiVal[2]; TL3 = TL_New(date31,time31,Value31,date32,time32,Value32); } else { date32 = date[0]; time32 = stime[0]; Value32 = (hiVal[1]-hiVal[2])/(hiBar[2]-hiBar[1])*hiBar[2]+hiVal[2]; TL_SetEnd(TL3, date32,time32,Value32); } } */ if trnd == upTr and loVal[2] > loVal[1] then TL_SetColor(TL1,BLUE); else if trnd == dnTr and hiVal[2] < hiVal[1] then TL_SetColor(TL1,RED); else TL_SetColor(TL1,BLACK); TL_SetSize(TL1,2); TL_SetColor(TL2,RED); TL_SetColor(TL3,BLUE);