StockFetcher Forums · General Discussion · swing trade scanner<< 1 2 3 >>Post Follow-up
Mactheriverrat
3,136 posts
msg #137409
Ignore Mactheriverrat
8/7/2017 1:16:18 AM

1 messages ignored
Isn't this ignore button GREAT!
Teeeeeeeeeeeheeeeeeeeeeeeeeeee

shillllihs
5,984 posts
msg #137412
Ignore shillllihs
modified
8/7/2017 9:55:13 AM

Ignore is only as good as the user and doesn't work if you are tempted to go look at who wrote it.

He asked for a simple system that is easily explained with an entry and exit, which you and many others have never provided. It's ok, don't be sensitive.

I have provided several simple systems that may have not have had mechanical backtesting but looked very good when checked manually, but my entry's and exits have been well defined.

Kevin_in_GA
4,599 posts
msg #137416
Ignore Kevin_in_GA
8/7/2017 11:16:40 AM

Pthomas and shill - I have done exactly what I suggested here numerous times. To help out I will repost two successful systems from my days charging for these on Collective2.

12/31/2014 8:39:29 AM

As some of you know, I have been running a few subscription systems over at Collective2 since early last year. These have been successful both as a trading system and as a source of extra revenue from the subscription fees, but I have decided that for 2015 I will shut them down and spend more time sharing stuff here at SF. Truth is managing three systems nightly had me spending about an hour in total getting the nightly signals out, and that was time I wanted to spend with others rather than in front of the computer (or at least doing something more satisfying on the computer than sending out the nightly signals). Since Pangolin W and Pangolin Z were originally coded in SF, and I use SF every night to put the trades together, it just makes sense to share them here as a way of getting back to what I enjoy most - sharing stuff rather than charging for it.

HERE IS THE COMPLETE PANGOLIN Z SYSTEM CODE IN STOCKFETCHER

Let me start by walking you through the code line by line:

1. Define the market: I only use the S&P 500 for stock systems, as it guarantees liquidity and tight bid/ask spreads, and these stocks are unlikely to make big corrections that can pull you deep into a hole.

The SF code for this is simple:

/*DEFINE THE MARKET*/
S&P 500

2. Determine the ratio of the stock to the S&P 500 index. I use SPY here so that the filter can be checked intraday. The correlation between SPY and the ^SPX is 1.000 so it works perfectly for this application. I use a lot of user-defined variables ... they are constructed using the SET{} function to allow for various mathematical functions and tweaking to be done. As you will see, it allows for a very flexible code construction that not a lot of SF folks know how to do very well.

/*DETERMINE RATIO OF S&P STOCK TO THE ^SPX*/
SET{PRICERATIO, CLOSE / IND(SPY,CLOSE)}
3. Now take the 20 day simple moving average of the ratio. This was one of the optimized parameters. I looked at about 20 different timeframes for this, from 5 to 100 days in 5 day increments:

SET{RATIOMA20, CMA(PRICERATIO,20)}

4. Calculate the Standard Deviation and current Z-score. This is essentially putting Bollinger Bands around the price ratio - the Z-score is the number of SD away from the 20 day simple moving average.

SET{RATIOSTD20, CSTDDEV(PRICERATIO,20)}
SET{DIFF20, PRICERATIO - RATIOMA20}
SET{ZSCORE20, DIFF20 / RATIOSTD20}

5. Set up the required risk management control elements. NEVER ENTER A TRADE WITHOUT RISK CONTROLS!

/*DETERMINE THE MAXIMUM AMOUNT YOU ARE WILLING TO LOSE*/
SET{ACCOUNTSIZE, 25000}
SET{RISKLEVEL, ACCOUNTSIZE*0.005}

Here I have set up the code to put only 0.5% of your trading equity at risk on any given trade. All you need to do is set your account size at whatever the amount is that you can currently trade using this system.

/*DETERMINE LIMIT ENTRY POINT*/
SET{LIMITENTRY, MIN(CLOSE, REVERSERSI(2,5))}

Here we are using the limit entry at the price the would correspond to a RSI(2) of 5. If the stock is already below that value, you use the current close instead - that is why I use the MIN() function here as it automatically chooses the lower price of the two possible limit entries.

/* VAN THARP POSITION SIZING - SET THE STOP LOSS AND SHARE SIZE BASED ON LIMIT ENTRY AND AMOUNT WILLING TO LOSE*/
SET{2ATR, 2 * ATR(20)}
SET{STOPLOSS, LIMITENTRY - 2ATR}

I use twice the value of the ATR(20) as the point for positioning the stop loss. Just a simple subtraction of this amount from the entry price - this should give the stock enough room to fluctuate normally without triggering the stop loss.

/*DETERMINE THE NUMBER OF SHARES TO BE PURCHASED*/
SET{SHARESTOBUY1, RISKLEVEL/2ATR}
SET{SHARESTOBUY, ROUND(SHARESTOBUY1, 0)}

Just a quick comment here - SF code does not let you do more than 1 mathematical operation in any given SET{} statement. Here I have determined the required number of shares, then used the ROUND() function to make the output a whole number for ease in placing orders. When I place my orders I usually round to the nearest 5 shares since that is easier to actually get an order filled - odd amounts like 17 are harder to get filled than 15 or 20 shares.

/*TOTAL AMOUNT OF EQUITY USED IN THIS TRADE*/
SET{POSITIONAMT, LIMITENTRY * SHARESTOBUY}

/*PERCENT OF TRADING CAPITAL USED IN THIS TRADE*/
SET{POSITIONPCT1, POSITIONAMT / ACCOUNTSIZE}
SET{POSITIONPCT, POSITIONPCT1 * 100}

Keep track of these - this helps to prevent you from overcommitting funds.

6. Determine the order of selection of stocks from the nightly results.
There are a lot of ways one can do this, but I prefer to use the ratio of what I can make to what I can lose (return/risk). What you will see if that as the stock price moves up, the profit target moves down until they meet. To me, that means I want the maximum amount I can make to be as large as possible at the start so that the trade stands the best chance of making decent money. As you will see a little further down, I do not want to take trades where this ratio is below 1.

/*DETERMINE THE REWARD-TO-RISK RATIO BASED ON THE PROFIT TARGET AT RSI(2) = 90*/
SET{REWARD1, REVERSERSI(2,90) - LIMITENTRY}
SET{REWARD, REWARD1 * SHARESTOBUY}
SET{R_R, REWARD / RISKLEVEL}

7. Now we tell the filter what to look for. In the original version of the filter, we simply looked for the day where the 16-day Z score crossed below -2, and sold when it crossed back above -1. What I had observed was that often the stock would stay below -2 for another day or so and that buying a little later would have been more profitable. So I ran another optimization on " X days in a row where the Z score was below Y" where I varied X and Y as well. The result - a balance of trade returns and trade frequency - was that the stock had to have a Z score below 0 for the last four days in a row. I also only trade stocks that are above their 200 day moving average. I also looked at the price action relative to a set of different Bollinger Bands - if the low for the day was below the lower BB(10,2) the results were better than any other setting, so that is one of the selection criteria as well.

/*SET THE CRITERIA NECESSARY TO TRIGGER A TRADE*/

COUNT(ZSCORE20 BELOW 0,4) ABOVE 3
LOW BELOW LOWER BOLLINGER BAND(10,2)
CLOSE ABOVE MA(200)
RSI(2) BELOW 15

8. Define the specific columns for the filter results. Here is where you specify and format the filter output.

ADD COLUMN RSI(2)
ADD COLUMN ATR(20) {ATR(20)}
ADD COLUMN SEPARATOR
ADD COLUMN SHARESTOBUY {SHARES TO BUY}
ADD COLUMN LIMITENTRY {LIMIT ENTRY}
ADD COLUMN REVERSERSI(2,90) {PROFIT TARGET}
ADD COLUMN STOPLOSS {STOP LOSS}
ADD COLUMN R_R {REWARD-TO-RISK}
ADD COLUMN POSITIONAMT {POSITION SIZE IN DOLLARS}
ADD COLUMN POSITIONPCT {PERCENT OF TRADING EQUITY}

SORT ON COLUMN 12 DESCENDING

9. Now add some "bells and whistles" to the charts. This part lets you quickly see the entry and exit price

DRAW PRICE LINE AT LIMITENTRY ON PLOT PRICE
DRAW PRICE LINE AT REVERSERSI(2,90) ON PLOT PRICE
DRAW RSI(2) LINE AT 5
DRAW RSI(2) LINE AT 90
DRAW BOLLINGER BANDS(10,2)
DRAW ZSCORE20 LINE AT 0
CHART-TIME IS 3 MONTHS


10. Putting it all together into a single filter. You can now just cut and paste the code below into a new filter on SF, and you have the Pangolin Z system. For determining the new RSI(2)-based profit target each night you simply set up a watchlist of the stocks you are holding and add a column with "add column reversersi(2,90) {profit target}". This will automatically update the dynamic exit for the next day.

Fetcher[
/*DEFINE THE MARKET*/
S&P 500

/*DETERMINE RATIO OF S&P STOCK TO THE ^SPX*/
SET{PRICERATIO, CLOSE / IND(SPY,CLOSE)}

SET{RATIOMA20, CMA(PRICERATIO,20)}

SET{RATIOSTD20, CSTDDEV(PRICERATIO,20)}
SET{DIFF20, PRICERATIO - RATIOMA20}
SET{ZSCORE20, DIFF20 / RATIOSTD20}

/*DETERMINE THE MAXIMUM AMOUNT YOU ARE WILLING TO LOSE*/
SET{ACCOUNTSIZE, 25000}
SET{RISKLEVEL, ACCOUNTSIZE*0.005}

/*DETERMINE LIMIT ENTRY POINT*/
SET{LIMITENTRY, MIN(CLOSE, REVERSERSI(2,5))}

/* VAN THARP POSITION SIZING - SET THE STOP LOSS AND SHARE SIZE BASED ON LIMIT ENTRY AND AMOUNT WILLING TO LOSE*/
SET{2ATR, 2 * ATR(20)}
SET{STOPLOSS, LIMITENTRY - 2ATR}

/*DETERMINE THE NUMBER OF SHARES TO BE PURCHASED*/
SET{SHARESTOBUY1, RISKLEVEL/2ATR}
SET{SHARESTOBUY, ROUND(SHARESTOBUY1, 0)}

/*TOTAL AMOUNT OF EQUITY USED IN THIS TRADE*/
SET{POSITIONAMT, LIMITENTRY * SHARESTOBUY}

/*PERCENT OF TRADING CAPITAL USED IN THIS TRADE*/
SET{POSITIONPCT1, POSITIONAMT / ACCOUNTSIZE}
SET{POSITIONPCT, POSITIONPCT1 * 100}

/*DETERMINE THE REWARD-TO-RISK RATIO BASED ON THE PROFIT TARGET AT RSI(2) = 90*/
SET{REWARD1, REVERSERSI(2,90) - LIMITENTRY}
SET{REWARD, REWARD1 * SHARESTOBUY}
SET{R_R, REWARD / RISKLEVEL}

/*SET THE CRITERIA NECESSARY TO TRIGGER A TRADE*/

COUNT(ZSCORE20 BELOW 0,4) ABOVE 3
LOW BELOW LOWER BOLLINGER BAND(10,2)
CLOSE ABOVE MA(200)
RSI(2) BELOW 15

ADD COLUMN RSI(2)
ADD COLUMN ATR(20) {ATR(20)}
ADD COLUMN SEPARATOR
ADD COLUMN SHARESTOBUY {SHARES TO BUY}
ADD COLUMN LIMITENTRY {LIMIT ENTRY}
ADD COLUMN REVERSERSI(2,90) {PROFIT TARGET}
ADD COLUMN STOPLOSS {STOP LOSS}
ADD COLUMN R_R {REWARD-TO-RISK}
ADD COLUMN POSITIONAMT {POSITION SIZE IN DOLLARS}
ADD COLUMN POSITIONPCT {PERCENT OF TRADING EQUITY}

SORT ON COLUMN 12 DESCENDING

DRAW PRICE LINE AT LIMITENTRY ON PLOT PRICE

DRAW PRICE LINE AT REVERSERSI(2,90) ON PLOT PRICE
DRAW RSI(2) LINE AT 5
DRAW RSI(2) LINE AT 90
DRAW BOLLINGER BANDS(10,2)

DRAW ZSCORE20 LINE AT 0

CHART-TIME IS 3 MONTHS
]




AND HERE IS THE COMPLETE CODE FOR PANGOLIN W - most of the code, specifically the risk control elements and position sizing, are identical so rather than walk through it line by line here is the full filter. Note that the limit entry strategy is the same, but the exit occurs at an RSI(2) of 85 rather than 90.

Fetcher[
S&P 500

COUNT(ROC(9,1) BELOW -1,2) ABOVE 1
ROC(50,1) ABOVE 5
CLOSE ABOVE MA(200)
RSI(2) BELOW 15

SET{2ATR, 2 * ATR(20)}
SET{ACCOUNTSIZE,25000}
SET{RISKLEVEL, ACCOUNTSIZE*0.005}
SET{LIMITENTRY, MIN(CLOSE,REVERSERSI(2,5))}
SET{SHARESTOBUY1, RISKLEVEL / 2ATR}
SET{SHARESTOBUY, ROUND(SHARESTOBUY1,0)}
SET{POSITIONAMT, LIMITENTRY * SHARESTOBUY}
SET{STOPLOSS, LIMITENTRY - 2ATR}
SET{DIFF, LIMITENTRY - STOPLOSS}
SET{REWARD1, REVERSERSI(2,85) - LIMITENTRY}
SET{R_R, REWARD1 / RISKLEVEL}

ADD COLUMN RSI(2)
ADD COLUMN ROC(9,1) {ROC(9)}
ADD COLUMN ROC(50,1) {ROC(50)}
ADD COLUMN SEPARATOR
ADD COLUMN SHARESTOBUY {SHARES TO BUY}
ADD COLUMN LIMITENTRY {LIMIT ENTRY}
ADD COLUMN REVERSERSI(2,85) {PROFIT TARGET}
ADD COLUMN STOPLOSS {STOP LOSS}
ADD COLUMN R_R {REWARD-TO-RISK}
ADD COLUMN POSITIONAMT {POSITION SIZE IN DOLLARS}

DRAW PRICE LINE AT LIMITENTRY
DRAW PRICE LINE AT REVERSERSI(2,85)
DRAW RSI(2) LINE AT 5
DRAW RSI(2) LINE AT 85
DO NOT DRAW ROC(9,1)
DO NOT DRAW ROC(50,1)
SORT ON COLUMN 5 DESCENDING
CHART-TIME IS 3 MONTHS
]






Enjoy.


shillllihs
5,984 posts
msg #137434
Ignore shillllihs
8/7/2017 6:18:42 PM

Didn't read everything but looks good. Is the positioning based on a percentage of 100,000?
What kind of return can you expect?

Kevin_in_GA
4,599 posts
msg #137436
Ignore Kevin_in_GA
8/7/2017 6:42:19 PM

Typical trade return was 1-2% in a few days. During 2013-2014 while I traded this at Coll2, it returned 37% per annum when the S&P returned about 17%. I have moved away from individual stocks (as you have) and now really only focus on ETFs - shorting 3x leveraged (e.g., SOXS) and long XIV.

That said, the system works. Conceptually I liked W better than Z, since it was a "buy the dip" strategy that did not rely on relative performance versus the index, but both worked well.

shillllihs
5,984 posts
msg #137437
Ignore shillllihs
8/7/2017 6:53:37 PM

I removed the top line sp500 and put etf and it seems to give good returns. Is that just a fluke?

pthomas215
1,251 posts
msg #137440
Ignore pthomas215
8/7/2017 7:08:14 PM

good etf filter. Thanks Kevin.

Kevin_in_GA
4,599 posts
msg #137442
Ignore Kevin_in_GA
8/7/2017 9:09:07 PM

I would not advise simply swapping out stocks for ETFs on this without rerunning the filter entry parameters. They were optimized against the S&P 500 stocks, not a short list of ETFs. Not saying it won't work, just pointing out that it was not designed for those securities. Caveat stated here.

shillllihs
5,984 posts
msg #137575
Ignore shillllihs
modified
8/11/2017 2:16:51 PM

Good potential.


shillllihs
5,984 posts
msg #137587
Ignore shillllihs
modified
8/12/2017 1:10:30 PM

Can anyone draw this up as I'm limited in my brain capacity. I'm more of a visual trader.
Thanx.
When line reverse 2,90 is above limit entry, and 200MA. is crossing down through limitentry, you seem to get a very high percentage of stocks that spike. The larger the spread between the 2 lines the more potential.

Example: CF sept. 2016

StockFetcher Forums · General Discussion · swing trade scanner<< 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.