-
Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
Messages Editor - momarzai: something i am missing. at line 89 it is giving the error.
You don't indicate what line is 89, nor what the error is. Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button) or attach the source file.
How To Ask Questions The Smart Way. (2004)
Be precise and informative about your problem -
int init() { ⋮ } int start() { ⋮
You should stop using the old event handlers (init, start, deinit) and IndicatorCounted() and start using new event handlers (OnInit, OnTick/OnCalculate, OnDeinit).
Event Handling Functions - MQL4 Reference
How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 (2016)
-
Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
Messages Editor -
You don't indicate what line is 89, nor what the error is. Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button) or attach the source file.
How To Ask Questions The Smart Way. (2004)
Be precise and informative about your problem -
You should stop using the old event handlers (init, start, deinit) and IndicatorCounted() and start using new event handlers (OnInit, OnTick/OnCalculate, OnDeinit).
Event Handling Functions - MQL4 Reference
How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 (2016)
Thanks for feedback, offcourse thier are no mind readers. but just run it in mt4 you would see it too. in line 89 the error is divided by zero.
i didnt changed the code on event lvl. wanted first it work the way i want. then working i will change it.
these two line below returns 0. which makes in line 89 delta/zero. what exactly happend, that it returns 0. i cant figure it out. but in some magic way. sometine it works. without error.
HighRange = MitBuffer[ArrayMaximum(MitBuffer, Stochastic_period, i)];
LowRange = MitBuffer[ArrayMinimum(MitBuffer, Stochastic_period, i)];
i hoop that i cleared it up.
english is not my native language. sry
HighRange = MitBuffer[ArrayMaximum(MitBuffer, Stochastic_period, i)];
LowRange = MitBuffer[ArrayMinimum(MitBuffer, Stochastic_period, i)];
i hoop that i cleared it up. english is not my native language. sry
- We are under no obligation to run or debug your code for you. That is up to you to do. So if you require help, it is up to you to identify the offending line explicitly (such as highlighting it, for example) and reporting what error is reported by showing the log entry.
- When using ArrayMaximum or ArrayMinimum, you should always verify that the index they return is valid, before using it as an array index. You are not doing that. You cannot assume that they always return a valid index.
As per the documentation — "Return Value: The function returns an index of a found element taking into account the array serial. In case of failure it returns -1." - If HighRange and LowRange are both zero, or if there difference is zero, then obviously you will get a "divide by zero" error. So, you have to verify those conditions in your code and handle the outcome.
To identify the reasons for this, either place more "Print" statements in your code to log the various values for you monitor the outcome, or use the built-in debugger and place some breakpoints so you can monitor the variables and find the reason for the issue.
- We are under no obligation to run or debug your code for you. That is up to you to do. So if you require help, it is up to you to identify the offending line explicitly (such as highlighting it, for example) and reporting what error is reported by showing the log entry.
- When using ArrayMaximum or ArrayMinimum, you should always verify that the index they return is valid, before using it as an array index. You are not doing that. You cannot assume that they always return a valid index.
As per the documentation — "Return Value: The function returns an index of a found element taking into account the array serial. In case of failure it returns -1." - If HighRange and LowRange are both zero, or if there difference is zero, then obviously you will get a "divide by zero" error. So, you have to verify those conditions in your code and handle the outcome.
To identify the reasons for this, either place more "Print" statements in your code to log the various values for you monitor the outcome, or use the built-in debugger and place some breakpoints so you can monitor the variables and find the reason for the issue.
Thanks Fernando,
offcourse nobody is under any obligation. just thought out of cerioucity . point is noted for future.
"When using ArrayMaximum or ArrayMinimum" i tesetd
MitBuffer
it is always contain data. what do you mean with checking array index. how can i check it if it is valid index?
thanks
- docs.mql4.com
// the following code was not compiled or tested, but simply typed out int indexMax = ArrayMaximum( MitBuffer, Stochastic_period, i ); if( indexMax >= 0 ) { Print( "Valid index for maximum found: ", indexMax ); HighRange = MitBuffer[ indexMax ]; } else { Print( "Invalid index for maximum!" ); HighRange = some_default_value; };
indexH = ArrayMaximum(MitBuffer, Stochastic_period, i); indexL = ArrayMinimum(MitBuffer, Stochastic_period, i); if( indexH >= 0 && indexL >=0) { HighRange = MitBuffer[indexH]; LowRange = MitBuffer[indexL]; } else { //Print( "Invalid index for maximum!" ); HighRange = MitBuffer[ArrayMaximum(MitBuffer, Stochastic_period, i+1)]; LowRange = MitBuffer[ArrayMinimum(MitBuffer, Stochastic_period, i+1)]; };
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi All,
help is needed. anyone can change this code to multipair. i have tried it. something i am missing. at line 89 it is giving the error.
DSS = delta/(HighRange - LowRange)*100.0;
code is added. my change it here below.