I need to detect when the new bar for any timeframe commences and then put out an alert if a certain condition is met. I am new to this and just completed my first indicator but my alerts occur for every tick.
define lastBar before Start function and in the start function check:
if(Bars>lastBar)
{
alert me
lastBar = Bars;
}
Also, how do I return a specific bar's commencing server or local time. Does each bar have a time "label"?
Yes, u can use Time[] array or iTime() function
The documentation tells me how to get current time in seconds since 1970 and there are functions to extract components such as hour or day. Is there any function that can convert to a specified format?
All help appreciated.To what format do u want to convert it? It returns standard timestamp, and as we know timestamp can be converted to any format as u wish.
Regards
Kale
I need to detect when the new bar for any timeframe commences and then put out an alert if a certain condition is met. I am new to this and just completed my first indicator but my alerts occur for every tick.
Also, how do I return a specific bar's commencing server or local time. Does each bar have a time "label"?
The documentation tells me how to get current time in seconds since 1970 and there are functions to extract components such as hour or day. Is there any function that can convert to a specified format?
All help appreciated.You may use iClose():
where shift is number of bar starting from 0 (curent bar).
Or indicator/EA may look back to some bars to search the condition:
[CODE] int limit;
int counted_bars=IndicatorCounted();
if(counted_bars<0) counted_bars=0;
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//----
for(int i = 0 ;i < limit ;i++)
{
double f1u = iCustom(...,i);
double f2u = iCustom(...,i+1);So if you want to find the bar in the history which meets your condition so it is not difficult.
If you know the time for the bar (11:00 GMT for example) and you want to find condition for that bar so I don't know.
it's here too
define lastBar before Start function and in the start function check:
if(Bars>lastBar)
{
alert me
lastBar = Bars;
}
Yes, u can use Time[] array or iTime() function
To what format do u want to convert it? It returns standard timestamp, and as we know timestamp can be converted to any format as u wish.
Regards
KaleWe answered simultaniously with Kalenzo.
So forget about my answer as i am not a coder.
I'm wrirint right now an article about "New Bar Mystery" at: http://www.metatrader.info/node/151 Hope it clears the idea!
Great! Once and for all
New Bar Mystery
I'm writing right now an article about "New Bar Mystery" at: http://www.metatrader.info/node/151
Hope it clears the idea!
I'm writing right now an article about "New Bar Mystery" at: http://www.metatrader.info/node/151 Hope it clears the idea!
Hey, I could have really used that about a week ago! At least now I know my conclusions were right!
WOOOT! Thanks for the excellent info, as always cg..
Hey, I could have really used that about a week ago! At least now I know my conclusions were right! WOOOT!


Create your own MetaTrader extension (dll) - Part 1
Create your own MetaTrader extension (dll) - Part 2
There'll be another part (or 2) which I'm writing them!
Hope you enjoy them!
Create your own MetaTrader extension (dll) - Part 1
Create your own MetaTrader extension (dll) - Part 2
There'll be another part (or 2) which I'm writing them!
Hope you enjoy them!OH YOU SOOOOOOOOO ROCK!!!!!
This is extremely helpful!!
If you are looking for another challenge, check out:
I've been trying to use a vb.net / C# library with MT4 by using a managed C++ wrapper. So far, I can get the managed wrapper up just fine, but it craps out when trying to access the vb.net. *SNAP*

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I need to detect when the new bar for any timeframe commences and then put out an alert if a certain condition is met. I am new to this and just completed my first indicator but my alerts occur for every tick.
Also, how do I return a specific bar's commencing server or local time. Does each bar have a time "label"?
The documentation tells me how to get current time in seconds since 1970 and there are functions to extract components such as hour or day. Is there any function that can convert to a specified format?
All help appreciated.