SeriesInfoInteger returns 0 - page 3

 
chinaski:

Sorry

Is a mistake by me. But you can see in my original code it is correct, even it uses int as i guess there is an implicit cast.

You say:

"Also, why do you need that extra code when the data is already available to you within the OnCalculate?

It has "rates_total" which is the total number of bars (i.e.SERIES_BARS_COUNT).

It already has all the data for time[], open[], high[], low[], close[], tick_volume[], volume[], spread[] and there is no need to use CopyRates?

You are making your own programming difficult when the data it is already there and easily accessible.

EDIT: Yes it is all documented, but you are not following the documentation. That is why you are having this difficult time!"


I think this is not the point. There is a function, promising a service and this function works not reliable in OnInit and in OnCalculate only with your code.

This takes time. 

I checked again the call in OnInit and it works now! Why that ?? Also with integer type.

Those functions are there to be used in other circumstances, such as Script, Service or EAs. There is no need to use those functions in an Indicator that already has the functionality simplified for you.

Also, the reason it probably works now in OnInit is because the chart has now been updated and so has all the relevant data. That is why I said that using it in the OnInit it is unreliable (and yes it is documented). So just don't use it there.

Like I said, there is a proper way of doing it in an Indicator, and you are not following the documentation. You asked for help, and we have given you advice. If you do not wish do follow it, then that is up to you!

 
Fernando Carreiro:

Those functions are there to be used in other circumstances, such as Script, Service or EAs. There is no need to use those functions in an Indicator that already has the functionality simplified for you.

Also, the reason it probably works now in OnInit is because the chart has now been updated and so has all the relevant data. That is why I said that using it in the OnInit it is unreliable (and yes it is documented). So just don't use it there.

Like I said, there is a proper way of doing it in an Indicator, and you are not following the documentation. You asked for help, and we have given you advice. If you do not wish do follow it, then that is up to you!

I asked for help, got it and said thank you. 

Here is where we differ: What you call is the proper way, is in my eyes a special, undocumented way to do it which , in addition ,

works not intuitive.


Why did it fail with each call in OnCalculate ? Why an if condition which asks for "rates_calcuated", makes the difference ?

Why does it work now in OnInit and previously not ?

You say:

probably works now in OnInit is because the chart has now been updated and so has all "

Ok, but in script or experts it should not fail?


Sorry, there are too many questions and it might be better to rework this function or the documentation

for our all benefit.

 
chinaski:

I asked for help, got it and said thank you. 

Here is where we differ: What you call is the proper way, is in my eyes a special, undocumented way to do it which , in addition ,

works not intuitive.


Why did it fail with each call in OnCalculate ? Why an if condition which asks for "rates_calcuated", makes the difference ?

Why does it work now in OnInit and previously not ?

You say:

probably works now in OnInit is because the chart has now been updated and so has all "

Ok, but in script or experts it should not fail?


Sorry, there are too many questions and it might be better to rework this function or the documentation

for our all benefit.

Are you sure about all what you said ?

From the start, I can see in your code :

   PrintFormat("bars=%d code=%d",GetLastError());

So for sure it always return 0, whatever where it's called, as there is no error and GetLastError returns 0. So probably it returns the good value but you just print something wrong.

 
chinaski:

I asked for help, got it and said thank you. 

Here is where we differ: What you call is the proper way, is in my eyes a special, undocumented way to do it which , in addition ,

works not intuitive.

Why did it fail with each call in OnCalculate ? Why an if condition which asks for "rates_calcuated", makes the difference ?

Why does it work now in OnInit and previously not ?

You say:

probably works now in OnInit is because the chart has now been updated and so has all "

Ok, but in script or experts it should not fail?

Sorry, there are too many questions and it might be better to rework this function or the documentation

for our all benefit.

What I explained to you, is the documented way! Your way is the undocumented way! Please do not confuse that!

I provided you information to the very questiones you have just posed, but have ignored my answers.

I explained and even gave you a link to follow that explains the sequence of events of why it will sometimes work, but most of the time fail if used in OnInit.

When using those some functions, in a Expert Advisor for example, then the same precautions will hold. You will also not be able to use it reliably in OnInit for an EA either, only during OnTick, and should use it it on a different Symbol or Timeframe, not the same as the chart, then you will have to carry out further steps to make sure that it works correctly. All this is documented, even though it my be difficult to find or understand.

So, please, if you want to code an Indicator, then follow the guidelines to properly handle the data as provided by the OnCalculate method. You can still use functions like CopyRates if you wish (if done properly and correctly), but you will be making life difficult for yourself. The only time you should use the functions like CopyRates in an indicator, is when you need to use data from a different Timeframe or Symbol from that of the current chart. And when you do so, there will many other checks and verifications that you will need to do, before those functions give you reliable information. This too is documented, but it is complex.

I will leave the thread for now, and leave it up to you to contemplate how you wish to do things on your own. Just remember, that if you do it in an unconventional way not described in the documentation, then it will be more difficult for you to receive help from other users.

 
Fernando Carreiro:

What I explained to you, is the documented way! Your way is the undocumented way! Please do not confuse that!

I provided you information to the very questiones you have just posed, but have ignored my answers.

I explained and even gave you a link to follow that explains the sequence of events of why it will sometimes work, but most of the time fail if used in OnInit.

When using those some functions, in a Expert Advisor for example, then the same precautions will hold. You will also not be able to use it reliably in OnInit for an EA either, only during OnTick, and should use it it on a different Symbol or Timeframe, not the same as the chart, then you will have to carry out further steps to make sure that it works correctly. All this is documented, even though it my be difficult to find or understand.

So, please, if you want to code an Indicator, then follow the guidelines to properly handle the data as provided by the OnCalculate method. You can still use functions like CopyRates if you wish (if done properly and correctly), but you will be making life difficult for yourself. The only time you should use the functions like CopyRates in an indicator, is when you need to use data from a different Timeframe or Symbol from that of the current chart. And when you do so, there will many other checks and verifications that you will need to do, before those functions give you reliable information. This too is documented, but it is complex.

I will leave the thread for now, and leave it up to you to contemplate how you wish to do things on your own. Just remember, that if you do it in an unconventional way not described in the documentation, then it will be more difficult for you to receive help from other users.

Again, can you point me to this documentation please ?

 

It seems i don't want to accept how it is. I appreciate your help but i stay with my comment that the behaviour for this function is more than tricky.

If you say, "stick with documented way", there is no indication in the documentation not to use this function in indicators.

So, what do you mean ? Which documentation you are talking about ?
Thank you

 
chinaski:

It seems i don't want to accept how it is. I appreciate your help but i stay with my comment that the behaviour for this function is more than tricky.

If you say, "stick with documented way", there is no indication in the documentation not to use this function in indicators.

So, what do you mean ? Which documentation you are talking about ?
Thank you


Most importantly, start by reading articles on how to code an Indicator using the documentation as a reference. Here is one example:

Since I don't know what your end goal is with the Indicator you are making, I can only suggest you start with the documentation on the OnCalculate event handler and the example at the very end.

You should also read up on the various event handling functions and how they operate:


MQL5: Create Your Own Indicator
MQL5: Create Your Own Indicator
  • www.mql5.com
What is an indicator? It is a set of calculated values that we want to be displayed on the screen in a convenient way. Sets of values are represented in programs as arrays. Thus, creation of an indicator means writing an algorithm that handles some arrays (price arrays) and records results of handling to other arrays (indicator values). By describing creation of True Strength Index, the author shows how to write indicators in MQL5.
Reason: