Discussion about OnCalculate returning 0. - page 3

 
Conor Mcnamara #:

Yeah that's what I thought. 

This is what return 0 does in OnCalculate, it tells the program to successfully complete its operation and it calls OnDeInit gracefully. This isn't explained in the docs, however "return 0" was always known to indicate completion of a program in C programming. You would expect it to keep calculating, but this will end the program. They could flesh out the docs a bit more for OnCalculate explanation.

All these statements are incorrect.

Is the code in post #9 the last version ? I would check it.

 
Alain Verleyen #:

All these statements are incorrect.

Explain why please. Returning 0 will prevent OnCalculate to continue. It's not the same as MT4
 
Conor Mcnamara #:
Explain why please. Returning 0 will prevent OnCalculate to continue. It's not the same as MT4

No. Returning 0 will just lead to the next OnCalculate call using prev_calculated=0.

Please provide code to show your issue if you need more explanation.

 
Alain Verleyen #:

No. Returning 0 will just lead to the next OnCalculate call using prev_calculated=0.

Please provide code to show your issue if you need more explanation.

as discussed in this topic, return 0 leads to OnDeInit returning code 1 to say that the indicator is now removed. So if this is not meant to be, perhaps it's a bug, or what? Keep in mind the documentation is vague to explain OnCalculate, so we can't know for sure

Feel free to take any code, like that guy did, and place return 0 at the end of the OnCalculate.
 
Conor Mcnamara #:
as discussed in this topic, return 0 leads to OnDeInit returning code 1 to say that the indicator is now removed. So if this is not meant to be, perhaps it's a bug, or what? Keep in mind the documentation is vague to explain OnCalculate, so we can't know for sure

Feel free to take any code, like that guy did, and place return 0 at the end of the OnCalculate.

This is complete non sense. Vladislav already asked you to post code to prove your claim, I asked you to do it too and still you don't want to cooperate.

OnCalculate() behaviour is perfectly known. The documentation is perfectly clear.

If there is an issue it's something specific on your side. If you don't want to post code so we can investigate about what you saw, I will remove all this sequence of posts which is pointless without code.

 
Alain Verleyen #:

This is complete non sense. Vladislav already asked you to post code to prove your claim, I asked you to do it too and still you don't want to cooperate.

OnCalculate() behaviour is perfectly known. The documentation is perfectly clear.

If there is an issue it's something specific on your side. If you don't want to post code so we can investigate about what you saw, I will remove all this sequence of posts which is pointless without code.

What do you mean? Why is it difficult to take any code and replace return rates_total?


How come he could do it, but you couldn't do it? What is the need to provide code?


 
Conor Mcnamara #:
What is the need to provide code?

I thought the return value didn't affect anything at all except prev_calculated.

But, it turned out that the terminal does not update the indicator when the indicator returns 0. In this context, you are right - it is better not to return 0.

But returning 0 does not lead to a crash or deinitialization - in this context, you are wrong (at least I cannot reproduce it).

[edit]

the terminal does not update the indicator when the indicator returns 0

I meant that the terminal will not update the indicator buffers. I only considered indicator buffers.

 
Vladislav Boyko #:


But returning 0 does not lead to a crash or deinitialization - in this context, you are wrong (at least I cannot reproduce it).

well, that is just what I got

(post #21)

via the code I posted in post #9


Let's keep it productive guys. In my mind, someone shouldn't yell "nonsense" without reason. We're all wishing to know certainties here. 


If any of you want to understand more:

https://www.geeksforgeeks.org/return-0-vs-return-1-in-c/

return 0 vs return 1 in C++ - GeeksforGeeks
return 0 vs return 1 in C++ - GeeksforGeeks
  • www.geeksforgeeks.org
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
 
Conor Mcnamara #:

well, that is just what I got

(post #21)

I don't know any other way to get the REASON_REMOVE code other than manually removing the indicator from the chart. I don't see any relationship between returning 0 and REASON_REMOVE. Most likely, you simply removed the indicator from the chart (this was the reason for REASON_REMOVE).

I have run your indicator many times in the strategy tester, returning 0 and returning rates_total. I was unable to get an indicator crash or unexpected deinitialization. The order history was empty, so the indicator displayed uninitialized values. Sometimes it didn't display anything (objects were visible in the object list, but not in the chart). But there was no crash or deinitialization - the indicator continued to work.

I didn't study how your indicator works, I didn't try to understand if there are any errors there, I just wanted to get deinitialization in the middle of testing or crash. And I didn't get it.

 

Of course, there is a possibility that you have encountered some kind of terminal bug or something similar.

But so far only you have seen it.