StockFetcher Forums · General Discussion · Fibonacci screener<< 1 2 3 >>Post Follow-up
nibor100
1,031 posts
msg #149726
Ignore nibor100
12/1/2019 2:20:19 PM

@xarlor,

I'm finally posting my attempt at a backtest filter for your Fibonacci screener, as I can't seem to make any more headway against SF complexity issues:

a. Before we get to that filter, here is my One day backtest filter, for your full Fibonacci screener, which shows which Fib Touch occurred the day before and how much the gain is, if one held from Open to Close the following day.

for example your Fibonacci Screener returns SAND for Tuesday Nov 26 and the One Day Backtest Filter returns SAND on Wed Nov 27.

Fetcher[
average volume(30) 1 day ago > 1234567
chart-time is 1 month
/* Set the Fib values at 23.6%, 38.2%, 50%, and 61.8%*/

set{Hi,high 1-year high 1 day ago}
set{Lo,low 1-year low 1 day ago}
set{Vdiff,Hi - Lo}
set{x1,Vdiff * .236}
set{x2,Vdiff * .382}
set{x3,Vdiff * .50}
set{x4,Vdiff * .618}
set{x5,Vdiff * .786}
set{Fib1, Hi - x1} add column fib1
set{Fib2, Hi - x2}
set{Fib3, Hi - x3}
set{Fib4, Hi - x4}
set{Fib5, Hi - x5}

/* Check if price touched any of the Fib lines 1 day ago while that candle's body is above the Fib line */

set{touch1a,count(low 2 days ago <= Fib1,1)}
set{touch1b,count(close 2 days ago > fib1,1)}
set{touch1c,count(open 2 days ago > fib1,1)}
set{touch1d,touch1a * touch1b}
set{Touch1,touch1c * touch1d}

set{touch2a,count(low 2 days ago <= Fib2,1)}
set{touch2b,count(close 2 days ago > fib2,1)}
set{touch2c,count(open 2 days ago > fib2,1)}
set{touch2d,touch2a * touch2b}
set{Touch2,touch2c * touch2d}

set{touch3a,count(low 2 days ago <= Fib3,1)}
set{touch3b,count(close 2 days ago > fib3,1)}
set{touch3c,count(open 2 days ago > fib3,1)}
set{touch3d,touch3a * touch3b}
set{Touch3,touch3c * touch3d}

set{touch4a,count(low 2 days ago <= Fib4,1)}
set{touch4b,count(close 2 days ago > fib4,1)}
set{touch4c,count(open 2 days ago > fib4,1)}
set{touch4d,touch4a * touch4b}
set{Touch4,touch4c * touch4d}

set{touch5a,count(low 2 days ago <= Fib5,1)}
set{touch5b,count(close 2 days ago > fib5,1)}
set{touch5c,count(open 2 days ago > fib5,1)}
set{touch5d,touch5a * touch5b}
set{Touch5,touch5c * touch5d}

set{z1,Touch1 + Touch2}
set{z2,z1 + Touch3}
set{z3,z2 + Touch4}
set{Trigger,z3 + Touch5}
Trigger > 0

/* The bounce: Green day following a 3-day declining close */
close 1 day ago > high 2 days ago
close 2 days ago < close 3 days ago for last 3 days

set{var2, opcl / open}
set{var3, var2 * 100} add column var3 {Todays Open-Close %GAIN}


draw price line at hi
draw price line at Fib1
draw price line at Fib2
draw price line at Fib3
draw price line at Fib4
draw price line at Fib5
draw price line at lo

do not draw Trigger
add column touch1 add column touch2 add column touch3 add column touch4
add column touch5
]



b. The following filter conducts a 1 year backtest looking for the Fibonacci Screener Touch1 events.
It returns the stocks that have had winners or losers(next close to open % change) and the total hits for the past year for each stock. You'll see I've made many changes to your original filter in order to reduce the number of nested Set statements for complexity reasons but I believe it stays fairly close to your original Fib Screener resuts.

Note: It take at least 20 seconds to run each time.

c. If you run that filter in SF 2.0 you can hover at the apex of winners and losers triangles on their respective charts and quickly see the exact value of the gain or loss.

d. It can be fairly easily modified to do backtests for the Touch2, 3, 4, and 5 scenarios and you can adjust the date offset to go past 1 year in the past.

e. When I tried to run it with both Touch 1 and Touch2 criteria activated it kept running for at least 8 hours without returning results or error messages so i believe it can't run in SF.

Any help to expand the backtest to more Touch Fib lines would be appreciated or any other comments.
Ed S.

@Cheese,
I'm moving on the Weinstein backtest now in my spare time.....

Fetcher[
set{cv1, count(average volume(30) 1 day ago > 1234567, 1)}

set{Vdiff,high 1-year high - low 1-year low}
set{x1,Vdiff * .236}
set{Fib1, high 1-year high - x1}
set{touch1b,count(close 2 days ago > fib1,1) * count(open 2 days ago > fib1,1)}
set{Touch1,touch1b * count(low 2 days ago <= Fib1,1)}
set{trg1, Touch1 }

set{cl1, count(close 1 day ago > high 2 days ago, 1)}
set{cl2, count(close 2 days ago < close 3 days ago, 1)}
set{cl3, count(close 3 days ago < close 4 days ago, 1)}
set{cl4, count(close 4 days ago < close 5 days ago, 1)}
set{Tru2, cl1*cl2 }
set{Tru3, cl3*cl4 }
set{Tru40, trg1*cv1 }
set{Tru4, tru2*tru3 }
set{Tru5, tru40*Tru4 }

set{var2, opcl / open}
set{var3, var2 * 100} /*add column var3 {Todays Short %GAIN}*/
set{var4, count( var3 is between 0 and 100, 1)}
set{var6, count( var3 is between -100 and 0, 1)}
set{Tru12, tru5*var4 }
set{var5, count(tru12 > 0 ,200)} and add column var5 {next day winners}
set{Tru13, tru5*var6 }
set{var8, count(tru13 > 0 ,200)} and add column var8 {next day losers }

set{TotalHits, var5 + var8} add column var20 {totalhits }
TotalHits > 0

set{winners, Tru12*var3 } draw winners
set{losers, Tru13*var3 } draw losers
chart-time is 252 days*/

/*date offset is 1/17/2016*/
sort column 6 descending
add column touch1
draw high 1 year high
draw Fib1 on plot price
draw low 1 year low
]







Cheese
1,374 posts
msg #149727
Ignore Cheese
12/1/2019 3:05:36 PM

Ed S nibor100 wrote:
@Cheese,
I'm moving on the Weinstein backtest now in my spare time....
=============================================================

Thank you very much for your time, Ed.
I am a basic sub so I had to make some minor editing.to your code.

Depending on the limit settings,
there were about 24 next day winners
and about 22 next day losers
out of 7,398 to 9,737 results on Nov 29, 2019


nibor100
1,031 posts
msg #149729
Ignore nibor100
12/1/2019 5:47:01 PM

@cheese,

please post your minor edited filter as I am very curious to what you did

thanks
Ed S

Cheese
1,374 posts
msg #149730
Ignore Cheese
12/1/2019 6:29:55 PM

All I try to do here, as a basic sub, is see your backtest results with Nov 29, 2019 data.

sF still shows advanced sub required when I preview my post
but my edited version did run fine on my machine.

I do like some of graftonian's expanded works with Weinstein,
but the Weinstein basic specs didn't resonate with me.

Thanks again, Ed S nibor100.

Fetcher[
/* original backtesting code by nibor100 is here: */
/* https://www.stockfetcher.com/forums/General-Discussion/Fibonacci-screener/149298/10 */

not otcbb /* edit to reduce run time */
close above 1 /* edit to reduce run time */
average volume(30) > 1000000 /* edit to reduce run time */

set{cv1, count(average volume(30) 1 day ago > 1234567, 1)}

set{Vdiff,high 1-year high - low 1-year low}
set{x1,Vdiff * .236}
set{Fib1, high 1-year high - x1}
set{touch1b,count(close 2 days ago > fib1,1) * count(open 2 days ago > fib1,1)}
set{Touch1,touch1b * count(low 2 days ago <= Fib1,1)}
set{trg1, Touch1 }

set{cl1, count(close 1 day ago > high 2 days ago, 1)}
set{cl2, count(close 2 days ago < close 3 days ago, 1)}
set{cl3, count(close 3 days ago < close 4 days ago, 1)}
set{cl4, count(close 4 days ago < close 5 days ago, 1)}
set{Tru2, cl1*cl2 }
set{Tru3, cl3*cl4 }
set{Tru40, trg1*cv1 }
set{Tru4, tru2*tru3 }
set{Tru5, tru40*Tru4 }

set{var2, opcl / open}
set{var3, var2 * 100} /*add column var3 {Todays Short %GAIN}*/
set{var4, count( var3 is between 0 and 100, 1)}
set{var6, count( var3 is between -100 and 0, 1)}
set{Tru12, tru5*var4 }
/* set{var5, count(tru12 > 0 ,200)} */ /* edit */
set{var5, count(tru12 > 0 ,100)} and add column var5 {next day winners} /* edit */
set{Tru13, tru5*var6 }
/* set{var8, count(tru13 > 0 ,200)} */ /* edit */
set{var8, count(tru13 > 0 ,100)} and add column var8 {next day losers } /* edit */



/* set{TotalHits, var5 + var8} add column var20 {totalhits } */
/* TotalHits > 0 */ /* add column TotalHits */

set{winners, Tru12*var3 } /* draw winners */ add column winners /* edit */
set{losers, Tru13*var3 } /* draw losers */ add column losers /* edit */
chart-time is 252 days*/

/*date offset is 1/17/2016*/
sort column 6 descending
add column touch1
draw high 1 year high
draw Fib1 on plot price
draw low 1 year low
]


















nibor100
1,031 posts
msg #149756
Ignore nibor100
12/2/2019 1:12:28 PM

@All,

When I posted my backtest filter yesterday I posted an earlier test version by mistake, so the 200s for var5 and var8 should be replaced by 252s in order to cover a full year of data in the backtest.

Another OOps,
Ed S.

Cheese
1,374 posts
msg #149759
Ignore Cheese
12/2/2019 1:54:50 PM

ok, thanks Ed.

nibor100
1,031 posts
msg #149760
Ignore nibor100
12/2/2019 2:08:23 PM

@cheese,

for Nov 29 my backtest filter returns 76 stocks vs your modified filter run on same date returning 40.

all 40 of your results stocks are in the group of 76.

My 76 have only 2 OTCBB exchange traded stocks,

My 76 have 29 stock with volume between 275,300 and 1,000,000

If I change your volume speed parameter to >275000 it still executes much quicker than my original, in about 6 seconds.

If I change my original var5 and var8 to just 100 days mine runs faster and returns 43 results for Nov29 vs your 40 results.

I thought your changes to make the filter faster were a good idea and I'm surprised that it mostly runs under the basic subscription when the addition of one more line makes mine un-runnable in my higher level subscription????

Thanks,
Ed S.



Cheese
1,374 posts
msg #149761
Ignore Cheese
12/2/2019 2:30:50 PM

Thank you very much Ed.
On my machine, sometimes sF requires advanced sub, other times not.
I wonder if that may be due to the sF systems load at the time.
There were times when I was tempted to pay for an advanced sub.
But there is a benefit to be a basic sub. It forces me to look for the core of the filter.
I will have to take a closer look later.

Cheese
1,374 posts
msg #149765
Ignore Cheese
modified
12/2/2019 8:46:40 PM

Hello Ed,

ok, so I edited my basic sub version again to come closer to your adanced sub version.
This is what I got:

Dec 2, 2019 data
1,088 results
34 next day winners (33 instances)
37 next day losers (34 instances)

Nov 29, 2019 35
1,089 results
35 next day winners (34 instances)
37 next day losers (34 instances)

Based on counts, it was almost random, whis is what I would expect in many cases.
Thank you again for your time, Ed.

Cheese
1,374 posts
msg #149766
Ignore Cheese
12/2/2019 8:51:39 PM

In case you may be interested, this is the edited version of Dec 2, 2019 in the evening.
Again, it worked on my machone but the preview suggests it requires advanced sub on sF machine.

Fetcher[
/* edited version of Dec 2, 2019 in the evening for a basic sub */

/* original backtesting code by nibor100 is here: */
/* https://www.stockfetcher.com/forums/General-Discussion/Fibonacci-screener/149298/10 */

not otcbb /* edit to reduce run time */
close above 1 /* edit to reduce run time */
average volume(30) > 1234567 /* edit to reduce run time */

set{cv1, count(average volume(30) 1 day ago > 1234567, 1)}

set{Vdiff,high 1-year high - low 1-year low}
set{x1,Vdiff * .236}
set{Fib1, high 1-year high - x1}
set{touch1b,count(close 2 days ago > fib1,1) * count(open 2 days ago > fib1,1)}
set{Touch1,touch1b * count(low 2 days ago <= Fib1,1)}
set{trg1, Touch1 }

set{cl1, count(close 1 day ago > high 2 days ago, 1)}
set{cl2, count(close 2 days ago < close 3 days ago, 1)}
set{cl3, count(close 3 days ago < close 4 days ago, 1)}
set{cl4, count(close 4 days ago < close 5 days ago, 1)}
set{Tru2, cl1*cl2 }
set{Tru3, cl3*cl4 }
set{Tru40, trg1*cv1 }
set{Tru4, tru2*tru3 }
set{Tru5, tru40*Tru4 }

set{var2, opcl / open}
set{var3, var2 * 100} /*add column var3 {Todays Short %GAIN}*/
set{var4, count( var3 is between 0 and 100, 1)}
set{var6, count( var3 is between -100 and 0, 1)}
set{Tru12, tru5*var4 }
/* set{var5, count(tru12 > 0 ,200)} */ /* edit */
set{var5, count(tru12 > 0 ,252)} and add column var5 {next day winners} /* edit */
set{Tru13, tru5*var6 }
/* set{var8, count(tru13 > 0 ,200)} */ /* edit */
set{var8, count(tru13 > 0 ,252)} and add column var8 {next day losers } /* edit */



/* set{TotalHits, var5 + var8} add column var20 {totalhits } */
/* TotalHits > 0 */ /* add column TotalHits */

set{winners, Tru12*var3 } /* draw winners */ add column winners /* edit */
set{losers, Tru13*var3 } /* draw losers */ add column losers /* edit */
chart-time is 252 days*/

/*date offset is 1/17/2016*/
sort column 6 descending
add column touch1
draw high 1 year high
draw Fib1 on plot price
draw low 1 year low
]




StockFetcher Forums · General Discussion · Fibonacci screener<< 1 2 3 >>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.