Errors, bugs, questions - page 2997

 
Alexey Viktorov:

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.

 
Alexey Viktorov:

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.

 
Francuz:

Yes, I did. The result has not changed.

I don't believe it.
try again

datetime a = D'2021.04.08 10:00:00';
   int      handle;
   double   Buffer[];
   

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{

   handle = iCustom(_Symbol, PERIOD_CURRENT, "Examples\\ATR.ex5", 14);
   ::Print(__FUNCTION__ + "| PERIOD_CURRENT = ", EnumToString(_Period));

   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| 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[])
{

   if(prev_calculated>0 && handle != INVALID_HANDLE)
   {
      ::CopyBuffer(handle, 0, a, 1, Buffer);
      
      double BS = ::NormalizeDouble(Buffer[0], _Digits);
      
      ::Print(__FUNCTION__ + "| a = ", a);
      ::Print(__FUNCTION__ + "| BS ", BS);
      
      handle = INVALID_HANDLE;
   }
   
   // return value of prev_calculated for next call
   return(rates_total);
}
 
Nikolai Semko:

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.
 
Nikolai Semko:

I don't believe it.
try again

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 ".

 
Nikolai Semko:

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?

 
Alexey Viktorov:

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

 
Alexey Viktorov:

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                         |
//+------------------------------------------------------------------+
int OnInit()
{

   handle = iCustom(_Symbol, PERIOD_CURRENT, "Examples\\ATR.ex5", 14);
   ::Print(__FUNCTION__ + "| PERIOD_CURRENT = ", EnumToString(_Period));

   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| 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[])
{

   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 call
   return(rates_total);
}


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

 
Artyom Trishkin:

Oh, what wondrous discoveries are in store for us... more

I meant the data to calculate the indicator. Don't be sarcastic))))