StockFetcher Forums · View by Author: Kevin_in_GA (3,430 messages) ·  [ Display By: Date / Subject ]<< 1 ... 2 3 4 5 6 ... 343 >> 
General Discussion · Yepher.com
Kevin_in_GA
msg #122454
1/3/2015 9:25:05 PM

I read this multiple times when first learning to code for SF - a tremendous resource. Hey StockFetcher, how about hosting it?

General Discussion · Wanted: Stock Fetcher Pro...
Kevin_in_GA
msg #122446
1/1/2015 5:06:32 PM

I still stand by what I said then. Why pay for what you can likely get for free by just posting the desired screen? If you think it is so good that you don't want to share it, that's fine as well. Someone here can probably use the money.

Filter Exchange · PANGOLIN Z AND PANGOLIN W - FULL SYSTEM CODE
Kevin_in_GA
msg #122445
1/1/2015 5:02:41 PM

The trades are the same, since this is the source for all of my trades since the inception of Pangolin Z. I would periodically use lowest RSI or highest R/R to make selections, but all trade will be found if one looks.

The system was optimized on 5-10 trades. Either work well, but when using the Van Tharp position sizing you will find that not all of your available funds are in play. In that case you can increase the number of trades, but only from what the filter returns.

Filter Exchange · PORTFOLIO SELECTION AND MANAGEMENT USING RISK/REWARD RATIOS
Kevin_in_GA
msg #122432
12/31/2014 9:20:40 AM

Yes, IWM for January.

Filter Exchange · PANGOLIN Z AND PANGOLIN W - FULL SYSTEM CODE
Kevin_in_GA
msg #122431
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 system 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.

Filter Exchange · how to find sectors crossing 150DMA in last week
Kevin_in_GA
msg #122296
12/18/2014 8:21:07 AM

That was my original thought as well, but there are a lot more sectors than there are sector ETFs, and all but a handful of the sector ETFs are low volume traders, which can skew some of the volume-based indicators.

If you are just looking at the 10-20 biggest sectors ETFs are the way to go, but if you are planning to go farther afield then you could use the sector indices as well.

Filter Exchange · how to find sectors crossing 150DMA in last week
Kevin_in_GA
msg #122286
modified
12/17/2014 1:19:07 PM

Not really - SF filters only return stocks, not sectors.

However, you could set up a watchlist that would be able to use the Dow Jones Indices listed here:

http://www.stockfetcher.com/help/What-indices-are-available/100229

In that watchlist you can add a column that says

add column count(close crossed above ma(150) within the last week,1)

this would give you a "1" or "0" for meeting that criteria.

Filter Exchange · Double Inside Days
Kevin_in_GA
msg #122213
12/11/2014 9:44:13 PM

I do accept payment in beer. However in this case I'm sufficiently compensated knowing that it helps you out.

I will say that you should be looking at some of Tony Crabel's N4 and N7 + inside day stuff (you will see that in the other post responding to you original question). My catch has been that while this usually leads to a breakout play, I can never tell in which direction.

Filter Exchange · Thanks Kevin!
Kevin_in_GA
msg #122212
12/11/2014 9:40:03 PM

None really. This was more of an observation that I put into SF code - I never really used it nor have I evolved it since the original post a long while back.

Filter Exchange · Thanks Kevin!
Kevin_in_GA
msg #122198
12/10/2014 8:15:58 PM

A blast from the past. You are welcome. Glad if it makes you some money!

StockFetcher Forums ·  · << 1 ... 2 3 4 5 6 ... 343 >>

*** 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 2015 - 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