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

 
PolarSeaman:

Didn't come up with it myself"Just make sure you update the data in OnTimer() to make your code work. "

How should I do it?

Do you have an offline schedule?

 
Can you tell me how to get the bottom indicators from a timeframe other than the one on which the owl is hovering?
 
Galim_V:
Can you tell me how to get the bottom indicators from a timeframe other than the one the owl is hovering on?

1. Why did you hang the bird up? Isn't it a pity?

2. Have you ever opened the help? To receive indicator data in the Expert Advisor from any timeframe is not a problem at all because the first two parameters of functions of receiving indicator data are used to specify the symbol and period of the chart from which you want to receive values.

Indeed, even when you type the code in the editor, the list of formal variables of the function is opened, and a tooltip there shows the symbol and timeframe. Strange that you didn't pay attention to them.

 
Artyom Trishkin:

Do you have an offline schedule?

No.

 
PolarSeaman:

No.

Then why the constant refresh without need?

Do you need time? You can get the time of last tick: TimeCurrent(), or the last local time: Time Local().

If you get the time of the last tick at weekend, the timer will not help - the time will be the last tick on Friday, or the last tick of the last working day. And TimeLocal() will not give you server time - you need to recalculate it with an offset.

However, I don't know exactly what you want to get in the end.

 
Artyom Trishkin:

1. Why did you hang the bird up? Isn't it a pity?

2. Have you ever opened the help? To receive indicator data in the Expert Advisor from any timeframe is not a problem at all because the first two parameters of functions of receiving indicator data are used to specify the symbol and period of the chart from which you want to receive values.

Indeed, even when you type the code in the editor, the list of formal variables of the function is opened, and a tooltip there shows the symbol and timeframe. Strange that you didn't pay attention to them.

2018.07.04 22:17:38.398 2016.11.10 13:00:00 Arap01 EURUSD,H1: Rounding 44.53781512605145 45.0 This is stochastic data in "normal" mode. ie:

2=iStochastic(NULL,0,K,D,slowing,Average_method,price_field,MODE_MAIN,2);

here I ask M5 2=iStochastic(NULL,5,K,D,slowing,Average_method,price_field,MODE_MAIN,2);

I get 2018.07.04 22:23:05.680 2016.11.10 13:00:00 Arap01 EURUSD,H1: Rounding 0.0 0.0



 
Artyom Trishkin:

However, I don't know exactly what you want to end up with.

Alert, I want, two seconds before the bar closes. I won't be working over the weekend.

 
PolarSeaman:

So I need an alert two seconds before the bar closes without a tick.

It is not easy to do, you need to run more accurate timer (at least 500 ms) and previously do synchronization of local time and server time.
I've already told you about this:

At the moment of tick arrival, count the difference TimeCurrent()-TimeLocal()
(this is done once to synchronize local and server time)

- This is the offset relative to the broker, if this offset changes later, the time should be recalculated;
- at the Expert Advisor start (orat appearance of barD1) we recalculate all the necessary times again, in the local time, taking into account the offset;
- We wait for what we "counted" in the timer, checking for desynchronization, loss of connection with the broker, translation of the local hands.

you can catch +/- 1 second
 
Taras Slobodyanik:

It's not easy to do, you have to run a more accurate timer (at least 500ms) and pre-synchronize the local time with the server time.
I've already told you about it:

You can catch +/- 1 second

Thank you. How to make the time in seconds, before the M5 bar closes. Right now it's displaying H1.

#property strict
#property indicator_chart_window
//--- input parameters
#define  MILLISEC_TIMER_INTERVAL         500 
int            timeOffset;
datetime       ServerLocalOffset;
datetime       prevTime,myTime,localtime;
bool           newBar = false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   EventSetMillisecondTimer(MILLISEC_TIMER_INTERVAL);
   
  datetime srvtime,tmpOffset;
   RefreshRates();
   srvtime = TimeCurrent();
   // Modified
   localtime = TimeLocal()+TimeGMTOffset();
   if(TimeHour(srvtime)>TimeHour(localtime)){
      // Server Time is still ahead of us
      int newOffset = TimeHour(srvtime)-TimeHour(localtime);
      ServerLocalOffset = (newOffset*60*60);
   }else if(TimeHour(srvtime)<TimeHour(localtime)){
      // Server Time is Behind us
      int newOffset = TimeHour(localtime)-TimeHour(srvtime);
      ServerLocalOffset = (newOffset*60*60);
   }else{
      // No modification required
      ServerLocalOffset = srvtime;
   }
   localtime = TimeLocal()-ServerLocalOffset;
   
   tmpOffset = TimeSeconds(srvtime) - TimeSeconds(localtime);
   if(tmpOffset < 30 && tmpOffset >= 0){
      timeOffset = TimeSeconds(srvtime) - TimeSeconds(localtime);
   }
   return(INIT_SUCCEEDED);
  }
  
void OnDeinit(const int reason)
  {
   EventKillTimer();
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
datetime sec;
   datetime localtime;
   localtime = TimeLocal()+(TimeGMTOffset()+(60*60));
 sec=Time[0]-localtime-timeOffset;
 if(sec<=2){Alert("время откр. бара ",Time[0]);}
      Comment(TimeToStr(sec,TIME_SECONDS ));
  }
//+------------------------------------------------------------------+
 
Still haven't figured out how to count the seconds until the bar closes on the current period. Help.
Reason: