Errors, bugs, questions - page 2995

 
   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);
      
      handle = INVALID_HANDLE;
   }
   
   // return value of prev_calculated for next call
   return(rates_total);
}


Can anyone answer why this code only works correctly on minutes?

This is an indicator.


P. S.

On timeframes other than minute ones it outputs wrong values.

 
Francuz:


Can anyone answer why this code only works correctly on minutes?

This is an indicator.

P. S.

On timeframes other than minutes it outputs wrong values.

Because you have performed a single iteration only at the very first visit of OnCalculate, when prev_calculated = 0. At that point the bars may not have been formed yet. And all TFs are formed from 1M TFs.
Insert in the check:

if(prev_calculated>0 && handle != INVALID_HANDLE)

And everything will work.

 

There are two EA tabs open in ME, both have unsaved changes, we press the compile button on one of them and see that ME saves the changes in both EAs. Why? Who asked him to do that?

If ME saved changes in the linked files before compiling, it would be logical behaviour, but so.... Of course, because it's so much easier, why sort out which files belong to whom? It's much easier to save all open files and be done with it....

 
Andrey Dik:
In ME the tabs of two EAs are open, both have unsaved changes, press the compile button of one of them and see that ME saves the changes in both EAs. Why? Who asked him to do that?
How else could it do it?
This is the only way.
In all IDEs this is the case.
 
Nikolai Semko:
How else?
This is the only way.
All IDEs are like that.

Is it sure in all IDEs?

I just tried VS, yes, the behavior is the same. But, should the retarded behavior of a product, even the most famous one, be considered as a benchmark? Let's copy all bugs and misunderstandings of VS, why?

))

 
Andrey Dik:

is it accurate in all of them?

I just tried VS, yes, the behaviour is the same. but, the retarded behaviour of a product, even the most well-known one, should be considered the benchmark? let's then copy all bugs and misunderstandings of VS, why.

))

I have used at least 9 different IDEs in the last year. It's like this everywhere.
Well, think logically, how many problems can there be if one file has several masters that don't see each other's changes. If one compiled with one code, and another with another code, you already have to create two ex5 files with the same name, etc.
 

Why not make the Navigator as a table in the manner of the Market Watch window? TheMarket Watch has implemented sorting, kudos! - We've been asking for it for a long time.

Now comes the era of our new dream of mega coolest usability of displaying the Navigator content and sorting by columns: Title, Author, Compilation Date, Last Run Date, Availability of Source, Program Type (and disabling sorting and reverting to the current view)

 
Nikolai Semko:
I have used at least 9 different IDEs in the past year. Everywhere it's like this.
Well think logically, how many problems can there be if one file has several hosts that do not see each other's changes. If one compiled with one code and the other with another code, you already need to create two ex5 files with the same name, etc.

If two different EAs are opened, what can be the connection between them? Only inludes that are part of the owls need to be saved, and it doesn't matter who else those inludes belong to.

For example, if you open some *txt file that is not saved, it has nothing to do with the compiled file and/or project, so why save it?

 
Nikolai Semko:

because you only perform a single iteration at the very first OnCalculate entry, when prev_calculated = 0. At this point the bars may not have been formed yet. And all TFs are formed from 1M TFs.
Insert in the check:

and everything will work.

You missed the point. The code should work only once. Its purpose is to show that the called indicator does not work. The problem is that in any variants of the indicator called will not work if it (and the caller) has a different TimeFrame from the minute one. I found out that it is a bugof MetaTrader that can be solved only with crutches. And this problem is quite old. You can read the details in "I can't get indicator data from the older TF 123".

Вопросы от начинающих MQL5 MT5 MetaTrader 5
Вопросы от начинающих MQL5 MT5 MetaTrader 5
  • 2012.03.12
  • www.mql5.com
Подскажите пожалуйста, такой показатель тестера в жизни реален? И хороший это или плохой результат за год с депо 3000...
 
Francuz:

You are missing the point. The code is only supposed to work once. Its purpose is to clearly show that the called indicator doesn't work. The problem is that the called indicator will not work if it (and the caller) has a different TimeFrame from the minute one. I found out that it is a bugof MetaTrader that can be solved only with crutches. And this problem is quite old. You can read the details in details in "I can't obtain indicator data from the major TF 123".

That was a long time ago. The problem has been solved long ago. You need at least once every two minutes to access the data of a non-native timeframe/symbol. In the main loop, if there is no data from the requested timeframe yet, you need to exit the loop - just return zero to wait for the next tick, and the indicator knew that the historical data has not been calculated yet.