Only run EA on new bar?

 

How do you run an EA only on a new bar? I've been running below but after reading the documentation, it obviously won't work.

if (Volume[0]) { return; } // since EA has already acted on this bar.

 

Use the following style:

datetime timeprev=0;

int start()

{

// your code on every tick like trailingstops etc can go here

if(timeprev==Time[0])

return(0);

timeprev=Time[0];

/// your code on new bar goes here

}

Reason: