/********************************************************* Alexis C. Montenegro © September 2005 Use and/or modify this code freely. If you redistribute it please include this and/or any other comment blocks and a description of any changes you make. **********************************************************/ var fpArray = new Array(); function preMain(){ setPriceStudy(false); setStudyTitle("Correlation"); setCursorLabelName("Corr"); setPlotType(PLOTTYPE_LINE); setDefaultBarFgColor(Color.blue); var x=0; fpArray[x] = new FunctionParameter("Symbol1", FunctionParameter.STRING); with(fpArray[x++]){ setDefault(); } fpArray[x] = new FunctionParameter("Symbol2", FunctionParameter.STRING); with(fpArray[x++]){ setDefault("$INDU"); } fpArray[x] = new FunctionParameter("Source", FunctionParameter.STRING); with(fpArray[x++]){ addOption("open"); addOption("high"); addOption("low"); addOption("close"); addOption("hl2"); addOption("hlc3"); addOption("ohlc4"); setDefault("close"); } fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER); with(fpArray[x++]){ setLowerLimit(1); setDefault(25); } fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN); with(fpArray[x++]){ setName("Show Parameters"); setDefault(true); } } var bInit = false; var Ind = null; var Dep = null; function main(Symbol1,Symbol2,Source,Length,Params){ if(bInit==false){ if(Symbol1==null) Symbol1 = getSymbol(); Ind = eval(Source)(sym(Symbol1)); Dep = eval(Source)(sym(Symbol2)); addBand(0,PS_SOLID,1,Color.black,"0"); setShowTitleParameters(eval(Params)); bInit=true; } var Counter1 = 0; var Counter2 = 0; var Correlation = 0; for (var i=0; i=Ind.getValue(-(i+1)) && Dep.getValue(-i)>=Dep.getValue(-(i+1)) || Ind.getValue(-i)0){ Correlation = (Counter1 - Counter2) / (Counter1 + Counter2) } else { Correlation = 0; } return Correlation; }