I have been trying to develop an indicator that applies stochastics functions to bar sets for multiple timeframes. My approach has resulted in the correct values being returned and plotted, but values are returned only for a limited number of bars. For example, with the simplified version of the code shown below, the stochastic plot for the smallest tick interval (colored red) only extends partway through the study. Similarly, the plots for the higher tick values are also truncated farther along.
What is the best approach to be able to return values for a greater range of tick bars? Is there something I need to adjust in the timeframe definition? Something to adjust regarding memory allocation? Would it be beneficial to have the routines that produce the stochastic values external to the main efs script?
A simplified version of the code is shown below, along with an image of the study.
function preMain() {
setPriceStudy(false);
setStudyTitle("Multiple Stochastics");
setDefaultBarBgColor(Color.black);
setCursorLabelName("StochD0",0);
setCursorLabelName("StochD1",1);
setCursorLabelName("StochD2",2);
setCursorLabelName("StochD3",3);
setPlotType(PLOTTYPE_LINE,0);
setPlotType(PLOTTYPE_LINE,1);
setPlotType(PLOTTYPE_LINE,2);
setPlotType(PLOTTYPE_LINE,3);
setDefaultBarThickness(1,0);
setDefaultBarThickness(1,1);
setDefaultBarThickness(1,2);
setDefaultBarThickness(1,3);
setDefaultBarFgColor(Color.red,0);
setDefaultBarFgColor(Color.white,1);
setDefaultBarFgColor(Color.blue,2);
setDefaultBarFgColor(Color.green,3);
}
var aInterval = new Array(25,50,100,200);
var xStochK0 = null;
var xStochD0 = null;
var xStochK1 = null;
var xStochD1 = null;
var xStochK2 = null;
var xStochD2 = null;
var xStochK3 = null;
var xStochD3 = null;
var sInterval0 = aInterval[0] + "T";
var sInterval1 = aInterval[1] + "T";
var sInterval2 = aInterval[2] + "T";
var sInterval3 = aInterval[3] + "T";
function main() {
xStochK0 = stochK(14,1,3,inv(sInterval0));
xStochD0 = stochD(14,1,3,inv(sInterval0));
xStochK1 = stochK(14,1,3,inv(sInterval1));
xStochD1 = stochD(14,1,3,inv(sInterval1));
xStochK2 = stochK(14,1,3,inv(sInterval2));
xStochD2 = stochD(14,1,3,inv(sInterval2));
xStochK3 = stochK(14,1,3,inv(sInterval3));
xStochD3 = stochD(14,1,3,inv(sInterval3));
return new Array(xStochD0,xStochD1,xStochD2,xStochD3);
}
What is the best approach to be able to return values for a greater range of tick bars? Is there something I need to adjust in the timeframe definition? Something to adjust regarding memory allocation? Would it be beneficial to have the routines that produce the stochastic values external to the main efs script?
A simplified version of the code is shown below, along with an image of the study.
function preMain() {
setPriceStudy(false);
setStudyTitle("Multiple Stochastics");
setDefaultBarBgColor(Color.black);
setCursorLabelName("StochD0",0);
setCursorLabelName("StochD1",1);
setCursorLabelName("StochD2",2);
setCursorLabelName("StochD3",3);
setPlotType(PLOTTYPE_LINE,0);
setPlotType(PLOTTYPE_LINE,1);
setPlotType(PLOTTYPE_LINE,2);
setPlotType(PLOTTYPE_LINE,3);
setDefaultBarThickness(1,0);
setDefaultBarThickness(1,1);
setDefaultBarThickness(1,2);
setDefaultBarThickness(1,3);
setDefaultBarFgColor(Color.red,0);
setDefaultBarFgColor(Color.white,1);
setDefaultBarFgColor(Color.blue,2);
setDefaultBarFgColor(Color.green,3);
}
var aInterval = new Array(25,50,100,200);
var xStochK0 = null;
var xStochD0 = null;
var xStochK1 = null;
var xStochD1 = null;
var xStochK2 = null;
var xStochD2 = null;
var xStochK3 = null;
var xStochD3 = null;
var sInterval0 = aInterval[0] + "T";
var sInterval1 = aInterval[1] + "T";
var sInterval2 = aInterval[2] + "T";
var sInterval3 = aInterval[3] + "T";
function main() {
xStochK0 = stochK(14,1,3,inv(sInterval0));
xStochD0 = stochD(14,1,3,inv(sInterval0));
xStochK1 = stochK(14,1,3,inv(sInterval1));
xStochD1 = stochD(14,1,3,inv(sInterval1));
xStochK2 = stochK(14,1,3,inv(sInterval2));
xStochD2 = stochD(14,1,3,inv(sInterval2));
xStochK3 = stochK(14,1,3,inv(sInterval3));
xStochD3 = stochD(14,1,3,inv(sInterval3));
return new Array(xStochD0,xStochD1,xStochD2,xStochD3);
}