Update only once a minute

 

I´m a newbie to MT4, so there are a lot of features that I may miss...

Background:

I export all the quotes to a MySQL-database, when a new minute/bar occurs. But there is a problem...

If the new minute/bar tick will occur at 12:10:00 (HH:MM:SS) that would be perfect, but the new minute/tick could occur at 12:10:15, then I´m delayed by 15 seconds.

Because I´m lazy/smart/dumb?, I´ve done all the "export to MySQL" in ONE CHART with ONE SCRIPT to all the quotes (about 23 quotes). I have a rollover function that fixes "S&P500-SEP11" to "S&P500DEC" and so on (when it occurs).

Otherwise I could have a script for every chart and export every tick, then I shouldn´t have this problem. But because I´m in to futures and I don´t want to remove and apply my script everytime a rollover occur, I have to make a function that executes every new minute on second "00".

Right now I apply my Indicator/scipt on a forexchart "CHFJPY". I use this only because there is a lot of trading.

I could do a WHILE-loop (this works), but then MetaTrader freezes for 59.99 seconds every minute :)

My questions:

Is there a "Do Event" command in MetaTrader?

Is there a "Hey let´s do this waiting in another thread" and let MetaTrader work normally in the main thread?

I´ve been reading a lot of forums (and done some other programming) and my conclution is if I change my script from beeing and indicator to an EA (I know nothing about EA yet) and using "Sleep" it would freeze everyting like my WHILE-loop or is this a better way?

Is there a function for executing this chart/indicator or EA every minute on second "00" even though there is not tick?

Sorry for my poor language...

 
IntraTrade:


Is there a function for executing this chart/indicator or EA every minute on second "00" even though there is not tick?

Nope . . . MT4 is tick driven
 
IntraTrade:

I´m a newbie to MT4, so there are a lot of features that I may miss...


A new bar is starting with the first tick when there is no tick there is no new bar

so if there is no data at "00" then there is no "Do Event" command in MetaTrader

The CurrentTime of your broker is not displaying every second...

 
deVries:


A new bar is starting with the first tick when there is no tick there is no new bar

so if there is no data at "00" then there is no "Do Event" command in MetaTrader

The CurrentTime of your broker is not displaying every second...


Thank you for your replies...

But If I use for ex. "CHFJPY", there is a tick every minute (somewhere), then I could hold on to that tick and force MT4 to wait for a new minute. When a new minute begins I read all data for the previous minute (for all diffrent quotes) and Export it to MySQL. This works but MT4 freezes during my WHILE-loop and thats why I want to "Do Events" while waiting for a new minute.

I don´t use brokertime I use systemtime...

Any Ideas?

 
IntraTrade:


Thank you for your replies...

But If I use for ex. "CHFJPY", there is a tick every minute (somewhere),

Not always, sometimes there will be no ticks maybe for more than a minute . . other times there will be many ticks for each minute.
 
RaptorUK:
Not always, sometimes there will be no ticks maybe for more than a minute . . other times there will be many ticks for each minute.


Yes, But if I choose a symbol/quote with a high frequenze of trading, there will often be a tick somwhere during one the one minute period.

And when I get a tick:

currSec = (59 - (TimeLocal()-(TimeMinute(TimeLocal())*60)));
time_waiting = TimeLocal() + currSec;
while ( TimeLocal() <= time_waiting ) {
// Do Events...
}

// Reading all quotes and export to MySQL

 
IntraTrade:


Yes, But if I choose a symbol/quote with a high frequenze of trading, there will often be a tick somwhere during one the one minute period.

And when I get a tick:

currSec = (59 - (TimeLocal()-(TimeMinute(TimeLocal())*60)));
time_waiting = TimeLocal() + currSec;
while ( TimeLocal() <= time_waiting ) {
// Do Events...
}

// Reading all quotes and export to MySQL


But is there something I can use like a "Do Events" function or someting else preventing MT4 to freeze.
 
IntraTrade:


Yes, But if I choose a symbol/quote with a high frequenze of trading, there will often be a tick somwhere during one the one minute period.

Even on GBPJPY There can be missing minute bars, i.e. minutes with no ticks
 
IntraTrade:

But is there something I can use like a "Do Events" function or someting else preventing MT4 to freeze.
I believe there is something like that in MT5
 
RaptorUK:
I believe there is something like that in MT5


Do you have any experience with the "Sleep" function in a indicator and does it suspend everyting in MT4 or only the chart it is aplied on?

 
You can't use Sleep in an Indicator, only in an EA and Script. It only Sleeps the EA or Script it is called from.
Reason: