Hello,
I have a problem with the programming of arrays.
For example I would like to compare the current stochastic value
with the value one bar before. If the current value is greater, the
line shall be green, if it is smaller, it shall be red.
Unfortunately, the result isn't correct since it doesn't always
show the right color. This probably lies to it because the array is
filled with new values too early.
Who can tell me how I get a correct result?
Must I use an array or is there also a simpler solution?
Thanks
Guido
Here is my example code:
// --------------------------------------------
// $ColorStoch.efs
// --------------------------------------------
var study1 = new StochStudy(7, 3, 3);
arStoch_7 = new Array(2);
function preMain() {
setPriceStudy(false);
setStudyTitle("StochTest");
setDefaultBarFgColor(Color.blue);
setDefaultBarThickness(2);
}
function main() {
var vStoch_7 = study1.getValue(StochStudy.FAST);
var vTempStoch_7;
vTempStoch_7 = arStoch_7.unshift(vStoch_7); // get one element
if(arStoch_7[0] >= arStoch_7[1]) {
setBarFgColor(Color.green, 0);
} else if(arStoch_7[0] < arStoch_7[1]) {
setBarFgColor(Color.red, 0);
}
vTempStoch_7 = arStoch_7.pop(); // delete one element
return vStoch_7;
}
// --------------------------------------------
I have a problem with the programming of arrays.
For example I would like to compare the current stochastic value
with the value one bar before. If the current value is greater, the
line shall be green, if it is smaller, it shall be red.
Unfortunately, the result isn't correct since it doesn't always
show the right color. This probably lies to it because the array is
filled with new values too early.
Who can tell me how I get a correct result?
Must I use an array or is there also a simpler solution?
Thanks
Guido
Here is my example code:
// --------------------------------------------
// $ColorStoch.efs
// --------------------------------------------
var study1 = new StochStudy(7, 3, 3);
arStoch_7 = new Array(2);
function preMain() {
setPriceStudy(false);
setStudyTitle("StochTest");
setDefaultBarFgColor(Color.blue);
setDefaultBarThickness(2);
}
function main() {
var vStoch_7 = study1.getValue(StochStudy.FAST);
var vTempStoch_7;
vTempStoch_7 = arStoch_7.unshift(vStoch_7); // get one element
if(arStoch_7[0] >= arStoch_7[1]) {
setBarFgColor(Color.green, 0);
} else if(arStoch_7[0] < arStoch_7[1]) {
setBarFgColor(Color.red, 0);
}
vTempStoch_7 = arStoch_7.pop(); // delete one element
return vStoch_7;
}
// --------------------------------------------
Comment