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

 

Hi all.

My time series array is not updated in the string of trade event definition (when a new candle appears), or rather its value does not change when a new candle appears.

if(T[i]!=iTime(NULL,TF[i],1))

T[i] is first set when launching the Expert Advisor, and then, when a new candle appears, the value is updated.

The I parameter is set on the basis of the input parameters.

What is interesting, the version where I used several TFs to work, and had to use a for loop because of that, everything worked fine, but it fails here - it is not updated, and that's it...(

 
Igemon:

Hi all.

My time series array is not updated in the string of trade event definition (when a new candle appears), or rather its value does not change when a new candle appears.

T[i] is first set when launching the Expert Advisor, and then, when a new candle appears, the value is updated.

The I parameter is set on the basis of the input parameters.

What is interesting, I used several TFs to work in the version where I had to use a for loop and it worked fine, but it fails now - it just does not update...(

Apparently it wasn't pulled out of the loop correctly...

Here's a custom function for defining a new bar

bool NewBar(int tf, datetime &lastbar)
{
   datetime curbar = iTime(_Symbol, tf, 0);
   if(lastbar != curbar)
    {
     lastbar = curbar;
     return (true);
    }
   else return(false);
}//******************************************************************|

Input variables:

tf - chart period or period value to determine the occurrence of a new bar.

lastbar - a variable passed by reference to store the time of the last bar.

void OnTick()
{
// хотим определить наступление нового дня
 static datetime lastDay, lastHour;
 bool newDay, newHour;
 newDay = NewBar(PERIOD_D1, lastDay);
 if(newDay)
 Print("наступил новый день");
// и нового часа
 newHour = NewBar(PERIOD_H1, lastHour);
 if(newHour)
 Print("наступил новый час");
}
 
AlexeyVik
bool NewBar(int tf, datetime &lastbar)
{
   datetime curbar = iTime(_Symbol, tf, 0);
   if(lastbar != curbar)
    {
     lastbar = curbar;
     return (true);
    }
   else return(false);
}//******************************************************************|

The first time it is called from the EA, it immediately reports a new bar. Fixed by adding function calls to OnInit()

When first called from the script, it immediately reports a new bar. Then it is always false. Fixed by adding RefreshRates() to the beginning of the function

 
LRA:

The first time it is called from the EA, it immediately reports a new bar. Fixed by adding function calls to OnInit()

When first called from the script, it immediately reports a new bar. Then it is always false. Fixed by adding RefreshRates() to the beginning of the function

1. At first call true, it is quite normal, if there have been no bars, the one that has appeared will be the new one. If necessary, if strategy demands it, it is possible to refuse from the new bar and some more in this way. At a glance, without thinking, I introduce two more.

static datetime lastDay = iTime(_Symbol, PERIOD_D1, 0);, lastHour = iTime(_Symbol, PERIOD_H1, 0);

or

if(lastbar != curbar && lastbar > 0)

2. Why would the script define a new bar? This is silly to what extent?

 

But why isn't it working here...((( I think it's fine(

extern int TFrame=1;

datetime T[6];
int TF[6]={1,5,15,30,60,240};
int i=TFrame-1;

int OnInit()
   {
   T[0]=iTime(NULL,1,1);
   T[1]=iTime(NULL,5,1);
   T[2]=iTime(NULL,15,1);
   T[3]=iTime(NULL,30,1);
   T[4]=iTime(NULL,60,1);
   T[5]=iTime(NULL,240,1);
   for(int q=0;q<=5;q++)
      Print(T[q]);
   return(INIT_SUCCEEDED);
   }
 
void OnTick()
   {
   while(1==1)
      {
      if(T[i]!=iTime(NULL,TF[i],1))
 

Igemon:

void OnTick()
   {
   while(1==1)
      {
      if(T[i]!=iTime(NULL,TF[i],1))
Excuse me, Ygemon, but why this recklessness? What kind person advised you to do that?
 
Good day to all. Could someone please advise me: how can I ensure that the EA works properly, i.e. that it executes a given algorithm when the terminal is restarted or when the internet is disconnected?
 
artmedia70:
Excuse me, Ygemon, but why this recklessness? What kind person advised you to do that?
What's wrong with it? I just didn't put in the rest of the code, because everything is normal there. The loop is needed to not depend on ticks, when defining events, not to restart the PC is sleep at 100 mlsec
 
Igemon:
What is wrong with it? I just didn't insert the rest of the code because everything is ok there. The loop is needed to not depend on ticks, when defining events, not to reboot the PC is sleep at 100mlsec

Don't OnTimer() and OnChartEvent() tell you anything?, good... sorry, Ygemon...

And how are you going to stop the loop?

Reason: