StockFetcher Forums · General Discussion · What Have You Learned About Filter Writing?<< 1 2 >>Post Follow-up
TheRumpledOne
6,498 posts
msg #161598
Ignore TheRumpledOne
3/7/2025 9:25:25 AM

Use this thread to share what you have learned about filter writing.



TheRumpledOne
6,498 posts
msg #161601
Ignore TheRumpledOne
3/7/2025 9:36:52 AM

I learned something new from StockFetcher Support...

I had to place my plots BEFORE the SELECTION CRITERIA to get the plot on the chart.

Submit
Fetcher[

/* FOR EDUCATIONAL PURPOSES ONLY */

/* price crossed above 2 day lowest open/close */

set{ Bot1, min(close 1 day ago, open 1 day ago) }
set{ Bot2, min(close 2 days ago, open 2 days ago) }
set{ Bot, min(Bot2, Bot1)}
set{ CAB, count(close above Bot,1) }
and add column CAB

/* Over the last 20 days, count number of days close above open */

set{CAO20, count(close > open , 20)}
add column CAO20

/* Over the last 20 days, count number of days close above previous close*/

set{CAPC, count(close > close 1 day ago, 20)}
add column CAPC


/* Over the last 20 days, count number of days high above previous close*/

set{HAPC, count(high > close 1 day ago, 20)}
add column HAPC

/* high minus previous close*/

set{HiPC, high - close }
add column HiPC

/* VolB - number of days volume below 1,000,000 */
set{VolB, count(volume below 1000000,100)}


and add column separator
add column industry
add column sector
and add column separator
add column sector

/* PLOTS */
draw low 20 day high
draw high 20 day low
draw Bot on plot close

/* selection criteria */

close is between 0.90 and 2
close above Bot

/* Only show stocks that never had volume less than 1,000,000 shares per day */
VolB below 1

/* sort criteria */
SORT COLUMN 5 DESCENDING


]



styliten
312 posts
msg #161624
Ignore styliten
modified
3/9/2025 3:49:18 PM

@ TheRumpledOne

Modified:

Fetcher[dow 30

chart-time is 4 months

set{a102, cema(close 2 day low multiply by 0.500, 1) add to cema(open 2 day low multiply by 0.500, 1)}
set{a103, cema(close 3 day low multiply by 0.500, 1) add to cema(open 3 day low multiply by 0.500, 1)}
set{a104, cema(close 4 day low multiply by 0.500, 1) add to cema(open 4 day low multiply by 0.500, 1)}
set{a105, cema(close 5 day low multiply by 0.500, 1) add to cema(open 5 day low multiply by 0.500, 1)}
set{a106, cema(close 6 day low multiply by 0.500, 1) add to cema(open 6 day low multiply by 0.500, 1)}
set{a107, cema(close 7 day low multiply by 0.500, 1) add to cema(open 7 day low multiply by 0.500, 1)}
set{a108, cema(close 8 day low multiply by 0.500, 1) add to cema(open 8 day low multiply by 0.500, 1)}
set{a109, cema(close 9 day low multiply by 0.500, 1) add to cema(open 9 day low multiply by 0.500, 1)}
set{a110, cema(close 10 day low multiply by 0.500, 1) add to cema(open 10 day low multiply by 0.500, 1)}

set{a202, cema(close 2 day high multiply by 0.500, 1) add to cema(open 2 day high multiply by 0.500, 1)}
set{a203, cema(close 3 day high multiply by 0.500, 1) add to cema(open 3 day high multiply by 0.500, 1)}
set{a204, cema(close 4 day high multiply by 0.500, 1) add to cema(open 4 day high multiply by 0.500, 1)}
set{a205, cema(close 5 day high multiply by 0.500, 1) add to cema(open 5 day high multiply by 0.500, 1)}
set{a206, cema(close 6 day high multiply by 0.500, 1) add to cema(open 6 day high multiply by 0.500, 1)}
set{a207, cema(close 7 day high multiply by 0.500, 1) add to cema(open 7 day high multiply by 0.500, 1)}
set{a208, cema(close 8 day high multiply by 0.500, 1) add to cema(open 8 day high multiply by 0.500, 1)}
set{a209, cema(close 9 day high multiply by 0.500, 1) add to cema(open 9 day high multiply by 0.500, 1)}
set{a210, cema(close 10 day high multiply by 0.500, 1) add to cema(open 10 day high multiply by 0.500, 1)}

and draw clri(a102, 20) on plot price
and draw clri(a103, 20) on plot price
and draw clri(a104, 20) on plot price
and draw clri(a105, 20) on plot price
and draw clri(a106, 20) on plot price
and draw clri(a107, 20) on plot price
and draw clri(a108, 20) on plot price
and draw clri(a109, 20) on plot price
and draw clri(a110, 20) on plot price

and draw clri(a202, 21) on plot price
and draw clri(a203, 21) on plot price
and draw clri(a204, 21) on plot price
and draw clri(a205, 21) on plot price
and draw clri(a206, 21) on plot price
and draw clri(a207, 21) on plot price
and draw clri(a208, 21) on plot price
and draw clri(a209, 21) on plot price
and draw clri(a210, 21) on plot price
]



Alternative:

Fetcher[dow 30

chart-time is 4 months

set{a102, cema(close 2 day low multiply by 0.500, 1) add to cema(open 10 day low multiply by 0.500, 1)}
set{a103, cema(close 2 day low multiply by 0.450, 1) add to cema(open 10 day low multiply by 0.550, 1)}
set{a104, cema(close 2 day low multiply by 0.550, 1) add to cema(open 10 day low multiply by 0.450, 1)}
set{a105, cema(close 2 day low multiply by 0.400, 1) add to cema(open 10 day low multiply by 0.600, 1)}
set{a106, cema(close 2 day low multiply by 0.600, 1) add to cema(open 10 day low multiply by 0.400, 1)}
set{a107, cema(close 2 day low multiply by 0.350, 1) add to cema(open 10 day low multiply by 0.650, 1)}
set{a108, cema(close 2 day low multiply by 0.650, 1) add to cema(open 10 day low multiply by 0.350, 1)}
set{a109, cema(close 2 day low multiply by 0.300, 1) add to cema(open 10 day low multiply by 0.700, 1)}
set{a110, cema(close 2 day low multiply by 0.700, 1) add to cema(open 10 day low multiply by 0.300, 1)}
set{a111, cema(close 2 day low multiply by 0.250, 1) add to cema(open 10 day low multiply by 0.750, 1)}
set{a112, cema(close 2 day low multiply by 0.750, 1) add to cema(open 10 day low multiply by 0.250, 1)}
set{a113, cema(close 2 day low multiply by 0.200, 1) add to cema(open 10 day low multiply by 0.800, 1)}
set{a114, cema(close 2 day low multiply by 0.800, 1) add to cema(open 10 day low multiply by 0.200, 1)}

set{a202, cema(close 2 day high multiply by 0.500, 1) add to cema(open 10 day high multiply by 0.500, 1)}
set{a203, cema(close 2 day high multiply by 0.450, 1) add to cema(open 10 day high multiply by 0.550, 1)}
set{a204, cema(close 2 day high multiply by 0.550, 1) add to cema(open 10 day high multiply by 0.450, 1)}
set{a205, cema(close 2 day high multiply by 0.400, 1) add to cema(open 10 day high multiply by 0.600, 1)}
set{a206, cema(close 2 day high multiply by 0.600, 1) add to cema(open 10 day high multiply by 0.400, 1)}
set{a207, cema(close 2 day high multiply by 0.350, 1) add to cema(open 10 day high multiply by 0.650, 1)}
set{a208, cema(close 2 day high multiply by 0.650, 1) add to cema(open 10 day high multiply by 0.350, 1)}
set{a209, cema(close 2 day high multiply by 0.300, 1) add to cema(open 10 day high multiply by 0.700, 1)}
set{a210, cema(close 2 day high multiply by 0.700, 1) add to cema(open 10 day high multiply by 0.300, 1)}
set{a211, cema(close 2 day high multiply by 0.250, 1) add to cema(open 10 day high multiply by 0.750, 1)}
set{a212, cema(close 2 day high multiply by 0.750, 1) add to cema(open 10 day high multiply by 0.250, 1)}
set{a213, cema(close 2 day high multiply by 0.200, 1) add to cema(open 10 day high multiply by 0.800, 1)}
set{a214, cema(close 2 day high multiply by 0.800, 1) add to cema(open 10 day high multiply by 0.200, 1)}

and draw clri(a102, 20) on plot price
and draw clri(a103, 20) on plot price
and draw clri(a104, 20) on plot price
and draw clri(a105, 20) on plot price
and draw clri(a106, 20) on plot price
and draw clri(a107, 20) on plot price
and draw clri(a108, 20) on plot price
and draw clri(a109, 20) on plot price
and draw clri(a110, 20) on plot price
and draw clri(a111, 20) on plot price
and draw clri(a112, 20) on plot price
and draw clri(a113, 20) on plot price
and draw clri(a114, 20) on plot price

and draw clri(a202, 21) on plot price
and draw clri(a203, 21) on plot price
and draw clri(a204, 21) on plot price
and draw clri(a205, 21) on plot price
and draw clri(a206, 21) on plot price
and draw clri(a207, 21) on plot price
and draw clri(a208, 21) on plot price
and draw clri(a209, 21) on plot price
and draw clri(a210, 21) on plot price
and draw clri(a211, 21) on plot price
and draw clri(a212, 21) on plot price
and draw clri(a213, 21) on plot price
and draw clri(a214, 21) on plot price
]



