I just found that for some reason it seems using sym() and getValue() can not align data quotes correctly in realtime. To illustrate what problem I ran into, I wrote a testing script.
Run it on any one of "YM H7,1", "ES H7,1", "NQ,1" or "AB H7" and wait for a few minutes. The script will only print out the first abnormal instance it found.
The attached sample screenshot was captured when the script was running on "YM H7,1" At the moment of the beginning of the bar at 12:27, the quotes of the open and close prices of the
bar at 12:25 was returned as that of bar 12:26.
Only interesting thing is that in the case of setComputeOnClose(), the similar method always returns the correct values (in stead of returning one bar shifted values in some cases as shown in my attached example.
Anyone knows what is the reason and if it is really a bug in EFS2, is there a work around fix?
//************************************************** *
// Script Name: sym_testing.efs
//************************************************** *
var symbols;
var bInit;
var aOpen, aClose;
var n;
var found = false;
function preMain() {
setPriceStudy(false);
setStudyTitle("ATS_sym_testing");
setShowCursorLabel(false);
}
function main( ) {
var i, j;
if ( getBarState() == BARSTATE_ALLBARS ) {
setStudyMax(100);
setStudyMin(0);
symbols = new Array(4);
symbols[0] = "ES H7";
symbols[1] = "YM H7";
symbols[2] = "AB H7";
symbols[3] = "NQ H7";
for ( i = 0; i < symbols.length; i ++ ) {
var S = getSymbol();
var S2 = symbols[i].substring(0, 2);
if ( S.indexOf(S2) == 0 ) {
n = i;
}
}
bInit = false;
if ( bInit == false ) {
bInit = true;
aOpen = new Array(symbols.length);
aClose = new Array(symbols.length);
for ( i = 0; i < symbols.length; i ++ ) {
aClose[i] = close(sym(symbols[i]));
aOpen[i] = open(sym(symbols[i]));
//debugPrintln(aOpen[i].getValue(0));
}
}
}
if ( getBarState() == BARSTATE_NEWBAR && getCurrentBarIndex() == 0 ) {
if ( found == false ) {
var h = hour(-1);
var m = minute(-1);
for ( i = 0; i < symbols.length; i ++ ) {
if ( found == false ) {
var o = aOpen[i].getValue(-1);
var c = aClose[i].getValue(-1);
var H = getValueAbsolute("Hour", 0, -3, symbols[i]+",1");
var M = getValueAbsolute("Minute", 0, -3, symbols[i]+",1");
var O = getValueAbsolute("Open", 0, -3, symbols[i]+",1");
var C = getValueAbsolute("Close", 0, -3, symbols[i]+",1");
if ( M[0] == m ) {
if ( O[0] != o || C[0] != c ) {
found = true;
if ( O[1] == o && C[1] == c ) {
debugPrintln(symbols[i] + " " + h + ":" + m + " actual quotes: c = " + C[0].toFixed(2) +" o = " + O[0].toFixed(2) + " sym results: c = " + c.toFixed(2) + " o = " + o.toFixed(2) + ", which are equal to quotes at " + H[1]+ ":"+M[1]);
}
else {
debugPrintln(symbols[i] + " " + h + ":" + m + " actual quotes: c = " + C[0].toFixed(2) +" o = " + O[0].toFixed(2) + " sym results: c = " + c.toFixed(2) + " o = " + o.toFixed(2) );
}
}
}
else if ( M[1] == m ) {
if ( O[1] != o || C[1] != c ) {
found = true;
if ( O[2] == o && C[2] == c ) {
debugPrintln(symbols[i] + " " + h + ":" + m + " actual quotes: c = " + C[1].toFixed(2) +" o = " + O[1].toFixed(2) + " sym results: c = " + c.toFixed(2) + " o = " + o.toFixed(2) + ", which are equal to quotes at " + H[2]+ ":"+M[2]);
}
else if ( O[0] == o && C[0] == c ) {
debugPrintln(symbols[i] + " " + h + ":" + m + " actual quotes: c = " + C[1].toFixed(2) +" o = " + O[1].toFixed(2) + " sym results: c = " + c.toFixed(2) + " o = " + o.toFixed(2) + ", which are equal to quotes at " + H[0]+ ":"+M[0]);
}
else {
debugPrintln(symbols[i] + " " + h + ":" + m + " actual quotes: c = " + C[1].toFixed(2) +" o = " + O[1].toFixed(2) + " sym results: c = " + c.toFixed(2) + " o = " + o.toFixed(2) );
}
}
}
}
}
debugPrintln(" ");
}
}
}
//************************************************** *
// End of the script
//************************************************** *
Run it on any one of "YM H7,1", "ES H7,1", "NQ,1" or "AB H7" and wait for a few minutes. The script will only print out the first abnormal instance it found.
The attached sample screenshot was captured when the script was running on "YM H7,1" At the moment of the beginning of the bar at 12:27, the quotes of the open and close prices of the
bar at 12:25 was returned as that of bar 12:26.
Only interesting thing is that in the case of setComputeOnClose(), the similar method always returns the correct values (in stead of returning one bar shifted values in some cases as shown in my attached example.
Anyone knows what is the reason and if it is really a bug in EFS2, is there a work around fix?
//************************************************** *
// Script Name: sym_testing.efs
//************************************************** *
var symbols;
var bInit;
var aOpen, aClose;
var n;
var found = false;
function preMain() {
setPriceStudy(false);
setStudyTitle("ATS_sym_testing");
setShowCursorLabel(false);
}
function main( ) {
var i, j;
if ( getBarState() == BARSTATE_ALLBARS ) {
setStudyMax(100);
setStudyMin(0);
symbols = new Array(4);
symbols[0] = "ES H7";
symbols[1] = "YM H7";
symbols[2] = "AB H7";
symbols[3] = "NQ H7";
for ( i = 0; i < symbols.length; i ++ ) {
var S = getSymbol();
var S2 = symbols[i].substring(0, 2);
if ( S.indexOf(S2) == 0 ) {
n = i;
}
}
bInit = false;
if ( bInit == false ) {
bInit = true;
aOpen = new Array(symbols.length);
aClose = new Array(symbols.length);
for ( i = 0; i < symbols.length; i ++ ) {
aClose[i] = close(sym(symbols[i]));
aOpen[i] = open(sym(symbols[i]));
//debugPrintln(aOpen[i].getValue(0));
}
}
}
if ( getBarState() == BARSTATE_NEWBAR && getCurrentBarIndex() == 0 ) {
if ( found == false ) {
var h = hour(-1);
var m = minute(-1);
for ( i = 0; i < symbols.length; i ++ ) {
if ( found == false ) {
var o = aOpen[i].getValue(-1);
var c = aClose[i].getValue(-1);
var H = getValueAbsolute("Hour", 0, -3, symbols[i]+",1");
var M = getValueAbsolute("Minute", 0, -3, symbols[i]+",1");
var O = getValueAbsolute("Open", 0, -3, symbols[i]+",1");
var C = getValueAbsolute("Close", 0, -3, symbols[i]+",1");
if ( M[0] == m ) {
if ( O[0] != o || C[0] != c ) {
found = true;
if ( O[1] == o && C[1] == c ) {
debugPrintln(symbols[i] + " " + h + ":" + m + " actual quotes: c = " + C[0].toFixed(2) +" o = " + O[0].toFixed(2) + " sym results: c = " + c.toFixed(2) + " o = " + o.toFixed(2) + ", which are equal to quotes at " + H[1]+ ":"+M[1]);
}
else {
debugPrintln(symbols[i] + " " + h + ":" + m + " actual quotes: c = " + C[0].toFixed(2) +" o = " + O[0].toFixed(2) + " sym results: c = " + c.toFixed(2) + " o = " + o.toFixed(2) );
}
}
}
else if ( M[1] == m ) {
if ( O[1] != o || C[1] != c ) {
found = true;
if ( O[2] == o && C[2] == c ) {
debugPrintln(symbols[i] + " " + h + ":" + m + " actual quotes: c = " + C[1].toFixed(2) +" o = " + O[1].toFixed(2) + " sym results: c = " + c.toFixed(2) + " o = " + o.toFixed(2) + ", which are equal to quotes at " + H[2]+ ":"+M[2]);
}
else if ( O[0] == o && C[0] == c ) {
debugPrintln(symbols[i] + " " + h + ":" + m + " actual quotes: c = " + C[1].toFixed(2) +" o = " + O[1].toFixed(2) + " sym results: c = " + c.toFixed(2) + " o = " + o.toFixed(2) + ", which are equal to quotes at " + H[0]+ ":"+M[0]);
}
else {
debugPrintln(symbols[i] + " " + h + ":" + m + " actual quotes: c = " + C[1].toFixed(2) +" o = " + O[1].toFixed(2) + " sym results: c = " + c.toFixed(2) + " o = " + o.toFixed(2) );
}
}
}
}
}
debugPrintln(" ");
}
}
}
//************************************************** *
// End of the script
//************************************************** *
Comment