Detecting new bar (Indicator / EA?)

 

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.

 
Nightmasks:
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;

}

Nightmasks:

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

Nightmasks:

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

 
Nightmasks:
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():

double iClose( string symbol, int timeframe, int shift),[/CODE]

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.

 
 
Kalenzo:
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

Kale

We answered simultaniously with Kalenzo.

So forget about my answer as i am not a coder.

 
codersguru:
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!

 

Thanks for all the help - that's excellent. I learned heaps today.

Also, the TimeMinute & other Time* functions solved my formatting fo specific bar. I wrote a simple format function using these.

 
codersguru:
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..

 
cubesteak:
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..
You're welcome cubesteak! I have good news for you I've written 2 parts in the subjected you have requested:

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!

 
codersguru:
You're welcome cubesteak! I have good news for you I've written 2 parts in the subjected you have requested:

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:

http://forum.mql4.com/3880

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*

Reason: