About the Code:

The purpose of this code is to select trending stock among all. 

Basically it only looks at the stocks which are above sma20, sma40, and sma60.

I am expecting around 2000 stocks out of 16000 stocks each day.

So on 2017-07-28 the program selected around 1800 stocks which is correct.

However after 2017-07-28, the number reduced significantly.  This is absolutely wrong.

And 2017-07-28 is the first day, the filter starts working.

(Caution: The backtest might take a long time)

//*********************************************************************

Question:

Can anyone help with this problem please?

Thank you very much.

//*********************************************************************

The output of this code is writing into log file.

Result showing below.

//*********************************************************************

2017-07-20 00:00:00 Number:0
2017-07-21 00:00:00 Number:0
2017-07-22 00:00:00 Number:0
2017-07-25 00:00:00 Number:0
2017-07-26 00:00:00 Number:0
2017-07-27 00:00:00 Number:0
2017-07-28 00:00:00 Number:1841
2017-07-29 00:00:00 Number:445
2017-08-01 00:00:00 Number:155
2017-08-02 00:00:00 Number:91
2017-08-03 00:00:00 Number:99
2017-08-04 00:00:00 Number:98
2017-08-05 00:00:00 Number:83
2017-08-08 00:00:00 Number:91
2017-08-09 00:00:00 Number:79
2017-08-10 00:00:00 Number:60
2017-08-11 00:00:00 Number:53
2017-08-12 00:00:00 Number:40
2017-08-15 00:00:00 Number:48
2017-08-16 00:00:00 Number:48
2017-08-17 00:00:00 Number:39
2017-08-18 00:00:00 Number:43
2017-08-19 00:00:00 Number:55
2017-08-22 00:00:00 Number:64
2017-08-23 00:00:00 Number:46
2017-08-24 00:00:00 Number:41
2017-08-25 00:00:00 Number:0