Hi,
I copied a sample script from another post, then modified it to help me calculate and plot the differences of two stock's 4-day return.
It seems to be working. However, the script stops plotting at Bar Index -668.
I tested with other stocks, the location that the script stops plotting is different for different stocks.
What did I do wrong?
Can anyone help me solve this problem? Thanks
function preMain() {
setCursorLabelName("Ratio");
setStudyTitle("Ratio");
var fp1 = new FunctionParameter("Sym1", FunctionParameter.STRING);
fp1.setName("Symbol1");
fp1.setDefault("SPY");
var fp2 = new FunctionParameter("Sym2", FunctionParameter.STRING);
fp2.setName("Symbol2");
fp2.setDefault("QQQ");
}
function main(Sym1, Sym2) {
var vSymbol1 = getValue("Close", 0, Sym1);
var vSymbol14 = getValue("Close", -4, Sym1);
var vSymbol2 = getValue("Close", 0, Sym2);
var vSymbol24 = getValue("Close", -4, Sym2);
var vRatio1 = (vSymbol1 - vSymbol14)/vSymbol14*100;
var vRatio2 = (vSymbol2 - vSymbol24)/vSymbol24*100;
var vRatio = vRatio1 - vRatio2;
return vRatio;
}
I copied a sample script from another post, then modified it to help me calculate and plot the differences of two stock's 4-day return.
It seems to be working. However, the script stops plotting at Bar Index -668.
I tested with other stocks, the location that the script stops plotting is different for different stocks.
What did I do wrong?
Can anyone help me solve this problem? Thanks
function preMain() {
setCursorLabelName("Ratio");
setStudyTitle("Ratio");
var fp1 = new FunctionParameter("Sym1", FunctionParameter.STRING);
fp1.setName("Symbol1");
fp1.setDefault("SPY");
var fp2 = new FunctionParameter("Sym2", FunctionParameter.STRING);
fp2.setName("Symbol2");
fp2.setDefault("QQQ");
}
function main(Sym1, Sym2) {
var vSymbol1 = getValue("Close", 0, Sym1);
var vSymbol14 = getValue("Close", -4, Sym1);
var vSymbol2 = getValue("Close", 0, Sym2);
var vSymbol24 = getValue("Close", -4, Sym2);
var vRatio1 = (vSymbol1 - vSymbol14)/vSymbol14*100;
var vRatio2 = (vSymbol2 - vSymbol24)/vSymbol24*100;
var vRatio = vRatio1 - vRatio2;
return vRatio;
}
Comment