How to take action only when next bar appears?
R
Something like this
static datetime LastTradeBarTime; int init() { //---- LastTradeBarTime = Time[1]; // initialise the variable //---- return(0); } start() { // Do <any tick> code here such as trailing stops etc if (LastTradeBarTime == Time[0]) return(0); // Not <first detected tick> on this bar so quit else LastTradeBarTime = Time[0]; // and continue // Do <once per bar> trading stuff here return (0); }
Good Luck
-BB-
int start() { static datetime Time.newBar; bool newbar = Time[0] > Time.newBar; Time.newBar=Time[0]; ...
Hi to all! I'm probably overlooking a simple bit of code for this, but missing it.
How would I write the code an action to take place only when a new bar appears (like waiting for a bar to close at 11:00 and for the new 12:00 to appear)?
For example, wanting two moving averages to cross, but since you don't know they'll really cross until the bar closes and new one appears, how would you write the code to for both conditions? I was thinking an AND statement?
Thanks.