If you have not yet read the first part of this article, please go to Technical Analysis Using Multiple Timeframes. In the previous post, we introduced the "TimeframeSet" function, whose role is to instruct the trading software to use specific timeframe. Here is an example: Once you apply the new timeframe, subsequent calculations will be done using this timeframe. The third line in the above formula calculates the Relative Strength Index using a weekly period. The fourth and fifth lines use the "Plot" function to draw these two RSI vectors or time-series. After using the "TimeframeSet" function, you can switch back to the default timeframe by calling the following function "TimeframeRestore();". The next two functions we will introduce are used to compress and decompress time-series calculated using a different timeframe than the original one. The first function, called “TimeframeDecompress”, decompresses a time-series and then returns it. To see how it works, type the following line just after the relative strength index line (b = rsi(14);): b = TimeframeDecompress(b); This line decompresses the RSI vector and returns an uncompressed time-series. Here is how it looks like: To get the opposite effect, that is, to compress a decompressed time-series, you should use a function whose name is 'TimeframeCompress'. With a weekly compressed time-series, when you use the "ref" function with an argument of one to reference the previous bar, you will get the previous week value. However, if you use the "ref" function to get the previous bar of a decompressed weekly time-series, you will get either the current week value or the previous week value. It depends on the current bar date; if the current bar' day of week is Monday, then you will get the previous week value; in all other cases, you will get the current week value. Now, we will introduce three timeframe-related functions that perform calculation in a specific timeframe and then returns a compressed time-series. The main advantage of using these functions is that the entire process is performed in a single line and thus these functions are well suited to create trading rules (For example, they can be used in the rules analyzer, screener, simulator...) TimeframeGetSeries: This function returns an array for the specified timeframe. The array could be a security's close price, open price, high price, low price, volume or open interest. TimeframeGetSeries1: This function is different from the first one in that it allows you to specify an external ticker symbol. You will get the close price, open price... for a custom timeframe and for the specified ticker symbol. Example: b = TimeframeGetSeries1("goog", 7, close, LastData); This single line instructs the application to return the weekly Google stock's close price. TimeframeApply: This is certainly the most interesting function. With a single line, it allows you to change the timeframe of time-series. Examples: b = TimeframeApply(7, sma(close, 10)); Returns the weekly 10-bar simple moving average of the security's close price. b = TimeframeApply(31, Macd()); Returns the monthly Moving Average Convergence/Divergence (MACD) of a stock. The time-series that results from the "TimeframeGetSeries", "TimeframeGetSeries1" and "TimeframeApply" functions are compressed.
|