Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 18
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
That's not very good. Did you probably get warnings at compile time? You need to get rid of the causes of the warnings in such cases, not #property strict
I have topped up my balance and now I can't find the terminal with the real account.
When #property strict was spelled out, the compiler generated errors in every for() loop that variables must have a type, so I had to write int i and int p in every loop. After that the compiler didn't generate errors, but the line didn't build. When I removed #property strict, the compiler did not require to declare the type in each loop, and the line was built.
A typical case of exploiting implicit errors in logic. Once the compiler has become "stricter", the self-deception is slowly disappearing.
I was wondering why there were so many identical loops?
And why don't you bother in any way with the error "out of array" when running the indicator on the chart?
For example, here:
{
for(int p=0; p<m; p++)
{
sum_x[i][p]=sum_x[i][p-1]+Price_CloseX[i][p];
sum_y[i][p]=sum_y[i][p-1]+Price_CloseY[i][p];
}
}
I have topped up my balance and now I can't find the terminal with the real account.
When #property strict was spelled out, the compiler gave errors in every for() loop that variables must have a type, and so I had to spell int i and int p in every loop. After that the compiler didn't generate errors, but the line didn't build. When I removed #property strict, the compiler no longer required to declare the type in each cycle, and the line was built.
the answer is very simple - you have a trivial array overrun - and your indicator stops working because of this error
{
for(int p=0; p<m; p++)
{
sum_x[i][p]=sum_x[i][p-1]+Price_CloseX[i][p];
sum_y[i][p]=sum_y[i][p-1]+Price_CloseY[i][p];
}
}
for(int i=1; i<n; i++)
{
for(int p=0; p<m; p++)
{
Mx[i][p]=sum_x[p+1][m-1]/(n-1);
My[i][p]=sum_y[p+1][m-1]/(n-1);
you can see this error at runtime - start the indicator and look at the log file on the Terminal - Experts tab:
This is a typical case of exploiting implicit logical errors. ...
A typical case of exploiting implicit errors in logic. Once the compiler has become "stricter", the self-deception is slowly disappearing.
I kept wondering, why are there so many identical loops?
And why don't you bother in any way with the error "out of array" when running the indicator on the chart?
For example, here:
{
for(int p=0; p<m; p++)
{
sum_x[i][p]=sum_x[i][p-1]+Price_CloseX[i][p];
sum_y[i][p]=sum_y[i][p-1]+Price_CloseY[i][p];
}
}
As for the same cycles, I, because of my limited knowledge of programming and algorithms, have not thought of anything better to select the element of the array from the required dimension, which was necessary for substitution in the formula.
the answer is very simple - you have a trivial array overrun - and your indicator stops working because of this error
{
for(int p=0; p<m; p++)
{
sum_x[i][p]=sum_x[i][p-1]+Price_CloseX[i][p];
sum_y[i][p]=sum_y[i][p-1]+Price_CloseY[i][p];
}
}
for(int i=1; i<n; i++)
{
for(int p=0; p<m; p++)
{
Mx[i][p]=sum_x[p+1][m-1]/(n-1);
My[i][p]=sum_y[p+1][m-1]/(n-1);
you can see this error at the execution stage - start the indicator and look at the log file on the Terminal tab - Experts:
Then how do you calculate the sum of the closing prices in each dimension???
As for the same cycles, due to my limited knowledge of programming and algorithms, I couldn't think of anything better to select that element of the array from the desired dimension, which was needed to substitute in the formula.
For example, like this:
for(int i=1; i<n; i++)
{for(int p=1; p<m; p++)
{
sum_x[i][p]=sum_x[i][p-1]+Price_CloseX[i][p];
sum_y[i][p]=sum_y[i][p-1]+Price_CloseY[i][p];
}
}
Can you please tell me how to fix this error?
To correct this error, you need to understand your formula - what, why and how you are counting.
And only then you will be able to work out your algorithm and eliminate the error outside the array.
By "gut feeling" method and not understanding your formula - you will eliminate error, but you will make wrong calculation.
p.s. Explain in detail what you are calculating -- comment on your code in detail -- and then we will understand how to fix the error.