StockFetcher Forums · General Discussion · Backtesting<< 1 2 >>Post Follow-up
2,824 posts
msg #33026
Ignore nikoschopen
8/27/2004 4:44:42 PM

Thx made that very clear for me to understand...I will do as you advise

235 posts
msg #33038
Ignore cegis
8/28/2004 1:55:45 PM

Rob, Thanks for doing the "leg work" of an explanation. (I was out of touch for a few days, and just read the posts...) And, the description is correct.

The key point here is that the "offset" phrase CHANGES what is considered "today". In this case, the filter ALWAYS runs as if "today" is 3/31/04. The "days ago" phrase counts back from the "today" date. I assumed 65 trading days (since I didn't count) from 1/1 to 3/31. You should check to see what market holidays were in that time period, and adjust accordingly.

And, yes, SF doesn't care a hoot as to what the values of the set{} variables become - unless you add selections to limit results based on them. So, "rtn" can be any value, and show in the results list. It will show the percentage return over the 65 trading days.

This technique can be used for any date range: Just use an offset of the ending date you care to look at, and a days ago that is the number of trading days in the period.



117 posts
msg #33087
Ignore rrochon
9/1/2004 2:01:09 PM


Is this filter for finding the performance of a single stock or for a filter? My original request was to backtest the performance of a filter (say Muddy's) for a period when the general market was trending down. (from 6/30 to 8/13).

Would your filter just be added to Muddy's filter?

Wouldn't it be nice if the offset could be a "range" instead of a "number" of days?


235 posts
msg #33088
Ignore cegis
9/1/2004 4:15:58 PM


This technique is used to test the performance of a filter, on a daily basis. To apply this technique to ANY filter, follow these steps:

1) Copy the original filter to another, perhaps adding the text "backtest as of" to it's description. Leave the original filter alone henceforth.

2) Add the "offset mm/dd/yy" that you want to use (substituting your ending date).

3) FOR EACH INDICATOR in the filter, add "n days ago", using the number of days in your period.

4) Add calculations (e.g., for return) for the date range. For example, you might add {gain,close - close 10 days ago} to get $ gain in the 10 day period ending with your offset date.

5) Add "add column xxx" for each calculation you wish to see in the results table.

6) Run the backtest filter, and enjoy.

I have requested that SF implement a variable period to be used in the Performance column that it shows when using the "offset" phrase, as well as other performance calculation requests. Unfortunately, the SF people tend to put a very low priority on requests that have a workaround, even if they are cumbersome. (This is not really unfortunate, because they work on requests that have no other method to get a result - like syntax checking [Thanks again, SF!].)

To get back to your original request, I think what you're looking for would require a slight modification to the above steps. I think you're looking for the performance for all of the selected stocks within the date range. That being the case, in order to use this technique, you'll need to determine the period for which you want the performance for each day's matches. This can be a few different periods. Then, you'll need to run the filter manually changing the offset date. The successive results will show you the performance for your periods, which you'll have to aggregate.

For example, if you want to see the 3, 5, and 10 day return for the simple filter "RSI(2) < 1" for your 6/30 to 8/13 date range, start with this:

set{gain3,close 7 days ago - close 10 days ago}
set{gain5,close 5 days ago - close 10 days ago}
set{gain10,close - close 10 days ago}
set{pct3,gain3 / close 10 days ago}
set{pct5,gain5 / close 10 days ago}
set{pct10,gain10 / close 10 days ago}

rsi(2) 10 days ago is less than 1

add column gain3
add column pct3
add column gain5
add column pct5
add column gain10
add column pct10

offset 07/15/2004

Where 7/15 is 10 trading days after 6/30 (just skipping 7/4; when was ronnie's funeral?). The combination of "offset 7/15/04" and "rsi(2) 10 days ago" will result in the stocks that had RSI(2) < 1 on 6/30. When you run the filter, the columns added will show you how well the selections did in the following 3, 5, and 10 days.

You then need to change the offset date for successive trading days, until it hits 8/27 (inclusive), capturing all of the results, and aggregating them yourself.

Did this clarify things?


12 posts
msg #132824
Ignore tugga82
11/27/2016 11:28:31 AM

Hi Cegis,
I've been going through your posts and tried to backtest this old filter around RSI<0.05 and there is a mistake I am making. It will be great if you can help fix this. All I want to do is run the filter 5 days ago and essentially buy the stock at the next day's close i.e. at day 4 and see what happens if I sell it at the next day close, the following day close (2 day hold), 3 day hold and 4 day hold and so on. Below is an attempt. Can you please help correct some of the syntax? Thanks a ton in advance for your help.

set{gain1, close 3 days ago - close 4 days ago}
set{gain2, close 2 days ago - close 4 days ago}
set{gain3, close 1 day ago - close 4 days ago}
set{gain4, close - close 4 days ago}
set{cl, close 4 days ago}

set{pct1,gain1*100 / cl}
set{pct2,gain2*100 / cl}
set{pct3,gain3*100 / cl}
set{pct4,gain4*100 / cl}

close 5 days ago is below 10
RSI(2) 5 days ago is below .05
volume 5 days ago has been increasing for the last 2 days
draw RSI(2)
draw Bollinger Band(20)
market is not ETF
add column gain1
add column pct1
add column gain2
add column pct2
add column gain3
add column pct3
add column gain4
add column pct4

StockFetcher Forums · General Discussion · Backtesting<< 1 2 >>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 2021 - 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.