I've got a question to drawing vertical lines. Basically I have three variables.
1. finseries containing data on some (financial) time series
2. peak - 1 if a given date is a peak, 0 otherwise
3. trough - 1 if a given date is a trough, 0 otherwise
I'd like to draw the time series and mark the peaks and troughs with vertical lines (in different colors would be nice).
My sample starts in 1960Q1 and goes until 2014Q3.
The problem is the following. Drawing lines itself is not a problem, but I'm not able to use the "correct" place. If I use the number of the observation EViews seems to try to convert it to the year and prints it there and if I try to use for example 70,5 (1970Q2) the line is not drawn at all.
Here's my code (including the calculation of peaks and troughs):
Code: Select all
!length = @obsrange
series finseries = credit_cycle
series peak = 0
series trough = 0
graph gr1 finseries
!tp = 0 ' tp indicates whether the last turning point was a peak (1) or a trough (-1)
gr1.line("a")
for !i = 3 to !length-3 step 1
if !tp <> 1 and (finseries(!i) - finseries(!i-2) > 0) and (finseries(!i) - finseries(!i-1) > 0) and (finseries(!i+2) - finseries(!i) < 0) and (finseries(!i+1) - finseries(!i) < 0) then
peak(!i) = 1
!tp = 1
gr1.draw(line, bottom) !i
endif
if !tp <> -1 and (finseries(!i) - finseries(!i-2) < 0) and (finseries(!i) - finseries(!i-1) < 0) and (finseries(!i+2) - finseries(!i) > 0) and (finseries(!i+1) - finseries(!i) > 0) then
trough(!i) = 1
!tp = -1
gr1.draw(line, bottom) !i
endif
next
1. draw the lines at the correct date and
2. draw the lines not just at one year itself, but also for specific quarters.
Thanks in advance!
Best,
Thomas
