GM
static datetime lastbar; init() { lastbar=Time[1]; return (0); } start () { //----------- Do every tick stuff here //----------- Do once-per-bar stuff here if (IsNewBar()) { // Do new bar stuff } return (0); } bool IsNewBar() { datetime curbar = Time[0]; // Open time of current bar if (lastbar!=curbar) { lastbar=curbar; return (true); } return(false); }
Good Luck
int start(){ static datetime Time0; if (Time0 == Time[0]) return(0); Time0=Time[0]; ...
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi,
I want to open/close trades only at the first tick of new bar, how can I write the condition? thanks.