Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 369

 

Good afternoon. something stopped processing the flag in mt4 after a while. just mt starts ignoring it, could you tell me why:

void OnTimer()
  {
//---
   //-----------------
   int tmeLeftC = PeriodSeconds() - (TimeCurrent()-Time[0]);
   int tmeLeftL = PeriodSeconds() - (TimeLocal()-Time[0]);
   
   
//флаг на вкл отправки   
   if ((sendflag==0) && (tmeLeftC >= 10)) 
      {
         sendflag=1;
      }
      

//Условия на отправку 
///------BAY 
   if ((sendflag==1) && (fNewBar()) && (TimeHour(Time[0]) >= StartH) && (TimeHour(Time[0]) <= EndH) && ((tmeLeftC <= SecondsPrevToServer) || (tmeLeftL <= SecondsPrevToServer)))
      {
         Print("Predict data");
         sendSig();
         Print("Send data");
         sendflag=0;
      }
 
itslek:

Good afternoon. something has stopped processing the flag in mt4 after some time. mt just starts ignoring it, could you tell me why:


try a timer frequency of 100-200ms,
500ms is too much to catch 1 second

and the candlestick may open a few seconds or even a minute later

 
Ivan Ivanov:

Try it:

... Or do you really need extern ?


Thank you. It seems to have helped.

What's the difference between input and extern?

 
Taras Slobodyanik:

try a timer frequency of 100-200ms,
500ms is too long to catch 1 second

and the candle can open a few seconds or even a minute later


so the problem isn't that it's not catching it. There's nothing wrong with that.

The problem is that the flag stops working and it starts to send a signal every 500ms, ignoring the flag conditions. I don't understand what's going on there...

 
RichLux: What is the difference between input and extern?


 

Can you please tell me how to reset the buffer when a new bar appears, but so that the previous data in the buffer is not erased, but displayed on the chart. For some reason I can't reset the buffer to zero and when a new bar appears, new data is overlaid on the old accumulated data. What I have not correctly described in the code.

void OnInit()
{
   IndicatorDigits(0);
   SetIndexBuffer(0,Buf_1);
   SetIndexBuffer(1,Buf_2);
   Bid1=Bid;
  
   
}
 
 
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   datetime Вр=Time[0];   // Время текущего бара
   if(Вр>Время)           // Если новый бар
   {
      Время=Вр;           // Запомнить
      Buf_1[0]=0;         // и обнулить последний элемент буфера
      Buf_2[0]=0;
   }
   
      
   if(Bid > Bid1) 
   {
   V1 = iVolume(NULL, 0, 0);
   V2 = V1 + V2;
   Buf_1[0]= V2;
   }                             
   else 
   {
   V3 = iVolume(NULL, 0, 0);
   V4 = V3 + V4;
   Buf_2[0]= (V4*-1);
   }
   Bid1=Bid;
   
   
  return(rates_total);
}
 
itslek:

so the problem isn't that he's not catching it. There is nothing wrong with that.

the problem is that the flag stops working and it starts sending a signal every 500ms, ignoring the flag conditions. i don't understand what's going on there...


Your timing is confusing, both local and server at the same time.
I would catch a second roughly like this:

//+------------------------------------------------------------------+
bool NewBar()
{
static bool flag=false;
static int bar=Bars;
static datetime lasttime=0;

if (!flag && Bars!=bar)
   {
   bar=Bars;
   lasttime=TimeLocal();
   flag=true;
   }
if (flag && TimeLocal()-lasttime>=pause) //pause - пауза после начала бара, например 59 сек
   {
   flag=false;
   return(true);
   }
return(false);
}
 

Hello, Can you please tell me if you need to type in iData for this indicator, no matter if it's any program or reference to the bar data, where you can specify the timeframe, why is the data from other timeframes are not reflected correctly in the current different on timeframe chart, but only in the chart of the specified timeframe? Thank you.

 

Hello, maybe someone will respond and help, I'll try again. Here's a post on page 367, it's all laid out there.

 
Novaja:

Hello, maybe someone will respond and help, I'll try again. Here's a post, page 367,, it's all there.


Check it out.

Reason: