I am creating a cross correlation matrix from the symbols in a watch list . I use Foreign to get one side of the list but the obtained symbols are not in the same order as read by the AFL. What I would like to do is null out the bottom left half of the matrix because it is a duplicate of the top right half. I have marked the IF command that would do this in the code below but it does not work because the symbols are not in the same order. Does someone have a suggestion?
// This routine prints the Cross Correlation Matrix
// The correlation is the last bars in the date range
// Symbols to be correlated are place in the watch list referenced in the
// CategoryFind command below
//IAListNum = CategoryFind("Inter-Asset Corr",categoryWatchlist);
IAListNum = CategoryFind("T2",categoryWatchlist);
// To run open in an Analysis window
// Select "Apply to" Filter and select the Watch list with the symbols
// You are now pointing to the watch list twice. Once with the find and second with the filter.
// Select date range
// Run as Explore
x = Cum(1);
FBIR = Status("firstbarinrange");
LBIR = Status("Lastbarinrange");
StartRange = LastValue(ValueWhen(FBIR == 1,X)) - 1;
EndRange = LastValue(ValueWhen(LBIR == 1,X)) - 1;
RangeLen = (EndRange - StartRange) +1;
IAlist = CategoryGetSymbols( categoryWatchlist, IAListNum ); // Point to watch list with ETF from artical
Filter = Status( "lastbarinrange" );
SN = Status("StockNum");
for ( n1 = 0; ( SymbolB = StrExtract( IAList, n1 ) ) !=""; n1++)
{
_TRACE("SymB: " + SN + " " + Name() + " SymL: " + n1 + " " + SymbolB);
FrClose = Foreign(SymbolB,"Close");
_TRACE("BSymB: " + SN + " " + Name() + " SymL: " + n1 + " " + SymbolB);
Cor = Correlation(Close,FrClose,RangeLen);
Clr = IIf(Cor >= .70,colorAqua,colorWhite);
Clr = IIf(Cor <= -.70,colorRed,Clr);
Clr = IIf(Cor == 1,colorYellow,Clr);
Txt = NumToStr(SN) + " " + NumToStr(n1);
//if(EndRange > 0 AND SN < n1){ ///<<<<< SN - Stock Number n1 - number of symbol from Foreign
if(EndRange > 0 ){
AddColumn(Cor[EndRange],SymbolB,1.2,colorBlack,Clr);
AddtextColumn(txt,"Ind");
}
}
SetSortColumns( 1 );