Questions from Beginners MQL5 MT5 MetaTrader 5 - page 534

 
MikeZv:

Vladimir, thanks for the answer to the first question, I missed these features.

I put one and the same indicator in MT4 and in MT5 (of course, the code is adapted to each platform).
Up to zero bar their values are the same, so apparently from one end ... :)
And when disabling the calculation on the current bar in MT4 nothing is drawn under the current bar, in MT5 - wrong values.

Forum on trading, automated trading systems and strategy testing

Questions from Beginners

Karputov Vladimir, 2016.03.08 15:13

... For debugging set check - which value is contained in time series array time[i] - so you understand at what end you start the calculation of bars and where you have a "zero" bar.


 
MikeZv:
And how to put such a check ?

In MetaEditore add a breakpoint and start debugging. When the breakpoint is stopped, add time[0] to the observation:

Debugging

 
Karputov Vladimir:

In MetaEditore add a breakpoint and start debugging. When the breakpoint is stopped, add time[0] to the observation:


I have already inserted the output in the code

MT4 2016.03.08 18:37:04.710 mvt_Vlt EURUSD,H1: time[0] = 2016.03.08 17:00:00 time[rates_total-1] = 1971.01.04 00:00:00

MT5 2016.03.08 18:36:23.565 mvt_Vlt (EURUSD,H1) time[0] = 2010.01.04 00:00:00 time[rates_total-1] = 2016.03.08 17:00:00

Inserted in the MT5 codeArraySetAsSeries(time,true);
Now output:

MT5 2016.03.08 18:45:05.402 mvt_Vlt (EURUSD,H1) time[0] = 2016.03.08 17:00:00 time[rates_total-1] = 2010.01.04 00:00:00

And do price arrays as well ?


 
MikeZv:
I already put the output in the code

MT4 2016.03.08 18:37:04.710 mvt_Vlt EURUSD,H1: time[0] = 2016.03.08 17:00:00 time[rates_total-1] = 1971.01.04 00:00

MT5 2016.03.08 18:36:23.565 mvt_Vlt (EURUSD,H1) time[0] = 2010.01.04 00:00:00 time[rates_total-1] = 2016.03.08 17:00:00
What do I do now ?

In both versions of the indicator addArraySetAsSeries- for those arrays that you use for your calculations: high[], low[] and temporarily for the time[] array - it will help you to understand where the "zero" bar is. Thus, the "zero" bar in both versions will be on the same side of the chart (right or left - depending on what you set in ArraySetAsSeries), and you will get the same calculation part of the indicator.

Added: while I was typing, you have fumbled the right way :)

 
Karputov Vladimir:


Added: while I was typing, you found the right way :)

I found it, but it still doesn't show it correctly. :)
I pasted it into MT5 code:
   ArraySetAsSeries(ExtCalcVlBuffer,true); 
   ArraySetAsSeries(ExtMovingBuffer,true);
   ArraySetAsSeries(ExtStdDevBuffer,true);
   ArraySetAsSeries(time,true);             
   ArraySetAsSeries(low,true);              
   ArraySetAsSeries(high,true); 

It's coming out:

It onlyoutputs ExtCalcVlBuffer, but the average and deviation don't count...
And it still outputs on the current bar, although it shouldn't.

 
MikeZv:
...

It still displays on the current bar, even though it shouldn't.

Why shouldn't it?
 
Karputov Vladimir:
Why shouldn't it?
I turned it off i<rates_total-1
 
MikeZv:
I turned it off i<rates_total-1
WHY?!
 
Karputov Vladimir:
WHY?!
You don't need to count on the current one, you're just wasting your CPU, and you just don't need the value.
 
MikeZv:
You don't need to use the current value, it will only load the processor in vain and you simply don't need this value.

You need to specify that right away :) .

The situation is as follows: if there is a bar in the chart, it corresponds to a cell in the indicator buffer. As long as you do not write something in this cell, this cell will store rubbish.