StockFetcher Forums · Filter Exchange · Musings & Misgivings: A Collection of Codes<< 1 2 >>Post Follow-up
nikoschopen
2,824 posts
msg #63586
Ignore nikoschopen
6/11/2008 7:05:31 PM

Ever since I've been here, I took not-so-copious notes on interesting codes that I thought were worth preserving. These aren't really filters in and of themselves but are more or less "hacks" (or tricks) that will simplify the filter writing process. Well, most of them came from this addlebrain by way of helping others but there are some very creative ones written by others like Cegis. I thought I take the liberty of sharing these codes with y'all at this point. After all, what good are they elsewhere?

Although no particular importance is placed on the order of appearance, I will start off with some simple codes and then gradually work my way up to the complex over the next few days.

Percent (%) over Dollars ($)This will spit out the difference in percent (%):
Fetcher[
set{HL%, high above low}
add column HL%
]

This can be also used between any two indicators (eg. "ema(20) above ema(50)")


Close-to-open gap (or just "gap")This will spit out how large the gap is for that given day:
Fetcher[add column gap]

If you prefer the amount in $ amount:
Fetcher[
set{gap_percent, Close to open gap / 100}
set{gap_amount, gap_percent * close 1 day ago}
add column gap_amount
]


This will find a hammer (hanging man) with a tail that's at least 3/4 of the daily range:
Fetcher[
set{tail, min(open, close) - low}
set{hammer, tail / day point range}
hammer above 0.66
]

Here, two columns labeled "Upper (%)" and "Lower (%)" are added to inform you how large the tail is in relation to the body (OPCL):
Fetcher[
set{Shadow, day point range / aopcl}
Shadow above 3

set{Hi, high - max(open, close)}
set{Lo, min(open, close) - low}
set{Hiratio, Hi / aopcl}
set{Loratio, Lo / aopcl}
set{Upper, mod(Hiratio,10) * 100}
set{Lower, mod(Loratio,10) * 100}

add column Upper{Upper (%)}
add column Lower{Lower (%)}
]

The following tip allows you to find stocks that have met two conditions in the past. For example, you might be looking for a hammer (condition 1) with a volume spike (condition 2) that occured within the last 5 days:
Fetcher[
set{tail, min(open, close) - low}
set{hammer, tail / day point range}
set{both, count(hammer above 0.75,1) / count(volume more than 200% above average volume(30),1)}
set{dayz, days(both equals 1,5)}
dayz above 0
add column dayz
]
You can readily see when the two conditions occured in the "dayz" column.


nikoschopen
2,824 posts
msg #63587
Ignore nikoschopen
6/11/2008 7:12:12 PM

BTW feel free to add ure own "hacks".

maxreturn
745 posts
msg #63590
Ignore maxreturn
6/11/2008 8:38:51 PM

I use a 1 year relative strength of a given stock as compared to the SPX in most of my filters:

Fetcher[
set{spx, ind(^spx,close)}
set{y, spx divided by spx 252 days ago}
set{z, close divided by close 252 days ago}
set{spxrs, z divided by y}
]



To return stocks stronger than the SPX over the last year:

Fetcher[spxrs above 1]



To return stocks weaker than SPX:

Fetcher[spxrs below 1]





nikoschopen
2,824 posts
msg #63592
Ignore nikoschopen
modified
6/11/2008 10:59:27 PM

Max, thanks for contributing. May I point out, however, one of the things that I find problematic with this filter? I feel that it tells only half the story. We're only given two price points, now (x) and then (y), without any detail on what might have happened between x and y.

Suppose the yearly ROI for S&P and XYZ are -10% and -9%, respectively. Based on these numbers alone, we're led to believe that XYZ is outpacing the general market. What we don't know is that, at one point, XYZ was down more than 30% while S&P was down 15%.

I have no easy answer for this, but could you not include the "yearly high" and the "yearly low" into the equation to get around this problem? Perhaps it could be done in the same way as the Pivot Point: (H + L + C) / 3.

Fetcher[
set{range, high 52 week high + low 52 week low}
set{pivot, range + close}
set{pp1yr, pivot / 3}
set{pp2yr, pp1yr 52 weeks ago}
set{ppratio, pp1yr / pp2yr}
set{spx, ind(^spx,ppratio)}
set{ratio, ppratio / spx}
compare to ^spx

add column ppratio{stock (x)}
add column spx{spx (y)}
add column ratio{ratio (x / y)}
]


Just my 2.

nikoschopen
2,824 posts
msg #63593
Ignore nikoschopen
6/11/2008 11:15:31 PM

MineUres
Fetcher[
set{range, high 52 week high + low 52 week low}
set{pivot, range + close}
set{pp1yr, pivot / 3}
set{pp2yr, pp1yr 52 weeks ago}
set{ppratio, pp1yr / pp2yr}
set{spx, ind(^spx,ppratio)}
set{ratio, ppratio / spx}
compare to ^spx

add column ppratio{stock (x)}
add column spx{spx (y)}
add column ratio{ratio (x / y)}
]

Fetcher[
set{spx, ind(^spx,close)}
set{y, spx divided by spx 252 days ago}
set{z, close divided by close 252 days ago}
set{spxrs, z divided by y}
compare to ^spx

add column y{stock (x)}
add column z{spx (y)}
add column spxrs{ratio (x / y)}
]


maxreturn
745 posts
msg #63603
Ignore maxreturn
6/12/2008 11:44:02 AM

Niko, you're absolutely correct. The weakness of the RS measurement, whether it's 1 year, 6mos, etc, is the volatility of the price swings during that 1 year period. Still, this does not diminish the importance of incorporating RS into your filters. My trading results took a dramatic turn for the better when I focused on buying only high rs stocks during broad market uptrends and selling low rs stocks during broad market downtrends. In summary, all of my filters include rs above 1 for buy candidates and below 1 for sell candidates. The rest of the code in my filters further isolate my ideal candidates. Then it's just a simple matter of eyeballing the charts of the remaining candidates.

nikoschopen
2,824 posts
msg #63605
Ignore nikoschopen
6/12/2008 12:14:29 PM

Howdy,

Note that it wasn't my intention to dispute the importance of utilizing RS in ure trading. I was merely alluding to its weakness that you correctly pointed out.

nikoschopen
2,824 posts
msg #63613
Ignore nikoschopen
modified
6/12/2008 7:30:57 PM

Standard deviation for the nonstandard misfitsThis will create those unsightly Bollinger Bands around any indicator of ure choice:
Fetcher[
/*Replace "My_Indicator" with other valid indicator (eg. RSI(2))*/
Set{MA20,CMA(My_Indicator,20)}
set{SD,cstddev(My_Indicator,20)}
set{SD20,2 * SD} /*2 standard deviation*/
set{BOLU,MA20 + SD20}
set{BOLD,MA20 - SD20}

add column BOLU{Upper BB}
add column MA20{Center BB}
add column BOLD{Lower BB}

draw MA20 on plot price
draw BOLU on plot price
draw BOLD on plot price
]


Did you know that Bollinger Width is the same as the Standardard Deviation? As such, the Bollinger Width can be used as a substitute for the Standard Deviation indicator:
Fetcher[
draw Bollinger width(10,1)
draw standard deviation(10,1) on plot Bollinger width(10,1)
]


Here's an imperfect representation of Linear Regression channel that can also be applied to any indicator of ure choice (yeah, this one came up before not too long ago):
Fetcher[
/*Applying 1 Standard Deviation*/
set{SD, cstddev(My_Indicator,60)}
set{SDU, My_Indicator + SD}
set{SDD, My_Indicator - SD}

draw 60 day slope of My_Indicator
draw 60 day slope of SDU on plot My_Indicator
draw 60 day slope of SDD on plot My_Indicator

do not draw SDU
do not draw SDD
]


Here, you can screen stocks with "My_Indicator" at or near any one of the three Linear Regression channels:
Fetcher[
/*1 Standard Deviation*/
set{SD,cstddev(OBV(1),60)}
set{SDU,OBV(1) + SD}
set{SDD,OBV(1) - SD}

/*Linear Regression: y = mx + b*/

/*Median Channel*/
set{mSD, 60 day slope of OBV(1)}
set{mx, 60 * mSD}
set{b2, sum(OBV(1),60)}
set{bx, mSD * 1830}
set{b1, b2 - bx}
set{b, b1 / 60}
set{y, mx + b}

/*Upper Channel*/
set{mSDU, 60 day slope of SDU}
set{my, 60 * mSDU}
set{b2a, sum(SDU,60)}
set{bx1, mSDU * 1830}
set{b1a, b2a - bx1}
set{ba, b1a / 60}
set{x, my + ba}

/*Lower Channel*/
set{mSDD, 60 day slope of SDD}
set{mz, 60 * mSDD}
set{b2b, sum(SDD,60)}
set{bx2, mSDD * 1830}
set{b1b, b2b - bx2}
set{bb, b1b / 60}
set{z, mz + bb}

/*Channels: x = Upper; y = Median; z = Lower*/
/*Use a filter phrase like "touching" or "approaching from above OR below"*/
OBV(1) touching z

add column separator
add column OBV(1)
add column separator
add column x{Upper Channel}
add column y{Median Channel}
add column z{Lower Channel}
add column separator

draw 60 day slope of OBV(1)
draw 60 day slope of SDU on plot OBV(1)
draw 60 day slope of SDD on plot OBV(1)

do not draw SDU
do not draw SDD
do not draw z
]


nikoschopen
2,824 posts
msg #63677
Ignore nikoschopen
6/14/2008 3:30:13 PM

I introduced this hack last Thanksgiving with this to say...
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 for a 20-day moving average crossover:
Fetcher[
set{up, count(price crossed above MA(20),1) * 1}
set{down, count(price crossed below MA(20),1) * -1}
set{both, up + down}
set{Xover, 1 - count(both equals 0,1)}
Xover above 0
add column both{Buy (1) / Sell (-1)}
]

And once you run this filter, you will notice in the fifth column either a "1", indicating a bullish crossover, or "-1", indicating a bearish crossover.


tomm1111
198 posts
msg #67019
Ignore tomm1111
modified
9/6/2008 9:28:37 PM

post deleted by tomm1111 due to posted filter inaccuracies

StockFetcher Forums · Filter Exchange · Musings & Misgivings: A Collection of Codes<< 1 2 >>Post Follow-up

*** Disclaimer *** StockFetcher.com 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. StockFetcher.com does not recommend particular securities. StockFetcher.com, 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 2016 - 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