StockFetcher Forums · General Discussion · Need to insert language into filter about broader market indices<< >>Post Follow-up
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.

76 posts
msg #88204
Ignore Venice
2/12/2010 12:58:52 PM


show stocks where comparative relative strength(^SPX,15) is below 30
and compare with ^SPX

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.

4,599 posts
msg #88217
Ignore Kevin_in_GA
2/12/2010 2:32:36 PM

Something like this?

set{spx_close, ind(^SPX,close)}
set{spx_ma, cma(spx_close, 200)}

spx_close above spx_ma


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

2,817 posts
msg #88220
Ignore chetron
2/12/2010 3:06:11 PM




set{Vspx, ind(^SPX, close)}

set{vSD10,2 * vSD}
set{vBOLU,vMA10 + vSD10}
set{vBOLD,vMA10 - vSD10}


set{v1,Vspx 1 day ago}
set{vud,Vspx - v1}
set{vud1,count(vud above -0,1)}
set{vudf,vud * vud1}

set{vdd,v1 - Vspx}
set{vdd1,count(vdd above -0,1)}
set{vddf,vdd * vdd1}

set{myrsi1,vudema / vddema}
set{myrsi2,1 + myrsi1}
set{myrsi3,1 / myrsi2}
set{myrsi4,myrsi3 * 100}
set{SpxRSI,100 - myrsi4}

draw Vspx
draw vbold on plot Vspx
draw vbolu on plot Vspx
draw vma10 on plot Vspx

SpxRSI below 30
close above .1
volume above 1000000


StockFetcher Forums · General Discussion · Need to insert language into filter about broader market indices<< >>Post Follow-up

*** Disclaimer *** does not endorse or suggest any of the securities which are returned in any of the searches or filters. They are provided purely for informational and research purposes. does not recommend particular securities., Vestyl Software, L.L.C. and involved content providers shall not be liable for any errors or delays in the content, or for any actions taken based on the content.

Copyright 2018 - Vestyl Software L.L.C.Terms of Service | License | Questions or comments? Contact Us
EOD Data sources: DDFPlus & CSI Data Quotes delayed during active market hours. Delay times are at least 15 mins for NASDAQ, 20 mins for NYSE and Amex. Delayed intraday data provided by DDFPlus