TheRumpledOne
6,498 posts
msg #161625
Ignore TheRumpledOne
3/9/2025 4:52:18 PM

What did you learn?

styliten
312 posts
msg #161638
Ignore styliten
3/9/2025 7:38:23 PM

@ TheRumpledOne

Luck is more (important than anything and everything else in life).

TheRumpledOne
6,498 posts
msg #161640
Ignore TheRumpledOne
3/10/2025 1:03:32 AM

LUCK: WHEN PREPARATION MEETS OPPORTUNITY.



xarlor
592 posts
msg #161643
Ignore xarlor
3/10/2025 11:47:48 AM

You can limit your universe to just the top performing sector(s):

Fetcher[
Show stocks in top sectors(2,daily)
add column sector
]



You can change any plot into a histogram (or line, or dot).

Fetcher[
symlist(spy,qqq,dia)
set{MACross,ma(50) - ma(20)}
draw MACross
plottype{MACross,zerobar}
]



There is an actual, valid use for tangent, sine, and cosine sometimes.

Fetcher[
/* Trade at the opening of the day AFTER a signal change. e.g. If trend goes from SHORT to LONG, do not go LONG on the day of signal. Instead, go LONG the next day at the open.
https://www.youtube.com/watch?v=7252FJ9ahvc */
symlist(SPY,QQQ,DIA)

set{x, 4 day slope of close}
/*find radians*/
set{y, atan(x)}
/*convert to degrees*/
set{z, y * 57.2957}
add column z
draw z

draw 4 day slope of close
do not draw z

set{LONG,count(z > 0,1)}
set{SHORT,count(z <= -22,1)}
LONG > -1
SHORT > -1
]



TheRumpledOne
6,498 posts
msg #161646
Ignore TheRumpledOne
modified
3/10/2025 1:30:23 PM

