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

 
hoz:

Well, I removed the #property library, but there was no warning, while there is no start function...

Warnings about what?
 
Vinin:

Warnings about what?


What about... Here:

sergeev:
you need it if you don't want to see warnings about a missing start

 
gince:

Hello.

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


How can this be done ? Is it possible to modify the function itself?


You declare it globally:

datetime = bdt_lastBarTime;

IN INIT:

bdt_lastBarTime = 0;

IN START:

if (g_lastBarTime == Time[0])         // На текущем баре все необходимые действия..
       return (0);                    // ..уже были выполнены

// если ...
//.. бар новый...
//.. делаем то..
//.. что нужно выполнить на очередном..
//.. новом баре

g_lastBarTime = Time[0];               // На текущем баре все необходимые действия..
                                       // .. успешно выполнены

Instead of Time[0]; you can mark iTime() to get a new bar for a timeframe other than the current one.

 
hoz:


You declare it globally:

INIT:

IN START:

You can mark iTime() instead of Time[0]; to get a new bar for a timeframe other than the current one.


The only problem is. The variable names don't match. Ouch, ouch. It's either inattention or habit.
 
Vinin:

Except here's the problem. The variable names don't match. Oh, dear. Either inattention or habit

That's inattention. Correction.

You declare globally:

datetime = bdt_lastBarTime;

IN INIT:

bdt_lastBarTime = 0;

IN START:

if (bdt_lastBarTime == Time[0])         // На текущем баре все необходимые действия..
       return (0);                    // ..уже были выполнены

// если ...
//.. бар новый...
//.. делаем то..
//.. что нужно выполнить на очередном..
//.. новом баре

bdt_lastBarTime = Time[0];               // На текущем баре все необходимые действия..
                                       // .. успешно выполнены

You can mark iTime() instead of Time[0]; to get a new bar for a timeframe other than the current one.

 

at a glance, only specifically for this task.

bool NewBar05()
{
static bool newbar;
if (Minute()==5 && !newbar) 
   {
   newbar=true;
   return true;
   } 
if (Minute()>5 && newbar)  newbar=false;
   return  false;
}
    
 
xxxKillxxx:

Comrade, excuse me again, but I have a problem.... I managed to check all blocks to close without any errors or warnings and I'm not getting any syntax, but I'm not getting any signals when I start my EA, my trades won't close as expected. The problem is that I can not put the code of the EA, and to solve the problem well very much needed, if you do not mind to spend on me again your precious time, please tell me what options may be to address the problem, if it is important, I can only say that the EA was created at forex generator 4.

I would like to ask you to explain the reasons (preferably on your fingers and tongue-in-cheek, because I only do this kind of programming) Thanks in advance.


My code or part of code of your Expert Advisor closes the specified profit of 0.1% and above. On forex generator 4 were you able to do something so that the equity would be higher than the balance ?
 
Roger:

at a glance, just specifically for this task.


Thank you all for your help.

The question was as follows.

<There is a function NewBar(sy, TF). It checks if a new bar has been opened. I need to get a signal on the hourly chart about the appearance of a new bar with a lag of 5 min. 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 doesn't work.

bool isNewBar5 ()
{

    static int   LastBar = 0; 
    datetime      curbar = iTime (Symbol(), 60, 0) +300; 
    int                h = Hour();
    if (LastBar != curbar && h == h + 1 && Minute() == 5)
    {
        LastBar = curbar;
        return (true);
    }
    else
    {return (false);}
}
 
gince:

Hello.

The function NewBar(sy, TF) is available. It checks if a new bar has opened. I need to get a signal of a new bar on the hour chart with a 5 min lag. I want to get the signal at 0.05, 1.05, 2.05, ..........., 10.05, 11.05, etc.


How can this be done ? Maybe the function itself can be rewritten?


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

The value of bt will change at 5 minutes of every 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.

 
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.

I don't get it. If you can get the full code.
Reason: