Home                           

 Try Investor/RT             

 Investor/RT Tour           

 Getting Started              

 What's New                  

 Testimonials                 

Search . . .

Login

 Pricing Summary

 Place Your Order

 Product Description

 Sales Center           

 Contact Us            

 Referrals              

 Renewals            

 Customer Support     

 Download Center      

 Videos        

 Documentation        

 Q & A                      

 Tip Of The Day        

 Tutorials                  

 Advanced Profiling

 Trading Systems    

 Scans                  

 Voices                  

 Education & Training

 Upgrade Center      

 Discussion List         

 Investor/RT Chat       

 About Linn Software

 User Exchange        

 Search

Investor/RT
Tutorials
Gap Trading System

This tutorial discusses setting up a trading system built upon gap trading.

The discussion below demonstrates how to create a backtest that covers the following rules. The discussion demonstrates several backtesting concepts.

  • Stock gaps down 2% at open (2% down from previous close)
  • If Stock takes out high of first 15 min go long. (If between 9:45 and 11:00, the price exceeds the high of the first 15-minutes: 9:30 to 9:45)
  • If no signal by 11am do not trade (Entry only between 9:45 and 11:00)
  • Only one entry permitted
  • Sell if +2% from entry
  • SellStop if -2% from entry.

First, we need to take care of setting a V# variable to the high of the first 15-minutes of the day. You can do this with the following two signals. These signals assume a session open at 9:30am. Adjust to account for your session opening. They also assume a periodicity of 1-min.

First, we'll initiate V#1 to the high of the first bar of the day. (If you were backtesting 5-min data, change 931 to 935, etc)

IF(TIME = 931) THEN (SET(V#1, HI))

Now, on subsequent bars (up until 9:45), we'll check if the high is higher than current V#1, and if so, set V#1 to the new high.

IF(TIME <= 945 AND HI > V#1) THEN (SET(V#1, HI))

The two signals above should be at the top of your list of rules, and be setup with action: none.

We also need a rule that helps up keep up with whether a trade has already been made that day. We'll do this with another no action rule that sets a V# variable:

IF(TIME = 931) THEN (SET(V#2, TNUM))

TNUM is the total number of trades that have been made thus far in the backtest. We'll use the following expression in our Entry rule later to ensure that we are making the first trade of the day.

V#2 = TNUM

Next, we will need to use MPD to get the daily open and previous close values within our intraday backtest. In the signal below, MPDOP (daily open) is simply the MPD token, renamed, setup just like you see in the image below.

MPDPREV, similarly represents the daily previous close value but it is a little trickier to implement. There are a few ways to do it, but we'll do it almost exactly like you see in the MPDOP preference, except for Data Source, we'll choose "Indicator: MA:Moving Average". Then click the "Indicator Preferences" button and setup the MA as a "Simple 1 period on Close, Shifted Right 1 bar". This will take the previous days Close and shift it over into today's MPD.  I have also renamed this MPD to "MPDPREV".  So the following expression:

((MPDOP - MPDPREV) / MPDPREV) <= -0.02

will tell us if there was a gap down of at least 2% from previous close to open.

Now, we only want to enter our position after 9:45, but no later than 11:00. The following expression will take care of this.

TIME > 945 AND TIME <= 1100

And to check that the current high has exceeded the high of the first 15-minutes (V#1), we'll use this expression:

HI > V#1

And to exit our position, we want to check if the closing price is 2% above or below our entry price, using this expression:

CL >= ENTRY * 1.02 OR CL <= ENTRY * 0.98

So to summarize, we have 2 no action rules that serve to set the high of the first 15-minutes into V#1. We have one big Entry rule that checks for the gap condition, the time being between 9:45 and 11:00, the first trade of the day, and the high being above the 15-min high (V#1). We also have an exit condition that checks for a 2% move from entry price. All four rules are below:

Rules 1&2: SETTING 15-MIN HIGH (No Action Rules)

IF(TIME = 931) THEN (SET(V#1, HI))

IF(TIME <= 945 AND HI > V#1) THEN (SET(V#1, HI))

Rule 3: SETTING V#2 TO TOTAL NUMBER OF TRADES TO THAT POINT

IF(TIME = 931) THEN (SET(V#2, TNUM))

Rule 4: ENTRY

(((MPDOP - MPDPREV) / MPDPREV) <= -0.02) AND (TIME > 945 AND TIME < 1100) AND (HI > V#1) AND (TNUM = V#2)

Rule 5: EXIT

CL >= ENTRY * 1.02 OR CL <= ENTRY * 0.98

That should do it. There may be a few things you will need to tweak based on your system. For instance, if you're using 5-min data, you'll need to change 931 to 935 in a couple of place. If you want to test of the Closing price breaking above the 15-minute high. you'll need to change:

(HI > V#1)

to...

(CL > V#1)

If you're already using V#1 and V#2 for other purposes, you may want to use V#18 and V#19, or whatever.