Tutorial 171 demonstrates how to create a correlation indicator for data pairs where one of the data pairs has ‘missing bars.’ For example, for symbol 1 (data1) trading might have occurred on every bar during the trading session. Symbol 2 might be more thinly traded and hence it doesn’t have trading activity on every bar.
The correlation coefficient is a number between -1 and 1, which measures the degree to which two data series are linearly related. A perfect linear relationship with positive slope gives a correlation coefficient of 1. If there is a perfect linear relationship with negative slope between the two data series, the correlation coefficient of -1. A correlation coefficient of 0 means that there is no linear relationship between the data series.
The normal correlation function works by counting back bars in both data series and checking if they are both going up or both going down. The problem is that, because some bars are missing in one of the data series the program is comparing bars with potentially different time signatures.
For example, using the symbol A as data1 and AADI as data2 the following data sample was printed using the following routine:
If LastBarOnChart then
For Value3 = 0 to Length - 1
Print( Value3, " Time 1 ", ( T Data1 )[Value3], " Time 2 ", ( T Data2 )[Value3] );
0.00 Time 1 1020.00 Time 2 1020.00
1.00 Time 1 1015.00 Time 2 1010.00
2.00 Time 1 1010.00 Time 2 1000.00
3.00 Time 1 1005.00 Time 2 955.00
4.00 Time 1 1000.00 Time 2 950.00
5.00 Time 1 955.00 Time 2 945.00
6.00 Time 1 950.00 Time 2 940.00
7.00 Time 1 945.00 Time 2 935.00
8.00 Time 1 940.00 Time 2 1600.00
9.00 Time 1 935.00 Time 2 1555.00
10.00 Time 1 1600.00 Time 2 1550.00
11.00 Time 1 1555.00 Time 2 1535.00
12.00 Time 1 1550.00 Time 2 1530.00
13.00 Time 1 1545.00 Time 2 1525.00
You will see that the bars would get out of sync very quickly because, for example, we would compare the increase or decrease in value of the 1015 bar on data1 with the increase or decrease in value of the 1020 bar on data2.
Tutorial 171 analyzes the data to create two arrays. Data1 bars that do not have a corresponding Data2 bar are excluded from the array, and vice versa. The standard CorrelationArray function then processes the two arrays to calculate the correlation.
Download the tutorial 171 TradeStation EasyLanguage indicators
If you want to save yourself some typing, the tutorial 171 code is available for immediate download for $19.50 by clicking the following button. You can pay using PayPal or credit card. The program works with TradeStation 9.5 and 10. It is also compatible with MultiCharts.
The download also includes a function version of the program (_Tutorial171Function). An example of the usage of the function is:
Value10 = _Tutorial171Function( 14, T Data1, T Data2, D Data1, D Data2, C Data1, C Data2 );
The download consists of _Tutorial171 (the TradeStation EasyLanguage indicator developed in the tutorial) and the _Tutorial171Function function.
THE TRADING APPS, INDICATORS, SHOW ME STUDIES, STRATEGIES AND OTHER PROGRAMS HAVE BEEN INCLUDED SOLELY FOR EDUCATIONAL PURPOSES.
TO THE BEST OF MARKPLEX CORPORATION’S KNOWLEDGE, ALL OF THE INFORMATION ON THIS PAGE IS CORRECT, AND IT IS PROVIDED IN THE HOPE THAT IT WILL BE USEFUL. HOWEVER, MARKPLEX CORPORATION ASSUMES NO LIABILITY FOR ANY DAMAGES, DIRECT OR OTHERWISE, RESULTING FROM THE USE OF THIS INFORMATION AND/OR PROGRAM(S) DESCRIBED, AND NO WARRANTY IS MADE REGARDING ITS ACCURACY OR COMPLETENESS. USE OF THIS INFORMATION AND/OR PROGRAMS DESCRIBED IS AT YOUR OWN RISK.
ANY EASYLANGUAGE OR POWERLANGUAGE TRADING STRATEGIES, TRADING APPS, SIGNALS, STUDIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS (AND PARTS THEREOF) AND ASSOCIATED TECHNIQUES REFERRED TO, INCLUDED IN OR ATTACHED TO THIS TUTORIAL OR PROGRAM DESCRIPTION ARE EXAMPLES ONLY, AND HAVE BEEN INCLUDED SOLELY FOR EDUCATIONAL PURPOSES. MARKPLEX CORPORATION. DOES NOT RECOMMEND THAT YOU USE ANY SUCH TRADING STRATEGIES, SIGNALS, STUDIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS (OR ANY PARTS THEREOF) OR TECHNIQUES. THE USE OF ANY SUCH TRADING STRATEGIES, SIGNALS, STUDIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS AND TECHNIQUES DOES NOT GUARANTEE THAT YOU WILL MAKE PROFITS, INCREASE PROFITS, OR MINIMIZE LOSSES.