Wednesday Reversal: SPY/SH
Author: rmpwealth
Creation Date: 4/23/2013 12:53 PM
profile picture

rmpwealth

#1
I would like to backtest a "Wednesday Reversal" strategy, but need help creating Rules or Code. I searched the Forum for an existing published strategy and found "QQQQ Wednesday Reversal"; but that is not the strategy I want to test.

The Wednesday Reversal strategy that I want to test states that if the market moves in the same direction on a Monday AND the following Tuesday, it will move in the opposite direction the following Wednesday.

I'm thinking the Rules/Code for trading SPY (and SH where appropriate) would be something like this:

Condition-1: If SPY closing price on any Monday is higher than SPY opening price that same Monday, AND if SPY closing price on the following Tuesday is higher than SPY opening price that same Tuesday.

Action-1: Buy SH at Open the following Wednesday morning and Sell SH at Close the same day.

Condition-2 and Action-2 would be the opposite: If SPY price would go DOWN on a Monday and the following Tuesday, then Buy SPY at Open on the following Wednesday and Sell SPY at close that same day.


profile picture

Eugene

#2
CODE:
Please log in to see this code.
profile picture

rmpwealth

#3
Thank you. I copied/pasted the code, and it executes; although I cannot confirm the results without manually checking a few of the indicated Trades.

I am not a programmer, but have perused the code to try to understand it and educate myself, and have a few questions.

1. I see a reference in the code to "SH", but not to "SPY". I presume this is because I should enter SPY manually in the Symbol field?

2. I see references to "Monday" (I presume this is bar = 0) and "Tuesday" (I presume this is bar +1). However, I do not see a specific reference to "Wednesday". It looks like the BuyAtMarket command references bar +1; but I would have expected a BuyAtMarket command on Wednesday to reference bar +2. Would you please explain the sytax of the code that evaluates the market direction on Mondays and Tuesdays, then, if the market direction on Monday and Tuesday are in the same direction, gives a Buy signal on Wednesday to purchase the symbol that is in the oposite of the direction of the market on Monday and Tuesday (i.e -- if Monday and Tuesday are up; Buy SH on Wednesday; and the reverse, where applicable)?

Thanks.
profile picture

Eugene

#4
1. The SPY is assumed to be the primary symbol, so the strategy should be executed on SPY to meet your objectives.

2. Generally, "bar+2" is not used in Wealth-Lab for signals because Alerts only work for bar+1.

It's usually enough to know that Wednesday happens after Tuesday. Of course it's possible to rewrite the code that the entry happens exactly on Wednesday (and does not on Thursday if a market holiday fell on Wednesday) but you will lose alerts. But since Wednesdays make the whopping 5.6% of all market holidays, it's worth the trouble to lose alerts:

CODE:
Please log in to see this code.