start of a new bar in m30 timeframe
iTime() returns a datetime variable . .
datetime M30Bar1Time; if(iTime(NULL, PERIOD_M30, 1) != M30Bar1Time) { // we have a new M30 bar . . . . M30Bar1Time = iTime(NULL, PERIOD_M30, 1); }
get fulfilled ....i have to be alerted only once when new bar forms..
it keeps on repeating..ie with each tick the condition if(iTime(NULL, PERIOD_M30, 1) != M30Bar1Time)
datetime M30Bar1Time; if(iTime(NULL, PERIOD_M30, 1) != M30Bar1Time) { // we have a new M30 bar . . . . M30Bar1Time = iTime(NULL, PERIOD_M30, 1); }
IFF M30Bar1Time is static or common (global scope) that will identify the start of a new M30 bar- Also you can compute directly:
static datetime timeM30; datetime now = TimeCurrent(), tM30= now - now % 1800; if (timeM30 == tM30) return; timeM30 = tM30; // start of a new M30 bar.
- If you want to identify the start of a new candle on the chart time frame:
static datetime time0; if (time0 == Time[0]) return; time0 = Time[0]; // start of a new bar.
iTime() returns a datetime variable . .
int start() { datetime M30Bar1Time; if(iTime(NULL, PERIOD_M30, 1) != M30Bar1Time) { Alert(" we have a new M30 bar . . . ."); M30Bar1Time = iTime(NULL, PERIOD_M30, 1); } return(0); }
see with each tick it gives an alert "new bar formation"

see with each tick it gives an alert "new bar formation"
You were meant to read what I posted and understand it before using it . . . this should be a globally declared variable . . . not local to start()
datetime M30Bar1Time;
You were meant to read what I posted and understand it before using it . . . this should be a globally declared variable . . . not local to start()
u wont told me to declare it globally.i was following your post..anyways the problems being solved.
u wont told me to declare it globally.i was following your post..anyways the problems being solved.
I didn't tell you to copy and paste my code directly into start() either but you took the decision to do it, take responsibility for "your" code. If I told you to add this to your code and follow the instructions in every Alert it made would you ?
Alert("Hurry, the end of the world is today, find a cliff and jump ! ! ! !");
The important thing is that you understand why the code that you used did what it did . . . . do you understand why using a globally declared variable fixes the problem ? do you know what a static variable is ?
iTime() returns a datetime variable . .
sir this condition executes 2 -3 times during a bar formation....wat to do??
hello all,
just wanna know how to identify start of new candle in mq4 ..seen itime but can't understand it what value it returns.