Errors, bugs, questions - page 3031

 
Igor Makanu:

my code will "hammer on every tick" only your indicator #1, where you have written :

it will allow the terminal to independently build the "higher timeframe".

For me - it's "cheaper" than to perform a complete recalculation of indicator 1, that happens in your code when synchronizing the history on the "higher TF

Yes, but why is the prefault reset on the lower TF?

 
Andrey Dik:

yes, but why is the prev kalk reset on the lower TF?

because return 0;
 
Andrey Dik:

yes, but why is the prev kalk reset on the low TF?

there are many variants, we do not know the implementation


there was a similar discussion about MT4 last year, one of the developers (i think Slava) said, that every access to the "older TF" initiates data synchronization, if it is required....

I think, that in MT5 the terminal also builds TF by itself, if necessary, but if there were network delays or ..... implementation is unknown... then the terminal, before giving the data to the indicator on a senior TF, synchronizes the historical data with the server, when it happens instantly, and when, maybe, it takes a long time, that's when it will probably be pre_calculated = 0

 
Igor Makanu:

there are a lot of options, we do not know the implementation

If the downloading changes the historical data of the low TF, the counter of the low TF will be forced to zero by the terminal, do not make problems out of the blue

 
Andrey Dik:

you're proving my point, comrade.

I'm no...comrade to the coder. It's not a confirmation, it's a hint, don't return 0. That's all your problems. You yourself are causing a complete recalculation of the indicator.

 

Forum on trading, automated trading systems and trading strategy testing

Bugs, bugs, questions

Andrey Dik, 2021.05.28 17:26

Pre_calculated does not increase by 1 on the next bar.


prev_calculated actually does not increase; it will always be the same as at the end of calculation

return(rates_total);


i.e., what we get back on exit of OnCalculated() will be returned on the next tick in prev_calculated (except prev_calculated == 0, the terminal does this when launching the indicator or synchronizing TF......)


Andrei Trukhanovich:

if the downloading changes the history data of the low low TF, the counter of the low TF will be forcedly zeroed by the terminal, don't make trouble out of the blue

I've been writing to him for the second day - take the indicators from Mladen and study them - they work, and without any complicated synchronization between TFs, and here ... we are saving resources and do not let the terminal to form the called TFs

 
Andrei Trukhanovich:

replace

to

and test it.

Don't prompt... He won't believe it anyway.

 
Alexey Viktorov:

I ... am no friend to the coder. This is not a confirmation but a hint, don't return 0. That's what causes all your problems. You yourself are causing a complete recalculation of the indicator.

You may be an idiot to give a hint, but not everyone can help you understand and explain.

 
Andrei Trukhanovich:

replace

to

and test it.

Thank you, Andrei. You are the only one who has fully penetrated into the question.

2021.05.28 21:22:54.394 LitTF (EURUSD,M2) The indicator for period 3 is not yet calculated

2021.05.28 21:22:54.396 LitTF (EURUSD,M2) The indicator on period 3 has not been calculated yet

2021.05.28 21:22:54.397 OldTF (EURUSD,M3) 0.000262 sec, 50046 bars calculated, total 50046 bars

2021.05.28 21:22:55.796 LitTF (EURUSD,M2) 0.007693 sec, 50000 bars calculated, 50000 total bars

2021.05.28 21:24:02.286 LitTF (EURUSD,M2) Indicator on period 3 not calculated yet

2021.05.28 21:24:02.286 OldTF (EURUSD,M3) 0.000000 sec, 1 bar calculated, 50047 bars total

2021.05.28 21:24:03.017 LitTF (EURUSD,M2) 0.000015 sec, calculated 1 bars, total bars 50001

2021.05.28 21:26:03.898 LitTF (EURUSD,M2) 0.000007 sec, calculated 1 bars, total bars 50002

now everything is working as planned, indicators have been fully calculated only once at first run and further only once per each new bar.


The final code of the second indicator, I hope it will be useful to someone:

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[])
{
   ulong t = GetMicrosecondCount ();
   if (rates_total == prev_calculated) return rates_total;

   
   if (SeriesInfoInteger (Symbol (), OldTF, SERIES_SYNCHRONIZED))
   {
      if (iBars (Symbol (), OldTF) != BarsCalculated (Handle))
      {
        Print ("Индикатор на периоде ", OldTF, " ещё не рассчитан");
        return prev_calculated;
      }
   }
   else 
   {
     Print ("Период ", OldTF, " не синхронизирован.");
     return prev_calculated;
   }

   ArraySetAsSeries (high, true);
   ArraySetAsSeries (time, true);

   int limit = rates_total - prev_calculated - 1;

   double buff [];
   int ind = 0;
   for (int i = limit; i >= 0; i--)
   {
      ind = iBarShift (Symbol (), OldTF, time [i], false);
      if (CopyBuffer (Handle, 0, ind, 1, buff) != -1)
      {
        IBuffer [i] = buff [0];
      }
      else
      {
        Print ("Ошибка копирования буфера ", GetLastError ());
        return 0;
      }
   }

   //----------------------------------------------------------------
   double e = (GetMicrosecondCount () - t) / 1000000.0;
   Print (DoubleToString (e, 6), " sec, расcчитано ", rates_total - prev_calculated, " баров, всего баров ", rates_total);
   return(rates_total);
}
 
Andrey Dik:

Any fool can give you a hint, but not everyone can help you understand and help you in detail.

Count how many fools are advising you... Only one smart guy can't hear anyone and stubbornly...............

You have created your own problem and are trying to present your ...code as an mql bug.

Reason: