Click here to Login




How to Backtest an Intraday Stock Trading System with EOD Ranking

Updated on 2014-03-15





In this article, I will show you how to mix end-of-day and intraday data by creating an intraday trading system that trades different stocks every day.

Let us say you want to implement the following intraday trading system:
- Enter long when a stock breaks the first 30-minute resistance

Besides the above rule, you want to trade stocks that performed best the previous day. Let us say that for each trading day, you want to pick from S&P 500 stocks, the first 20 stocks that had the best performance. You will then trade these stocks using the above intraday rule. Each day, you are going to perform the same process. But before trading or investing in such strategy, how can you backtest it?


Create the Intraday Trading System

Let us begin by creating the intraday trading system.
Click here to learn how to implement a trading system.

We must first create the function that calculates the 30-minute resistance. For this, let us use an indicator available on the sharing server (Support and resistance lines based on N-Minutes high/low of a trading session).
After downloading it; select "Tools -> Create Functions" to see how this indicator was implemented.

This chart displays the high and low of the 30 first minutes of a trading session:




In QuantShare programming language we should write:

res30 = FirstMinutesHL(30);

The second step would be to implement the breakout; this is done using the "cross" function:

buy = cross(close, res30);


How to Rank Stocks

Ranking securities on fly is one of the most powerful features of QuantShare.
The "comp" function is capable of ranking and creating composites on fly in different tools such as the screener, simulator, portfolio…

More information about this function can be found in the documentation and in the following articles:
How to create market indicators using the composite function - Part 1, Part 2, Part 3.
New Ranking and Percentile Composite Functions
Trading Indicators using the Rank and Percentile functions


To rank stocks based on their daily performance, type:

a = comp(perf(close, 1), "rank");

To buy top 20 stocks with the highest performance, type:

buy = comp(perf(close, 1), "rank") <= 20;

The best stock has a rank of 1, the next one has a rank of 2 and so on…


Intraday Stock Trading System with EOD Ranking

Now, it is time to combine EOD and intraday rules. Since our strategy is based on intraday data, we can reference our EOD rank rule we implemented previously using the "TimeframeSet" function.

This function allows us to switch to a different time frame, performs calculation then returns back to the original time frame.

Here is the process:

- We start with intraday time frame
- We use "Timeframeset" function to switch to daily time frame
- We calculate one-bar return (The time series is automatically synchronized with the main time frame)
- We move back to the intraday time frame
- We rank stocks based on the one-bar return and get the 20 best performing ones
- We create the intraday rule (cross)
- We combine the ranking and the cross rules

Here is how to implement the formula:

// EOD
TimeframeSet(-1);
rule1 = perf(close, 1);
rule1 = timeframedecompress(rule1); // This function is used to decompress the time series and synchronize it with intraday data
TimeframeRestore();

dailyRule = comp(rule1, "rank") <= 20;

// Intraday
res30 = FirstMinutesHL(30);
inRule = cross(close, res30);

// Buy Rule
buy = inRule and dailyRule;

// Sell Rule
sell = day() != ref(day(), 1); // Exit the same day
SetSimTiming(_Sell, _Close, -1); // Sell at close of current bar (instead of open of next bar)


Before backtesting this strategy, make sure you already downloaded end-of-day and intraday one-minute data for the analyzed symbols.

A similar trading system is available for download in the sharing server. You can get it here:
Intraday Trading System with Daily Ranking












no comments (Log in)

QuantShare Blog
QuantShare
Search Posts




QuantShare
Recent Posts

Create Graphs using the Grid Tool
Posted 1239 days ago

Profile Graphs
Posted 1344 days ago

QuantShare
Previous Posts

How Does QuantShare Work?
Posted 3716 days ago

Troubleshooting a Trading System
Posted 3757 days ago


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.