Nikolai, he had a different problem. I didn't immediately understand the issue either, thought I needed to get values from a different TF. Lubricated the skis and everything went right.
Alexey Viktorov: Nikolay, he had a different problem. I didn't understand the question at first either, I thought I needed to get the values from another TF. I oiled the skis and everything went well.
Strange, didn't understand anything. I reproduced his problem in mine exactly as he described. It happened exactly because the only execution of CopyBuffer took place at first run in OnCalculate, when prev_calculated == 0 and there was no guarantee that bars were already generated. The solution was to ignore this first run and run the only CopyBuffer only when prev_calculated>0. I don't understand"two different ATR files from different folders ".
Strange, didn't understand anything. I reproduced his problem in mine exactly as he described. It happened exactly because the only execution of CopyBuffer took place at first run in OnCalculate, when prev_calculated == 0 and there was no guarantee that bars were already generated. The solution was to ignore this first call and execute single CopyBuffer only when prev_calculated>0. Why there were"two different ATR files from different folders " - I don't understand.
Well, if the chart is opened and the indicator for the current TF is created, the data should already be ready when the chart is opened. Isn't it?
Well, if a chart is opened and an indicator is created for the current TF, the data should already be ready when the chart is opened. Isn't it?
I did not express it correctly. The bars are yes - most likely they are ready. But there is no guarantee that the indicator has been recalculated for all these bars at the first call of OnCalculate, when prev_calculated == 0. You can run such an indicator to make sure of it. But it must be done when the quotes are traded. If the market is closed, you won't see the mismatch. So it's better to try it on cryptocurrency, which is in movement, at weekend. If Size of Buffer array = -1, it means that indicator buffer is not recalculated yet and BS value will not be correct.
datetime a = D'2021.04.08 10:00:00';
int handle;
double Buffer[];
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intOnInit()
{
handle = iCustom(_Symbol, PERIOD_CURRENT, "Examples\\ATR.ex5", 14);
::Print(__FUNCTION__ + "| PERIOD_CURRENT = ", EnumToString(_Period));
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[])
{
if(handle != INVALID_HANDLE)
{
::CopyBuffer(handle, 0, a, 1, Buffer);
double BS = ::NormalizeDouble(Buffer[0], _Digits);
::Print(__FUNCTION__ + "| a = ", a);
::Print(__FUNCTION__ + "| BS ", BS);
int total_bars = iBars(NULL,PERIOD_CURRENT);
int size = CopyBuffer(handle, 0, 0, total_bars, Buffer);
Print("Total Bars = " + string(total_bars) + ", Size of Buffer array = " + string(size));
handle = INVALID_HANDLE;
}
// return value of prev_calculated for next callreturn(rates_total);
}
If you do it on next call of OnCalculate (when prev_calculated>0) then there will be no such problem.
Maybe the skis are bad?
And then there's the RTS-6.21.
This is something else. What broker do you have and what version of MT5.
Maybe the skis are bad?
And also RTS-6.21.
Thanks for the help. Figured it out. Connected different versions of indicators from different folders.
Yes, I did. The result has not changed.
I don't believe it.
try again
I don't believe it.
try again.
I figured it out. The problem was that two different ATR files from different folders were connected. That's why there was a discrepancy in values.
Thank you for your help.I don't believe it.
try again
Nikolay, he had a different problem. I didn't understand the question at first either, I thought I needed to get the values from another TF. I oiled the skis and everything went well.
Strange, didn't understand anything.
I reproduced his problem in mine exactly as he described.
It happened exactly because the only execution of CopyBuffer took place at first run in OnCalculate, when prev_calculated == 0 and there was no guarantee that bars were already generated.
The solution was to ignore this first run and run the only CopyBuffer only when prev_calculated>0.
I don't understand"two different ATR files from different folders ".
Strange, didn't understand anything.
I reproduced his problem in mine exactly as he described.
It happened exactly because the only execution of CopyBuffer took place at first run in OnCalculate, when prev_calculated == 0 and there was no guarantee that bars were already generated.
The solution was to ignore this first call and execute single CopyBuffer only when prev_calculated>0.
Why there were"two different ATR files from different folders " - I don't understand.
Well, if the chart is opened and the indicator for the current TF is created, the data should already be ready when the chart is opened. Isn't it?
Well, if a chart is opened and an indicator is created for the current TF, the data should already be ready when the chart is opened. Isn't it?
Oh, how many wonderful discoveries await us ... more
Well, if a chart is opened and an indicator is created for the current TF, the data should already be ready when the chart is opened. Isn't it?
I did not express it correctly. The bars are yes - most likely they are ready. But there is no guarantee that the indicator has been recalculated for all these bars at the first call of OnCalculate, when prev_calculated == 0.
You can run such an indicator to make sure of it.
But it must be done when the quotes are traded. If the market is closed, you won't see the mismatch.
So it's better to try it on cryptocurrency, which is in movement, at weekend.
If Size of Buffer array = -1, it means that indicator buffer is not recalculated yet and BS value will not be correct.
If you do it on next call of OnCalculate (when prev_calculated>0) then there will be no such problem.
SOM there was a mistake in code - fixed it
Oh, what wondrous discoveries are in store for us... more
I meant the data to calculate the indicator. Don't be sarcastic))))