Page 1 of 1
Creating shading series
Posted: Tue Feb 08, 2011 5:03 pm
by John_Val
I have 2 series hist and RSI from time 10 to 257. I want to create a dummy variable shade that is equal to 1 if hist(t)<0 and hist(t-1)>0 and RSI(t)>=60
It is also equal to 1 if hist(t)<0 and hist(t-1)>0 and RSI(t-1) >=60. When I run the program nothing gets recorded. I presume I did not set up correctly the if-block ****
Could you correct what I wrote.
do t=10,257
if hist(t)<0 {
if hist(t-1)>0 {
if RSI(t) >=60 {
com shade(t)=1.0
}
****** if RSI(t-1) >=60 {
com shade(t) = 1.0
}
}
}
else {
com shade(t)=0
}
end do t
Re: General Question
Posted: Tue Feb 08, 2011 8:02 pm
by TomDoan
First, you appear to be commenting out the first line of the second IF clause for RSI, but not the rest. When you want to disable some lines, it's a good idea to use the Edit-Comment Out Lines operation; then you can later do Edit-Uncomment Lines to enable them again.
It's usually better to create a dummy like this using SET with relational operators. In this case, it would be
set shade 10 257 = hist<0.and.hist{1}>0.and.(rsi>=60.or.rst{1}>=60)
Re: General Question
Posted: Wed Feb 09, 2011 11:59 am
by John_Val
hi,
I placed ***** to show where I think the the problem is. In the program I don't have any *****.
For example, in the below program I want comput1 to occur if the first two if statements are true, while compute2 occurs if the first and third if statements are true.
Did I set up the code correctly. Does Winrats know that for the comput2 to be done the first and third if statments have to be true.
I know I can set it up much easier using set command in order to create the dummy variable, but I want to better understand the programming capabilities in the case more complex calculations come up.
if { ...
if { ...
comput1 ....
}
if { ....
comput2...
}
}
Re: General Question
Posted: Thu Feb 10, 2011 8:16 am
by TomDoan
With proper indenting, your loop looks like this:
Code: Select all
do t=10,257
if hist(t)<0 {
if hist(t-1)>0 {
if RSI(t) >=60 {
com shade(t)=1.0
}
if RSI(t-1) >=60 {
com shade(t) = 1.0
}
}
}
else {
com shade(t)=0
}
end do t
It looks as if you'll get the 1's where you want them, but not the 0's, since the shade(t)=0 will only get executed if hist(t)>0. There's no way to write that logic to get the 1's and 0's without a single long clause (as done in my SET instruction). However, the way to handle that is to set everything to 0 first, then set the 1's. That is:
Code: Select all
do t=10,257
com shade(t)=0
if hist(t)<0 {
if hist(t-1)>0 {
if RSI(t) >=60 {
com shade(t)=1.0
}
if RSI(t-1) >=60 {
com shade(t) = 1.0
}
}
}
end do it