StockFetcher Forums · Filter Exchange · TRADING DIVERGENCES ON THE S&P 500<< 1 2 3 4 5 ... 33 >>Post Follow-up
Kevin_in_GA
4,599 posts
msg #108174
Ignore Kevin_in_GA
modified
9/25/2012 11:24:15 PM

Lately I have been playing around with Stratasearch and just letting it run massive numbers of indicator combinations on the SPX. After over 600,000 different combinations of entries and exits I began to notice some common repetitive patterns in the best performing combinations.

1. The entries were almost always based on divergences between price and an indicator. The divergences usually occurred over a 6-12 day time period, and always had the price stable or rising while the indicator continued to drop in value. This seems counter-intuitive, since that is called a "negative divergence" and is often associated with a short-term price reversal rather than a gain.

2. The exits were always connected to a 10-15 day high in the close, which did not parallel a similar high in the momentum. This makes sense, since you are getting out after a short run up in price. Very consistently I saw this exit, and actually began to set up my optimizations with the exit fixed, rather than the entry. The specific SF code for this exit is

set{exit1, count(close reached a new 10 day high,1)}
set{exit2, count(ROC(15,1) is below ROC(15,1) 10 day high,1)}
set{exit, exit1 * exit2}


I decided to set this as a common exit, and then run optimizations on a variety of indicator divergences. The results were quite good, usually with win percentages in the high 80's to low 90's, short hold times of 6-7 days, and very respectable annual returns and Sharpe ratios. Given this is for the S&P 500 index, it just makes sense to share this with the SF community - to be used as you see fit (general timing, leveraged ETFs, options, etc). All I will provide is the codes ... the rest is up to you.

Here are my "Top 10" divergence filters, along with the statistical analyses from 1/2/2007 until 9/14/2012. I am providing the Monte Carlo results here since they tend to be more reflective of how a system will work going forward. During this period most of the filters traded about 100-120 times each, with many triggering on the same dates.

++++++++++++++++++++++++++++++

Stratasearch code
(diverge(cmf(14), mov(close, 3, simple), 2, 7) = -1)

Fetcher[
SYMLIST(SPY)
/*CODING FOR DIVERGENCE BETWEEN MA(3) AND CHAIKIN MONEY FLOW*/

SYMLIST(SPY)
SET{CMF14DOWN, COUNT(CMF(14) BELOW CMF(14) 7 DAYS AGO,1)}
SET{CMF14DOWN2, COUNT(CMF(14) DROPPED MORE THAN 2% OVER THE LAST 7
DAYS,1)}

SET{MA3UP1, COUNT(MA(3) ABOVE MA(3) 7 DAYS AGO,1)}
SET{MA3UP1_2, COUNT(MA(3) GAINED MORE THAN 2% OVER THE LAST 7 DAYS,1)}

SET{DIV1A, CMF14DOWN * MA3UP1}
SET{DIV2A, CMF14DOWN2 + MA3UP1_2}
SET{DIV3A, COUNT(DIV2A ABOVE 0.5,1)}
SET{CMF14DIV, DIV1A*DIV3A}

ADD COLUMN CMF14DIV
DRAW CMF14DIV

set{exit1, count(close reached a new 10 day high,1)}
set{exit2, count(ROC(15,1) is below ROC(15,1) 10 day high,1)}
set{exit, exit1 * exit2}

ADD COLUMN EXIT

draw exit
]



Performance from 1/2/2007 to 9/14/2012
Number of Trades = 134
MC Av. Annual Return = 31.95%
MC Av. Trade Return = 0.79%
MC Av. Drawdown = 11.75%
MC Av. Percent Profitable = 88.81%
Annualized Sharpe Ratio = 1.505

++++++++++++++++++++++++++++++

Stratasearch code
(diverge(smi(3, 6, 6), mov(close, 3, simple), 7, 11) = -1)

Fetcher[
/*CODING FOR DIVERGENCE BETWEEN MA(3) AND THE STOCHASTIC MOMENTUM
INDICATOR*/
SYMLIST(SPY)
SET{SMI11down, COUNT(SMI(3,6,6) below SMI(3,6,6) 11 days ago,1)}
SET{SMI11down7, COUNT(SMI(3,6,6) DROPPED MORE THAN 7% OVER THE LAST 11
DAYS,1)}

SET{MA3UP2, COUNT(MA(3) above MA(3) 11 days ago,1)}
SET{MA3UP2_7, COUNT(MA(3) gained MORE THAN 7% OVER THE LAST 11 DAYS,1)}

SET{DIV1B, SMI11down * MA3UP2}
SET{DIV2B, SMI11DOWN7 + MA3UP2_7}
SET{DIV3B, COUNT(DIV2B ABOVE 0.5,1)}
SET{SMI11DIV, DIV1B*DIV3B}

ADD COLUMN SMI11DIV

DRAW SMI11DIV

set{exit1, count(close reached a new 10 day high,1)}
set{exit2, count(ROC(15,1) is below ROC(15,1) 10 day high,1)}
set{exit, exit1 * exit2}

ADD COLUMN EXIT

draw exit
]



Performance from 1/2/2007 to 9/14/2012
Number of Trades = 105
MC Av. Annual Return = 34.38%
MC Av. Trade Return = 1.05%
MC Av. Drawdown = 6.59%
MC Av. Percent Profitable = 91.43%
Annualized Sharpe Ratio = 1.734

++++++++++++++++++++++++++++++

Stratasearch Code
(diverge(wlr(14), mov(close, 3, simple), 1, 12) = -1)

Fetcher[
/*CODING FOR DIVERGENCE BETWEEN MA(3) AND THE WILLIAMS %R INDICATOR*/
SYMLIST(SPY)
SET{WLR12down, COUNT(WILLIAMS %R(14) below WILLIAMS %R(14) 12 days ago,1)}
SET{WLR12down1, COUNT(WILLIAMS %R(14) DROPPED MORE THAN 1% OVER THE LAST
12 DAYS,1)}

SET{MA3UP3, COUNT(MA(3) above MA(3) 12 days ago,1)}
SET{MA3UP3_1, COUNT(MA(3) gained MORE THAN 1% OVER THE LAST 12 DAYS,1)}

SET{DIV1C, WLR12down * MA3UP3}
SET{DIV2C, WLR12DOWN1 + MA3UP3_1}
SET{DIV3C, COUNT(DIV2C ABOVE 0.5,1)}
SET{WLR12DIV, DIV1C * DIV3C}

ADD COLUMN WLR12DIV

DRAW WLR12DIV

set{exit1, count(close reached a new 10 day high,1)}
set{exit2, count(ROC(15,1) is below ROC(15,1) 10 day high,1)}
set{exit, exit1 * exit2}

ADD COLUMN EXIT

draw exit
]



Performance from 1/2/2007 to 9/14/2012
Number of Trades = 123
MC Av. Annual Return = 37.86%
MC Av. Trade Return = 0.95%
MC Av. Drawdown = 8.23%
MC Av. Percent Profitable = 85.37%
Annualized Sharpe Ratio = 1.494

++++++++++++++++++++++++++++++

Stratasearch code
(diverge(pdi(10), mov(close, 3, simple), 10, 8) = -1)

Fetcher[
SYMLIST(SPY)
/*CODING FOR DIVERGENCE BETWEEN MA(3) AND THE +DI INDICATOR*/
SET{PDI10down, COUNT(PDI(10) below PDI(10) 8 days ago,1)}
SET{PDI10down10, COUNT(PDI(10) DROPPED MORE THAN 10% OVER THE LAST 8 DAYS,1)}

SET{MA3UP4, COUNT(MA(3) above MA(3) 8 days ago,1)}
SET{MA3UP4_1, COUNT(MA(3) gained MORE THAN 10% OVER THE LAST 8 DAYS,1)}

SET{DIV1D, PDI10down * MA3UP4}
SET{DIV2D, PDI10DOWN10 + MA3UP4_1}
SET{DIV3D, COUNT(DIV2D ABOVE 0.5,1)}
SET{PDI10DIV, DIV1D * DIV3D}

ADD COLUMN PDI10DIV

DRAW PDI10DIV

set{exit1, count(close reached a new 10 day high,1)}
set{exit2, count(ROC(15,1) is below ROC(15,1) 10 day high,1)}
set{exit, exit1 * exit2}

ADD COLUMN EXIT

draw exit
]



Performance from 1/2/2007 to 9/14/2012
Number of Trades = 86
MC Av. Annual Return = 29.60%
MC Av. Trade Return = 1.17%
MC Av. Drawdown = 7.27%
MC Av. Percent Profitable = 86.05%
Annualized Sharpe Ratio = 1.555

++++++++++++++++++++++++++++++

Stratasearch code
(diverge(aroonu(6), mov(close, 3, simple), 4, 4) = -1)

Fetcher[
/*CODING FOR DIVERGENCE BETWEEN MA(3) AND THE AROON UP INDICATOR*/
SYMLIST(SPY)
SET{ARUP6down, COUNT(AROON UP(6) below AROON UP(6) 4 days ago,1)}
SET{ARUP6down4, COUNT(AROON UP(6) DROPPED MORE THAN 4% OVER THE LAST 4 DAYS,1)}

SET{MA3UP5, COUNT(MA(3) above MA(3) 4 days ago,1)}
SET{MA3UP5_1, COUNT(MA(3) gained MORE THAN 4% OVER THE LAST 10 DAYS,1)}

SET{DIV1E, ARUP6down * MA3UP5}
SET{DIV2E, ARUP6DOWN4 + MA3UP5_1}
SET{DIV3E, COUNT(DIV2E ABOVE 0.5,1)}
SET{ARUP6DIV, DIV1E * DIV3E}

ADD COLUMN ARUP6DIV

DRAW ARUP6DIV

set{exit1, count(close reached a new 10 day high,1)}
set{exit2, count(ROC(15,1) is below ROC(15,1) 10 day high,1)}
set{exit, exit1 * exit2}

ADD COLUMN EXIT

draw exit
]



Performance from 1/2/2007 to 9/14/2012
Number of Trades = 113
MC Av. Annual Return = 34.21%
MC Av. Trade Return = 0.97%
MC Av. Drawdown = 7.80%
MC Av. Percent Profitable = 87.62%
Sharpe Ratio = 1.532

++++++++++++++++++++++++++++++

Stratasearch code
(diverge(lrs(close,8), mov(close, 3, simple), 10, 10) = -1)

Fetcher[
/*CODING FOR DIVERGENCE BETWEEN MA(3) AND THE LINEAR REGRESSION SLOPE*/
SYMLIST(SPY)
SET{LRS8down, COUNT(LRS(8) below LRS(8) 10 days ago,1)}
SET{LRS8down10, COUNT(LRS(8) DROPPED MORE THAN 10% OVER THE LAST 10 DAYS,1)}

SET{MA3UP6, COUNT(MA(3) above MA(3) 10 days ago,1)}
SET{MA3UP6_1, COUNT(MA(3) gained MORE THAN 10% OVER THE LAST 10 DAYS,1)}

SET{DIV1F, LRS8down * MA3UP6}
SET{DIV2F, LRS8DOWN10 + MA3UP6_1}
SET{DIV3F, COUNT(DIV2F ABOVE 0.5,1)}
SET{LRS8DIV, DIV1F * DIV3F}

ADD COLUMN LRS8DIV

DRAW LRS8DIV

set{exit1, count(close reached a new 10 day high,1)}
set{exit2, count(ROC(15,1) is below ROC(15,1) 10 day high,1)}
set{exit, exit1 * exit2}

ADD COLUMN EXIT

draw exit
]



Performance from 1/2/2007 to 9/14/2012
Number of Trades = 126
MC Av. Annual Return = 29.33%
MC Av. Trade Return = 0.79%
MC Av. Drawdown = 8.38%
MC Av. Percent Profitable = 91.27%
Sharpe Ratio = 1.381

++++++++++++++++++++++++++++++

Stratasearch code
(diverge(qst(12), mov(close, 3, simple), 2, 12) = -1)

Fetcher[

/*CODING FOR DIVERGENCE BETWEEN MA(3) AND THE Q-STICK INDICATOR*/
SYMLIST(SPY)
SET{QST12down, COUNT(QSTICK(12) below QST(12) 12 days ago,1)}
SET{QST12down2, COUNT(QSTICK(12) DROPPED MORE THAN 2% OVER THE LAST 12 DAYS,1)}

SET{MA3UP7, COUNT(MA(3) above MA(3) 12 days ago,1)}
SET{MA3UP7_1, COUNT(MA(3) gained MORE THAN 2% OVER THE LAST 12 DAYS,1)}

SET{DIV1G, QST12down * MA3UP7}
SET{DIV2G, QST12DOWN2 + MA3UP7_1}
SET{DIV3G, COUNT(DIV2G ABOVE 0.5,1)}
SET{QST12DIV, DIV1G * DIV3G}

ADD COLUMN QST12DIV

DRAW QST12DIV

set{exit1, count(close reached a new 10 day high,1)}
set{exit2, count(ROC(15,1) is below ROC(15,1) 10 day high,1)}
set{exit, exit1 * exit2}

ADD COLUMN EXIT

draw exit
]



Performance from 1/2/2007 to 9/14/2012
Number of Trades = 133
MC Av. Annual Return = 33.24%
MC Av. Trade Return = 0.81%
MC Av. Drawdown = 7.89%
MC Av. Percent Profitable = 87.97%
Annualized Sharpe Ratio = 1.605

++++++++++++++++++++++++++++++

Stratasearch code
(diverge(rsi(10), mov(close, 3, simple), 3, 12) = -1)

Fetcher[

/*CODING FOR DIVERGENCE BETWEEN MA(3) AND THE RSI INDICATOR*/
SYMLIST(SPY)
SET{RSI10down, COUNT(RSI(10) below RSI(10) 12 days ago,1)}
SET{RSI10down3, COUNT(RSI(10) DROPPED MORE THAN 3% OVER THE LAST 12 DAYS,1)}

SET{MA3UP8, COUNT(MA(3) above MA(3) 12 days ago,1)}
SET{MA3UP8_1, COUNT(MA(3) gained MORE THAN 3% OVER THE LAST 12 DAYS,1)}

SET{DIV1H, RSI10down * MA3UP8}
SET{DIV2H, RSI10DOWN3 + MA3UP8_1}
SET{DIV3H, COUNT(DIV2H ABOVE 0.5,1)}
SET{RSI10DIV, DIV1H * DIV3H}

ADD COLUMN RSI10DIV

DRAW RSI10DIV

set{exit1, count(close reached a new 10 day high,1)}
set{exit2, count(ROC(15,1) is below ROC(15,1) 10 day high,1)}
set{exit, exit1 * exit2}

ADD COLUMN EXIT

draw exit
]



Performance from 1/2/2007 to 9/14/2012
Number of Trades = 93
MC Av. Annual Return = 35.47%
MC Av. Trade Return = 1.21%
MC Av. Drawdown = 7.88%
MC Av. Percent Profitable = 87.10%
Annualized Sharpe Ratio = 1.553

++++++++++++++++++++++++++++++

Stratasearch Code
(diverge(rmi(8, 2), mov(close, 3, simple), 1, 12) = -1)

Fetcher[

/*CODING FOR DIVERGENCE BETWEEN MA(3) AND THE RMI INDICATOR*/
SYMLIST(SPY)
SET{RMI82down, COUNT(RMI(8,2) below RMI(8,2) 12 days ago,1)}
SET{RMI82down1, COUNT(RMI(8,2) DROPPED MORE THAN 1% OVER THE LAST 12 DAYS,1)}

SET{MA3UP9, COUNT(MA(3) above MA(3) 12 days ago,1)}
SET{MA3UP9_1, COUNT(MA(3) gained MORE THAN 1% OVER THE LAST 12 DAYS,1)}

SET{DIV1I, RMI82down * MA3UP9}
SET{DIV2I, RMI82DOWN1 + MA3UP9_1}
SET{DIV3I, COUNT(DIV2I ABOVE 0.5,1)}
SET{RMI82DIV, DIV1I * DIV3I}

ADD COLUMN RMI82DIV

DRAW RMI82DIV

set{exit1, count(close reached a new 10 day high,1)}
set{exit2, count(ROC(15,1) is below ROC(15,1) 10 day high,1)}
set{exit, exit1 * exit2}

ADD COLUMN EXIT

draw exit
]




Performance from 1/2/2007 to 9/14/2012
Number of Trades = 105
MC Av. Annual Return = 31.19%
MC Av. Trade Return = 0.99%
MC Av. Drawdown = 8.46%
MC Av. Percent Profitable = 87.62%
Sharpe Ratio = 1.490

++++++++++++++++++++++++++++++

Stratasearch code
(diverge(stochd(3, 2, 5, simple), mov(close, 3, simple), 2, 11) = -1)

Fetcher[
/*CODING FOR DIVERGENCE BETWEEN MA(3) AND THE STOCHASTICS %D INDICATOR*/
SYMLIST(SPY)
SET{STD325down, COUNT(FULL STOCHASTICS %D(3,2,5) below FULL STOCHASTICS %D(3,2,5) 11 days ago,1)}
SET{STD325down2, COUNT(FULL STOCHASTICS %D(3,2,5) DROPPED MORE THAN 2% OVER THE LAST 11 DAYS,1)}

SET{MA3UP10, COUNT(MA(3) above MA(3) 11 days ago,1)}
SET{MA3UP10_1, COUNT(MA(3) gained MORE THAN 2% OVER THE LAST 11 DAYS,1)}

SET{DIV1J, STD325down * MA3UP10}
SET{DIV2J, STD325DOWN2 + MA3UP10_1}
SET{DIV3J, COUNT(DIV2J ABOVE 0.5,1)}
SET{STD325DIV, DIV1J * DIV3J}

ADD COLUMN STD325DIV

DRAW STD325DIV

set{exit1, count(close reached a new 10 day high,1)}
set{exit2, count(ROC(15,1) is below ROC(15,1) 10 day high,1)}
set{exit, exit1 * exit2}

ADD COLUMN EXIT

draw exit
]



Performance from 1/2/2007 to 9/14/2012
Number of Trades = 126
MC Av. Annual Return = 35.06%
MC Av. Trade Return = 0.88%
MC Av. Drawdown = 6.88%
MC Av. Percent Profitable = 91.29%
Sharpe Ratio = 1.594

All of the results were generated using the "buy at the open on the day after the signal is given". Same with the close.

Looking at what they are saying about today's action, I already jumped into SPY near the close today.

Enjoy,

Kevin




Rock Sexton
111 posts
msg #108176
Ignore Rock Sexton
9/26/2012 12:06:08 AM

Love divergence trading. There is nothing else IMO.

bman99
6 posts
msg #108181
Ignore bman99
9/26/2012 12:55:32 PM

Kevin,

It looks good but I am not sure how to interpret the filter results.

In most of the filters you have two fields that toggle between values 0 and 1.

For example in the first filter, the one field is called cmf14div. The second field is called EXIT.

How do you interpret the filter results and use these two field's values?

For example, Do you buy when first field is 1 and then wait until the exits field hits 1 to sell?

Good work. Thank you!



Kevin_in_GA
4,599 posts
msg #108183
Ignore Kevin_in_GA
9/26/2012 1:25:05 PM

For example, do you buy when first field is 1 and then wait until the exits field hits 1 to sell?

Yes. If you look at the chart, you'll see that both the entries and exits for each filter are graphed at the bottom. Enter when the divergence signal is triggered (either end of day or at the open next day) and sell when the exit triggers.

Eman93
4,750 posts
msg #108190
Ignore Eman93
9/26/2012 10:21:43 PM

my basic money flow divergence .(.same filter as the rsi i have posted in the past.) when you get an extreme amount (+100) of hits it could signal a bottom.

From what I have experienced the MFI gives better results.

First thing to remember is that there is a big difference between a bounce and a trend reversal. But most reversals happen with a divergence in play.

Kevin you could also try combining RSI and MFI and see what you get.

Remember with this screen you need to "eyeball" each chart to see if price made a new swing low.. if it didn't its not a divergence.



Fetcher[

close > 1

Williams %R(14) > Williams %R(14) 1 day ago

volume > 800000

low reached a new 10 week low

set{rslo, 0 + Money Flow Index(10) 10 week low}



set{rsla, 0 + Money Flow Index(10) 3 week low}

set{rstoday, 0 + Money Flow Index(10)}

set{rdlo, rslo / rsla}

set{rdlp, 1 - rdlo}

set{rmda, rslo - rstoday}

set{rmdb, rslo - rsla}

rdlo < 1

draw Money Flow Ind
ex(10) 10 week low

add column rstoday

add column rsla {3w low}

add column rslo {10W low}

add column rmdb

add column rdlp

sort column 8 ascending

add column Volume Weighted Moving Average(14)

add column IND

add column high
]




Kevin_in_GA
4,599 posts
msg #108215
Ignore Kevin_in_GA
9/28/2012 3:54:53 PM

Not sure that I could get much better stats than what these are aready showing. By combining the RSI and MFI (or any other set of indicators) you will reduce the total number of trades. Given the high win percentage and positive expectancy seen in these I want to go the opposite direction and get as many more trades like these as possible.

To me this is a low-risk way to go long the S&P 500 using SPY, SSO, or even options for the bravest/most foolhardy. Not all of the trades are big - in fact most of the gains are less than 1% - but you have got to respect the consistency of these through what was an extremely challenging period for most investors.

mahkoh
1,065 posts
msg #108216
Ignore mahkoh
9/28/2012 5:04:14 PM

Kevin, what does MC avg drawdown mean? I hope not average drawdown per trade?
I did google it but before delving into extensive reading material I was hoping you might have a quick explanation.

Kevin_in_GA
4,599 posts
msg #108217
Ignore Kevin_in_GA
9/28/2012 7:00:58 PM

The Monte Carlo simulations (random combinations of all possible trades) tend to give you a better understanding of how a system might actually perform, since we can never actually select trades in real-time by volume descending, etc.

Each of the MC stats is the average from 5000 iterations. In the case you ask, it is the average of the Maximum Drawdown encountered in each combination during the test period. So if it is something like 7-8%, compare that to the actually SPX drawdown seen in 2008 and you'll see that these systems steered you clear of a lot of trouble.

mahkoh
1,065 posts
msg #108221
Ignore mahkoh
9/30/2012 3:42:52 PM

Thanks for clearing that up. I assume the MC av annual return is compounded?
Have you considered using a composite filter where you count all separate signals like with the Connors filters in the "high probability trading" thread?


Kevin_in_GA
4,599 posts
msg #108223
Ignore Kevin_in_GA
9/30/2012 6:35:25 PM

Yes to both. Note that in each filter I have adjusted variable names such that they can all be combined into a single filter if that's what folks want to do. To be honest the combined filter does not exceed any of the individual filters since all of the filters have very high win %'s.

Here is where each one is in terms of in or out of a trade - the columns are date of trade, entry, current, gain/loss, system

09/10/2012 1437.9200 1440.6700 0.19% STOCHD Divergence #1
09/10/2012 1437.9200 1440.6700 0.19% SMI Divergence #1
09/10/2012 1437.9200 1440.6700 0.19% CMF Divergence #1
09/11/2012 1429.1300 1440.6700 0.81% QST Divergence #1
09/11/2012 1429.1300 1440.6700 0.81% RSI Divergence #1
09/11/2012 1429.1300 1440.6700 0.81% WLR(14) Divergence #1
09/21/2012 1460.3400 1440.6700 -1.35% AROON UP Divergence #1
09/24/2012 1459.7600 1440.6700 -1.31% LRS Divergence #1
09/26/2012 1441.6000 1440.6700 -0.06% RMI Divergence #1
09/26/2012 1441.6000 1440.6700 -0.06% PDI Divergence #1

Not lighting the world on fire, but the combined performance of these 10 filters over the last four months is 64 wins, 1 losing trade for an aggregate gain of 9.3%.

YTD: Up 12.5%but you were only in a trade 49.8% of the time.

StockFetcher Forums · Filter Exchange · TRADING DIVERGENCES ON THE S&P 500<< 1 2 3 4 5 ... 33 >>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.