I'm new to this, but want to know what might be wrong with this script. Most of the time it seems to work, but then i get a false positive: a candlestick is designated as have a wider body then the previous 3, when in fact one of the previous 3 has an equal body height. This error does not occur for body heights greater or less than.
Any help detecting the error appreciated
// Test for whether a candlestick has wider body range than the previous three candlesticks
// This test is performed on whichever candlestick the cursor is placed
var vLastAlert = -1;
var o;
var c;
var BodyHeight;
var prevBodyHeight1;
var prevBodyHeight2;
var prevBodyHeight3;
function preMain() {
setPriceStudy(true);
setStudyTitle("WRB");
setCursorLabelName("WRB =", 0);
}
function main() {
c=close();
o=open();
BodyHeight=Math.abs(c-o);
prevBodyHeight1=Math.abs(close(-1)-open(-1));
prevBodyHeight2=Math.abs(close(-2)-open(-2));
prevBodyHeight3=Math.abs(close(-3)-open(-3));
onAction1();
if (
BodyHeight>prevBodyHeight1 &&
BodyHeight>prevBodyHeight2 &&
BodyHeight>prevBodyHeight3
)
return "YES";
}
function postMain() {
/**
* The postMain() function is called only once, when the EFS is no longer used for
* the current symbol (ie, symbol change, chart closing, or application shutdown).
*/
}
function onAction1() {
vLastAlert = 1;
}
Any help detecting the error appreciated
// Test for whether a candlestick has wider body range than the previous three candlesticks
// This test is performed on whichever candlestick the cursor is placed
var vLastAlert = -1;
var o;
var c;
var BodyHeight;
var prevBodyHeight1;
var prevBodyHeight2;
var prevBodyHeight3;
function preMain() {
setPriceStudy(true);
setStudyTitle("WRB");
setCursorLabelName("WRB =", 0);
}
function main() {
c=close();
o=open();
BodyHeight=Math.abs(c-o);
prevBodyHeight1=Math.abs(close(-1)-open(-1));
prevBodyHeight2=Math.abs(close(-2)-open(-2));
prevBodyHeight3=Math.abs(close(-3)-open(-3));
onAction1();
if (
BodyHeight>prevBodyHeight1 &&
BodyHeight>prevBodyHeight2 &&
BodyHeight>prevBodyHeight3
)
return "YES";
}
function postMain() {
/**
* The postMain() function is called only once, when the EFS is no longer used for
* the current symbol (ie, symbol change, chart closing, or application shutdown).
*/
}
function onAction1() {
vLastAlert = 1;
}
Comment