Submit
Fetcher[

/* Trade at the opening of the day AFTER a signal change. e.g. If trend goes from SHORT to LONG, do not go LONG on the day of signal. Instead, go LONG the next day at the open.
https://www.youtube.com/watch?v=7252FJ9ahvc */
symlist(SPY,QQQ,DIA)

set{x, 4 day slope of close}
/*find radians*/
set{y, atan(x)}
/*convert to degrees*/
set{z, y * 57.2957}

draw 4 day slope of close

set{CCb,days(z is above 0,100)}
set{CCa,days(z is below 0,100)}
set{CxC, CCa - CCb}
add column CxC {Degree}

set{SSb,days(x is above 0,100)}
set{SSa,days(x is below 0,100)}
set{SxS, SSa - SSb}

add column SxS {SLOPE}

draw SxS
plottype{SxS ,zerobar}
draw SxS line at 1
draw SxS line at -1

]



Not sure why you have to convert to degrees? Just compare the slope.

This displays how many days since the slope crossed above/below 0. SHORT when -2 and BUY when +2, if I understand correctly.



styliten
312 posts
msg #161648
Ignore styliten
modified
3/10/2025 4:58:00 PM

@ TheRumpledOne

Part 2:

A custom DMA would be very helpful as that allows instant reality check against 'history/historic trajectories'. But SF.com is unlikely to implement CDMA any time soon. Sigh!

Whould be eager to use:

draw CDMA(LRI(20), -15) on plot price
draw CDMA(LRI(20), -10) on plot price
draw CDMA(LRI(20), -5) on plot price

(i.e, shifting LRI(20) curves 15/10/5 days, respectively, back into history on the price plot)

vs

draw LRI(20) on plot price

lorypanna
32 posts
msg #161650
Ignore lorypanna
3/10/2025 7:20:55 PM

My contribution, FWIW.

Notes:
- Based on post in 'Filter Exchange' forum: Is it possible to get WTD, MTD,QTD,YTD in Stockfetcher?
- xTD: the filter uses the Open at the beginning of the period 'x' and the Close at the end of the period 'x' (the current / last Close unless 'offset' is greater than zero); maybe this is not the 'correct' way to calculate xTD
- Don't think QTD can be calculated, unless there's some ('hidden') way to identify 'start of Quarter' 's Open
- For WTD I didn't use date(MONDAY, open) because it returns the value of the 'nearest' previous trading-Monday. Example: for week starting on Tuesday 2025-01-21 (Monday 2025-01-20 was President Day), date(MONDAY, open) function returns the open value of Monday 2025-01-13

I'm interested to understand what is the 'correct' or 'generally used / accepted' way to calculate xTD.

Cheers from italy.

Fetcher[
/*
NOTES:
1. xTD is calculated as (xEnd_Close - xStart_Open) / xStart_Open
2. xTDP100 = (xTD * 100.0)
*/

offset is 0 days

apply to symlist(SPY, QQQ, IWM, SMH, XBI, DIA, XLF, TLT, XLE, XLK)

/* WTD based on 'weekly open' */
set{MyWCloseW, weekly close}
set{MyWOpenW, weekly open}
set{MyWTDWAbs, MyWCloseW minus MyWOpenW}
set{MyWTDW, MyWTDWAbs divided by MyWOpenW}
set{MyWTDWP100, MyWTDW multiplied by 100.0}

add column separator
add column MyWTDWP100 {WTD%}


/* MTD based on MonthOpen = date(MONTHSTART, open) */
set{MyMOpen, date(MONTHSTART, open)}
set{MyMTDAbs, close minus MyMOpen}
set{MyMTD, MyMTDAbs divided by MyMOpen}
set{MyMTDP100, MyMTD multiplied by 100.0}

add column separator
add column MyMTDP100 {MTD%}


/* YTD based on YearOpen = date(YEARSTART, open) */
set{MyYOpen, date(YEARSTART, open)}
set{MyYTDAbs, close minus MyYOpen}
set{MyYTD, MyYTDAbs divided by MyYOpen}
set{MyYTDP100, MyYTD multiplied by 100.0}

add column separator
add column MyYTDP100 {YTD%}


/* Monthly and Year open prices are plotted on price chart */
draw MyMOpen on plot price
draw MyYOpen on plot price
]




StockFetcher Forums · General Discussion · What Have You Learned About Filter Writing?<< 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 2022 - 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


This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.