- Trying to convert an mql4 to mql5 breakeven indicator but nothing is drawn on the chart.
- What indicator is this?
- Moved: How to use ZigZag indicator to build an EA ?
sorry but some other problems were noticed in this
return 0 in OnCalculate will cause the indicator to deallocate itself prematurely, and the initializer should return INIT_SUCCEEDED success number
n OnCalculate, return 0 can cause the indicator to stop calculating values and deinitialize itself
A very dubious statement.
but one should never use return 0 in OnCalculate, it will crash the indicator and there's never a reason to anyway. Return any number at the end but not 0 or -1
Are you saying that the code example in the documentation is incorrect and will crash the indicator?
https://www.mql5.com/en/docs/event_handlers/oncalculate
int OnCalculate(const int rates_total, // price[] array size const int prev_calculated, // number of previously handled bars const int begin, // where significant data start from const double &price[]) // value array for handling { //--- initial position for calculations int StartCalcPosition=(IntPeriod-1)+begin; //---- if calculation data is insufficient if(rates_total<StartCalcPosition) return(0);
nope in OnCalculate, return 0 can cause the indicator to stop calculating values and deinitialize itself. Try it.
I always thought that the return value of OnCalculate doesn't affect anything except the value of the prev_calculated variable the next time OnCalculate is called.
Could you show some code that can be used to make sure that the return value affects something other than prev_calculated?
I always thought that the return value of OnCalculate doesn't affect anything except the value of the prev_calculated variable the next time OnCalculate is called.
Could you show some code that can be used to make sure that the return value affects something other than prev_calculated?
That indicator simply doesn't work correctly, regardless of the return value. The variables are not initialized with anything and contain garbage values. If your indicator deinitialized itself, it's possible that a division by 0 occurred somewhere because the variables were not initialized.
My demo account history is empty. The indicator always displays random garbage.
If you can reproduce the situation you described, please do so and attach the log here. Most likely, we will find a division by 0 or some other runtime error in the log.
I did this, changing the return value does not affect anything. I can't reproduce what you write.
It will work sometimes, not other times. This is what I experienced
And can you explain why the indicator always seems to work correctly if return rates_total is used instead of return 0? 😏
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use