Hi,
here's the explanation.
This piece of code is equivalent to the following:
static datetime prevtime=0; // previously recorded time of current bar; static(!) variable, such that value is remembered on successive calls ... if (prevtime != Time[0]) { // are we in a new bar? prevtime = Time[0]; // remember new time ... // perform the calculations we want to } else { return(0); // do nothing }
If nothing follows the if-expression you can actually leave out the else-clause
static datetime prevtime=0; // previously recorded time of current bar; static(!) variable, such that value is remembered on successive calls ... if (prevtime != Time[0]) { // are we in a new bar? prevtime = Time[0]; // remember new time ... // perform the calculations we want to }
So if the start time of the current bar (Time[0]) changes, you do something, otherwise you don't.
Hope this helps!
Cheers!
Max
int bars;
int Start()
{
if (Bars>bars)
{
...;
...;
bars=Bars;
}
}
int Start()
{
if (Bars>bars)
{
...;
...;
bars=Bars;
}
}
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register