bullishjim 3 posts msg #88191 - Ignore bullishjim |
2/12/2010 11:22:25 AM
How's that for a thread title?
Here's what I am getting at: I want to add language to some of my filters which will make them only pull stocks when something is true about a particular market index. In real life, I might not buy stocks from a particular filter (ie "pullback to a rising 50 day moving avg") unless the market as a whole is in a rising trend. Without being able to model that fact into my Stockfetcher filters I am unable to backtest the actual performance. Is there an easy solution to this question? I've looked around quite a bit but haven't found language that works.
For example, her'es a simple filter I use to pull stocks that have pulled back to a rising 50 day moving average:
show stocks where close is between 10 and 100
and average volume(60) > 500000
and close > ma(50)
and rsi(7) < 50
and close is less than 2% > ma(50)
and ma(50) is more than 5% > ma(50) 30 days ago
and ma(50) is more than 10% > ma(50) 60 days ago
and ma(50) is more than 15% > ma(50) 90 days ago
Is there a simple line or two I can add that adds the requirment, for instance, that the rsi(14) of ^SPX must be below 30? I feel like the answer should be easy but I can't seem to make anything I've tried work.
|
Venice 82 posts msg #88204 - Ignore Venice modified |
2/12/2010 12:58:52 PM
Maybe?
|
bullishjim 3 posts msg #88207 - Ignore bullishjim |
2/12/2010 1:06:19 PM
Thanks for answering, Venice. Doesn't the language you provided require that stocks be outperforming the SPX for the past 45 days in order to be selected by the filter? What I'm trying to do is basically have the filter turn off entirely if the overall market is not trending the way I want it to. For instance, I might not want to buy stocks when the slow stochastic for the SPX as a whole is above a certain level, say 80.
In practice it's easy enough to simply not use a filter when the market is overbought (in my opinion). In order to backest a filter accurately, however, i need to be able to have Stockfetcher also not buy ANY stocks when that condition is true.
It seems like a simple question but I am totally stumped.
|
Kevin_in_GA 4,599 posts msg #88217 - Ignore Kevin_in_GA |
2/12/2010 2:32:36 PM
Something like this?
This piece of code, when incorporated into your screening filter, will only return stocks if the S&P is above its MA(200). As you can see, the basic structure can be modified to incorporate other criteria as well
|
chetron 2,817 posts msg #88220 - Ignore chetron modified |
2/12/2010 3:06:11 PM
MY SPX LAZY VERSION, YOU CAN CLEAN IT UP.....
|