dear coders - a small request!
in the below code for correlation can we add exploration which gives correlation values against the base ticker by exploring a watchlist?
in the below code for correlation can we add exploration which gives correlation values against the base ticker by exploring a watchlist?
Code:
_SECTION_BEGIN("Historical Correlaion");
symbol = ParamStr("Correlation ticker", GetBaseIndex() );
fc = Foreign( symbol, "C" );
Plot( Correlation(C,fc,60), _SECTION_NAME() + "(" + symbol + ")", ParamColor( "color", colorCycle ), ParamStyle("Style") );
_SECTION_END();
And in correlation function you change C array to Close of baseindex. Just compare the codes.
Not tested but should work. Set "Apply to" to "Current".
Code:
WLNum = Param( "WatchList Number", 0, 0, 64, 1 );
CorrPd = Param( "Correlation Period", 8, 1, 30, 1 );
list = CategoryGetSymbols( categoryWatchlist, WLNum );
SetOption( "NoDefaultColumns", True );
Filter = Status( "LastBarInRange" );
Ticker1 = GetBaseIndex();
Ticker1Close = Foreign( Ticker1, "C" );
SetSortColumns( 1 );
AddTextColumn(Ticker1, "Correlation", 1.0 );
for ( Col = 0; ( Ticker2 = StrExtract( List, Col ) ) != ""; Col++ )
{
Var2 = Foreign( Ticker2, "C" );
Corr = Correlation( Ticker1Close, Var2, CorrPd );
Color = IIf( Corr > 0, colorBrightGreen, IIf( Corr < 0, colorRed, colorWhite ) );
Color = IIf( Ticker1 == Ticker2, 1, Color );
AddColumn( Nz(Corr), Ticker2, 1.3, 1, Color );
}
Last edited: