Welcome!
question: how do you write an "if" function that triggers code at the END of each bar on the chart (which works independent of chart timeframe)?
murky waters,
Welcome to our forum!
Test this code:
{
static bool first_call = true;
static int start_bar = 0;
if(first_call)
{
start_bar=Bars;
first_call=false;
}
if(Bars == (start_bar+1))
{
first_call=true;
return (true);
}
else
{
return (false);
}
}
int start() //<-- in your start function you may use code like this
{
if (NewBar)
{
//do something
}
return (0);
}Really great job
Hi coderguru,
Your are really doing a gr8 job here . Keep up good works
Great Code
Thanks Codersguru
You help me greatly
Another Way
I prefer to use this solution for finding new Bars
{
static datetime LastTime;
if (LastTime != Time[0])
{
LastTime = Time[0];
return(true);
}
return(false);
}it's seems to be shorter
I prefer to use this solution for finding new Bars
{
static datetime LastTime;
if (LastTime != Time[0])
{
LastTime = Time[0];
return(true);
}
return(false);
}
Yes this is good one!
Yes this is good one!
thank u codersguru, i had read all of your MQL4 tutorial, its very good, i finished it 2 weeks ago
thanks a lot

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
question: how do you write an "if" function that triggers code at the END of each bar on the chart (which works independent of chart timeframe)?