Coding gap trading strategies
Author: markmcintosh58
Creation Date: 8/30/2017 8:36 PM
profile picture

markmcintosh58

#1
I have minimal coding experience. I am looking for the best way to code these strategies.

- Shorting a gap on a Wide Range day that is overbought on RSI2 (95 or higher) and then using various exit rules like a close below the 3SMA. I don't see a prebuilt wide range day in the conditions or a gap up condition even though I see there is a way to get this.

- I'd like to test using limit orders to enter on overbought conditions. For example if RSI2 is 95 or higher, stock gaps up above the previous day's high and trades 5% higher on the day entering that day 5% higher and using various holds as exits. I don't see an ability to enter during the day on a limit in the strategy builder.

- Stock gaps greater than 5% above previous close and gaps above 52 week high, then buy if the stock trades 2% higher than the opening gap and sell at the close or the next days open.

To clarify, I would define a wide range day as any day that has a larger range than the previous 6 trading days.

Another random question is testing. I would like to test these on the Russell 3000 as most of these will work better on small caps. I have the Yahoo data for the Data Set. I noticed this goes back to 1991. Is there anyway to test over specific time periods? and not just the full 25 years.


I downloaded a number of the extensions (like Community indicators) but don't see anything on gaps in the conditions of the strategy builder.

Thank you for any help getting started in this.
profile picture

Eugene

#2
Your entry conditions should be easy to approach in code (but not so in Rules). I'll work on getting it done tomorrow. Clarification required re:

QUOTE:
stock gaps up above the previous day's high and trades 5% higher on the day entering that day 5% higher and using various holds as exits.

What do you mean by "5% higher" - is this 5% higher than the previous day's high or from today's open.

P.S.
QUOTE:
Is there anyway to test over specific time periods?

I'm sure you have found the answer in the User Guide > Charting > Chart Control: Data Panel.
profile picture

markmcintosh58

#3
QUOTE:
What do you mean by "5% higher" - is this 5% higher than the previous day's high or from today's open.



I would define a gap as an opening price outside the previous day's range and a 5% higher as the price move off of the open.

QUOTE:
I'm sure you have found the answer in the User Guide > Charting > Chart Control: Data Panel.


I did spend quite a bit of time looking including the user guide. I exited out of the toolbar on the left somehow which made finding the answer less obvious. I see it now.
profile picture

Eugene

#4
#1
QUOTE:
- Shorting a gap on a Wide Range day

I thought of this more and should say that it doesn't fit into WL model well. You can't know that today is a Wide Range day until the close (of today). It would get tricky to code this condition for live trading.

In Wealth-Lab, the process works as follows:
1. A complete bar updates (can be 1-minute, 1-day, etc.)
2. Your strategy executes over all the bars in the chart and determines if it wants to trade on the next bar.
+ If it doesn't, you don't do anything.
+ If it does, you place orders for the next bar and they're worked by your broker. (Process complete).

There's an exception with obtaining today's incomplete bar's Open price (see strategy #2 below) but finding out today's daily range is out of question while the market is open. So here's an approximation for backtesting only where you enter on the close of the WRD with full gap up:
CODE:
Please log in to see this code.


#2.
QUOTE:
- I'd like to test using limit orders to enter on overbought conditions. For example if RSI2 is 95 or higher, stock gaps up above the previous day's high and trades 5% higher on the day entering that day 5% higher and using various holds as exits.

Since this logic requires knowing the incomplete day's open price it gets a little complex. Here's a strategy that should do the trick both for backtesting and live trading. QuickRef (F11) on GetSessionOpen for more:
CODE:
Please log in to see this code.


#3. Hope this helps:

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

markmcintosh58

#5
QUOTE:
I thought of this more and should say that it doesn't fit into WL model well. You can't know that today is a Wide Range day until the close (of today). It would get tricky to code this condition for live trading.


That was not only poorly worded by me, it was incorrectly worded. What I was looking for was a wide range day (WR7) as the initial condition. Then shorting a gap up the next day.
profile picture

Eugene

#6
That makes it simple. Note that I changed the entry as it isn't realistic to buy at market after making a check for a gap (i.e. query the open price). It's yours now -

#1

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

markmcintosh58

#7
Thank you very much for doing this. Absolutely great. I changed the last code to SellAtStop. I will see what I can learn from the code.

I kind of know what the numbers for the first two strategies should look like. The numbers I am getting testing it on the Nasdaq 100 are not in the ballpark. I will see if the numbers fit better with Russell stocks tonight.

I had no idea if the last strategy in the original post was profitable. I was more curious than anything. Thanks again.
profile picture

Eugene

#8
It's a pleasure to assist you.

The 3rd idea looks interesting to me, too.