Hi,
As I understand it anything within:
if(getBarState()==BARSTATE_NEWBAR){code}
should only execute on the first tick of a new bar but when I run the code below it plots a red circle above all candles even if I preceed it with:
if(getBarState()==BARSTATE_ALLBARS){return;}
Am I missing something?
Only if I include -getCurrentBarIndex() == 0- as a condition does it then execute only on new bars, i.e.,:
if(getBarState()== BARSTATE_NEWBAR && getCurrentBarIndex() == 0){code}
Thanks in advance.
This is my test code:
Wayne
As I understand it anything within:
if(getBarState()==BARSTATE_NEWBAR){code}
should only execute on the first tick of a new bar but when I run the code below it plots a red circle above all candles even if I preceed it with:
if(getBarState()==BARSTATE_ALLBARS){return;}
Am I missing something?
Only if I include -getCurrentBarIndex() == 0- as a condition does it then execute only on new bars, i.e.,:
if(getBarState()== BARSTATE_NEWBAR && getCurrentBarIndex() == 0){code}
Thanks in advance.
This is my test code:
PHP Code:
function preMain(){
setPriceStudy(true);
}
var Cntr = 0;
function main() {
var nState = getBarState();
if(nState == BARSTATE_ALLBARS ) return;
// else if(nState == BARSTATE_NEWBAR && getCurrentBarIndex() == 0){
else if(nState == BARSTATE_NEWBAR){
drawShapeRelative( 0, high(0), Shape.CIRCLE, null, Color.red, Shape.TOP | Shape.ONTOP );
}
}
This is what plots on the chart:
Comment