Click here to Login




Backtesting trading strategies using intraday data

Updated on 2012-08-15





Backtesting intraday trading strategies is not very different from backtesting EOD strategies. It is true that there are some additional options and functions you can use in an intraday system that you cannot in an EOD system. The "hour()", "minute()" or "second()" functions are some examples of such functions. It is also interesting to use daily data when working with intraday systems while the opposite is usually not true.


Downloading Intraday Data

The first thing you should do is to download intraday data for all stocks you want to backtest. Depending on the backtesting period, you should get the appropriate intraday data. If you want to create trading systems based on 10-minutes bars then you should download data with 10-minutes period or lower. In case you get a lower period data, QuantShare will automatically build bars for your desired period.

Several intraday data downloaders can be found in the QuantShare sharing server. The Intraday Data for US Stocks for example downloads 15 days of historical one-minute bars for U.S. stocks. Intraday Quotes for Major Stock Exchanges gets only 1 day of one-minute bars from Yahoo servers.
Both previous items retrieves data by symbol, unlike the Historical Intraday Data for U.S. Stocks item which gets 5-minutes intraday data quickly for all stocks listed in U.S. exchanges (NYSE, NASDAQ and AMEX).


Create a Trading System

- Open the simulator manager by selecting "Analysis" then "Simulator"
- Click on "New" to create a new trading system
- Define your trading system buy, sell, short and cover rules
- Select "Symbols & Dates" tab from the top menu
- Choose a period next to "Select a time frame" option
- Click on "Create a trading system" to save your settings

You can choose a predefined time frame (1 second, 1 minute, 10 minutes, 1 hour...) or a custom one by selecting "Custom" then specifying the number of seconds per bar. For example, specifying 60 is equivalent to a 1-minute period.


Intraday Settings

When you select an intraday period, notice the new "Options" link. Click on that link to open a form.
There you can select whether to use data outside regular trading hours or not. If the option is not checked, the simulator will get the exchange name of each symbol and read only the data that is between the start and end session times of the corresponding exchange.
Exchange settings can be updated by selecting "Accounts -> Intraday Settings -> Exchange. You can display or update the exchange name of each symbol, by selecting "Symbol -> Update Symbol" or "Symbol -> Manage Symbols" (Exchange name is stored under market field).


How to access Daily Data

If your want to access historical EOD data in your intraday trading strategy, then QuantShare offers you several ways to do so:

TimeframeGetSeries: This function transforms a price series using any custom period. Set negative values to use historical (EOD) periods when working with intraday data.

Example: (Returns the daily time series – Works only if you are display an intraday chart)
a = TimeframeGetSeries(-1, close, LastData); // Get daily data (1 day)
plot(a, "", colorBlue);

In QuantShare trading software, right click on chart, select "Edit Formula" then type the above instructions.

TimeframeApply: This function transforms any time series from one time frame to another one. The time series is returned in a compressed format.
More information can be found here:
Technical Analysis Using Multiple Timeframes - Second Part
Day Trading: A trading system that combines intraday and EOD data

Example: (Returns the same result as the first example)
a = TimeframeApply(-1, close);
a = TimeframeDecompress(a);
plot(a, "", colorRed);



Example of an Intraday Trading Strategy

The trading strategy we are going to implement enters a long position if a stock breaks the first 1-hour resistance (high of the first hour in the trading session). It exits the position if it crosses below that resistance or if the stock return becomes lower than 5%.

Additional buy rule: Enter a position only if the daily RSI is above 80.

Before implementing this strategy, make sure that both EOD and Intraday data are downloaded for the stocks you want to backtest.

How to calculate the resistance level of the first hour of a trading session:
First, let us download the following trading indicator: Support and resistance lines based on N-Minutes high/low of a trading session.
The resistance line of the first 60 minutes of a trading session can be calculated as follows:
FirstMinutesHL(60)

Stock breaks the resistance line:
rule1 = close > FirstMinutesHL(60);

Daily RSI is above 80:
a = TimeframeApply(-1, rsi(14));
a = TimeframeDecompress(a);
rule2 = a > 80;


Complete Formula:
rule1 = close > FirstMinutesHL(60);
a = TimeframeApply(-1, rsi(14));
a = TimeframeDecompress(a);
rule2 = a > 80;

buy = rule1 and rule2;


For the stock return lower than 5% rule, add a "5%" stop loss.


Backtesting Intraday Systems

Once your trading system is implemented, select it in the simulator manager then click on "Simulate" to begin the backtesting process.

The backtesting report displays several tabs, including:
- Statistics: Measure and statistics of the trading system performance
- Trades: Displays all trades/transactions generated by this trading system.
- Details: Shows you the composition of the portfolio, orders list and some other measures at any moment in the past.














2 comments (Log in)

QuantShare Blog
QuantShare
Search Posts




QuantShare
Recent Posts

Create Graphs using the Grid Tool
Posted 1479 days ago

Profile Graphs
Posted 1584 days ago

QuantShare
Previous Posts

More Posts

Back







QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.