Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 183

 
gince:


Thank you all for your help.

The question was this.

<There is a function called NewBar(sy, TF). It looks if a new bar has opened. I want to get a signal on hourly chart about the appearance of a new bar with a 5 min lag. That is, I want to get a signal at 0.05, 1.05, 2.05, ..........., 10.05, 11.05, etc. >

To clarify the question. The function should return true every hour, but with a delay of 5 min. I.e. when the formation of the bar 1.05 is over and the bar 2.05 appears, the function returns true when the latter appears. The function returns true when the bar appears at 1.10, 2.10, etc.

In the picture the yellow line shows that the next bar was true .

Following your tip I tried it this way but it does not work.


It immediately struck me that the types are not right:

static int  LastBar = 0; 
datetime    curbar = iTime (Symbol(), 60, 0) +300; 

And then comparing them and assigning values... int to datetime

 

I've just written it by hand. You can get the gist of it, and it's all right as far as it goes.

bool IsTrueBar ()
{
    static datetime LastTrueBar = 0;
    datetime OOT, CurBar, ShiftFromOOT;
//----    
    OOT = iTime (Symbol(), PERIOD_H1, 0);   // Время открытия часовик
    CurBar = OOT + ShiftFromOOT;            // Время открытия со сдвигом
    
    if (LastTrueBar != CurBar)
    {
        LastTrueBar = CurBar;
        return(true);
    }
    else return (false);
}
 

What's all the fuss about... Here every fifth minute of the hour returns TRUE and holds it for one minute:

bool NewBar(){
 if(Minute()==5)return(true);
 else return(false);
}
 
Integer:


int bt=((TimeCurrent()-5*60)/3600)*3600;

The bt value will change at 5 minutes of each hour. It is possible not to multiply by 3600 at the end, it will be the bar number from the beginning of the epoch, this is enough to define a new bar.


Missed. If multiplied by 3600 at the end, then also add back the 5*60 correction.

 
Sepulca:

What's all the fuss about... Here every fifth minute of the hour returns TRUE and holds it for one minute:


I mean, really, and we're making a smart-ass of ourselves here...
 
Integer:


Missed. If multiplied by 3600 at the end, then also add back the 5*60 correction.


It's a bit wrapped up and unreadable. I get the point though.
 
hoz:


It immediately struck me that the types are wrong:

And then compare them and assign the values... int to datetime

int and datetime are the same type.
 
Sepulca:

What's all the fuss about... Here every fifth minute of the hour returns TRUE and holds it for one minute:

During this minute the advisor will open up to forty orders for him.
 
Roger:
In that minute, the advisor will open up to forty orders for him.


This is the way to control...either the number of orders or just the first call to the function...
 
Roger:
During this minute, the Expert Advisor will open up to forty orders.

And if the first one will not open? Wait for the next signal for an hour? It is ok:

There is a signal --> Check if there is an order/position set/open on this candlestick, there is no --> set/open, there is --> then there is no need for more.