Combining intraday and end-of-day data in a trading system is something easy to perform in QuantShare. Some read-to-use functions allow you to get intraday data when working in EOD mode and EOD data when working in intraday mode. In case your needs are more complex, there is always the custom functions creator tool, which basically allows you to implement any function not matter how complex and advanced it is. The strategy we will describe here may be used as an example for day traders who want to implement trading systems using QuantShare. This is the second post of a series started few weeks ago. You can find the first post here: Example of a trading system implemented in QuantShare Software. There, you will also find instructions on how to create a trading system in your favorite quant trading software. Day Trading System Settings The time frame is set to 5 minutes and the maximum number of positions is set to 10. - Update your trading system then update the "Number of positions" field - Select "Symbols & Dates" tab then click on the link located next to "Select a time frame". In the list, select "5m" (5 minutes). Trading System Buy Rules Rule 1: Buy if the open price of today session is 1% lower than yesterday's close and if the stock price increases and stays in positive territory before the first trading hour. Rule 2: Buy only if the daily RSI (Relative strength index) is higher than 70 How to get the open price of today session: The open price of today can be obtained using the "HistoPrice" function. We specify the field type in the first parameter and the lag value in the second. By specifying zero as "Lag" value, we obtain data for the current trading day. a = HistoPrice(_open, 0); How to get yesterday's close: "HistoPrice" is also used to get yesterday's close. "_close" field is set in the first parameter and "1" in the second one (lag). a = HistoPrice(_close, 1); How to determine if the current bar is within the first trading hour: a = hour() * 60 + minute() < (10*60+30); In the above instruction, we calculate the number of minutes since date start and then compare it to the number of minutes from date start to "10:30 am". If the first component is lower than the second one then we are still in the first hour of the trading session. How to get the daily RSI while working with an intraday period: The easier way to perform calculation based on EOD data while working with intraday quotes is by using the "TimeframeApply" function. By simply entering a period and a time-series, this function will transform this time-series in the specified period and it will return the result in compressed format (No date synchronization with the current period). To adjust or synchronize the result with the current data, we must use the "TimeframeDecompress" function. Another important thing here is that we must add a minus (-) sign to the period to reference EOD data. Otherwise, the function will continue using the current intraday data/quotes. Note that when working with daily data, then minus sign allows us to reference intraday data. The easier way to understand and visualize the output of these functions is by plotting them on a chart: - Open a 5-minute chart then type the following formula: a = TimeframeApply(-1, close); a = TimeframeDecompress(a); Plot(a, "Daily Prices", colorBlack, chartLine, StyleSymbolNone); - Add "//" before the second line to see what I mean by compressed format Back to our trading system, in order to get the daily RSI value type: a = TimeframeDecompress(TimeframeApply(-1, rsi(14))); Note: It is necessary that you download EOD data for the analyzed securities Trading System Sell Rules This day trading system contains one single rule, which is to sell any position or trade after four hours. How to exit a trade after four hours: This can be accomplished using an "N-Bar Stop". Since we are working with 5-minute period, four hours represent a total of 48 bars (12 * 4). To set the stop rule programmatically, type the following line: SetSimStop(_StopNBar, _Point, 48, 0); Complete Trading System Formula rule1 = HistoPrice(_open, 0) < HistoPrice(_close, 1) * 0.99; rule2 = hour() * 60 + minute() < (10*60+30) and close > HistoPrice(_close, 1); rule3 = TimeframeDecompress(TimeframeApply(-1, rsi(14))) > 70; buy = rule1 and rule2 and rule3; SetSimStop(_StopNBar, _Point, 48, 0); This day trading system is simply an example to show you how implement trading ideas in QuantShare and it is not intended to create a profitable strategy. This is why we will not show you any report or backtesting result.
|