nikoschopen 2,824 posts msg #56947 - Ignore nikoschopen modified |
11/22/2007 7:49:20 PM
As a way to commemorate Thanksgiving, I would like to give back to the SF community something relatively small for many great things that I learned over the years.
As you may know, the logical disjunction "OR" isn't natively supported in SF language. However, we're able to get by this limitation using the method TRO introduced. I, on the other hand, wish to push this one step further by using it in conjunction with the "If-Then" conditional.
I have noticed that many of you write two filters of the same condition. For example, one filter is written for stocks that crosses above its 20-day moving average and another filter is written for stocks that crosses below its 20-day moving average. Why not just write one filter that would allow both conditions to be met but also informs you which is which. Here's how you write it.
code
set{condition 1, count(indicator 1, indicator 2,1) * 1}
set{condition 2, count(indicator 1, indicator 2,1) * -1}
set{both, condition 1 + condition 2}
set{result, 1 - count(both equals 0,1)}
result above 0
add column both{result}
Hence, taking the above example of 20-day moving average crossover:
And once you run the filter, you would see in the fifth column either a "1", indicating a bullish crossover, or "-1", indicating a bearish crossover. Here's a screenie of what you can expect after you run this filter:
|