Hello,
I am trying to compute the Relative Strength Indicator for treasury rates with 250 observations. I wrote the following code:
set DTR = Treasury - Treasury{1}
set RSI = 0.0
do j = 1,250
com [real] Sum1 = 0
com [real] Sum2 = 0
com avg1 = 0
com avg2 = 0
do i = 1,14
if DTR(250-i+2-j) > 0 {
com Sum1 = Sum1 + DTR(250-i+2-j)
com avg1 = avg1 + 1
}
else if DTR(250-i+1-j) < 0 {
com Sum2 = Sum2 + DTR(250-i+2-j)
com avg2 = avg2 + 1
}
end if
end do i
com RSI(250-j+1) = ((Sum1/avg1)/(Sum2/avg2))
end do j
Normal Completion. Halt at DO
graph
# RSI
## SX11. Identifier RSI is Not Recognizable. Incorrect Option Field or Parameter Order?
>>>># RSI<<<<
the inner loop (with counter i) seperates 14 days into increase and decrease in treasury and adds up all the increases (sum1) and all the decreases (sum2)
RSI = average increase/average decrease. The outer loop moves the the 14 day window by one data point.
I am getting Normal Completion error and RSI is coming up as unrecognizable eventhough I declared it as a series above.
In addition I am using version 5.
Could you please give me some direction of what I am doing wrong.
Coding Error
Re: Coding Error
END IF is rarely necessary in RATS. If an IF or ELSE is inside a DO loop or procedure or function, you just need the braces for the controlled statements. If you delete the line in red, it should work fine.John_Val wrote:Hello,
I am trying to compute the Relative Strength Indicator for treasury rates with 250 observations. I wrote the following code:
set DTR = Treasury - Treasury{1}
set RSI = 0.0
do j = 1,250
com [real] Sum1 = 0
com [real] Sum2 = 0
com avg1 = 0
com avg2 = 0
do i = 1,14
if DTR(250-i+2-j) > 0 {
com Sum1 = Sum1 + DTR(250-i+2-j)
com avg1 = avg1 + 1
}
else if DTR(250-i+1-j) < 0 {
com Sum2 = Sum2 + DTR(250-i+2-j)
com avg2 = avg2 + 1
}
end if
end do i
com RSI(250-j+1) = ((Sum1/avg1)/(Sum2/avg2))
end do j
graph
# RSI