getBarState()
getBarState()
Returns a status flag from the Formula Engine indicating the bar processing that is currently taking place.
One of 3 flags can be returned:
BARSTATE_ALLBARS
BARSTATE_NEWBAR
BARSTATE_CURRENTBAR
Examples:
nState = getBarState();
if (nState == BARSTATE_ALLBARS) {
//the bars are being loaded by the script. This happens when a script is first loaded
debugPrint("Script is loading\n");
}
else if (nState == BARSTATE_NEWBAR) {
//this flag is set when a new bar is coming in
debugPrint("The first tick of a new bar has arrived\n");
}
else if (nState == BARSTATE_CURRENTBAR) {
//this flag is set as each new tick comes in
debugPrint("A new tick has arrived\n");
}
Some typical usages would be to use the BARSTATE_ALLBARS flag to initialize some data when the script first loads:
if (getBarState() == BARSTATE_ALLBARS) {
sSymbol = getSymbol(); //grab the name of the symbol being charted for later use
nInterval = getInterval(); //grab the bar interval we are using for later use
return;
}
or to cycle an array when a new bars comes in....
if (getBarState() == BARSTATE_NEWBAR) {
myArray.unshift(0);
myArray.pop();
}