mql4 function with array: error parameter conversion not allowed
mql4 function with array: error parameter conversion not allowed
Loading saved threads...
user310291 · External communityPost link
External question — Stack Overflow Stack Exchange
Author: user310291
Original post: https://stackoverflow.com/questions/76200381
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I created this function and put it above init() but got error parameter conversion not allowed, I don't understand why :
int BelongsToArray(int value, int[] array)
{
int arrSize = ArraySize(array);
for(int i=0; i<arrSize; i++)
{
if(value == array[i])
{
return true; // value belongs to array
}
}
return false; // value does not belong to array
}
Quote
Report
Jalal Nouri · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: Jalal Nouri
Original post: https://stackoverflow.com/a/76205105
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
This function only accepts integer type array, but in the body of your code, you must have given it an array that is not an integer type (such as
double
) as input. So, to find the cause of the error, refer to the places in your code where you have called this function (that is,
BelongsToArray
).
Also in the function argument part, the second input, the array must be passed by reference. Therefore, it should be corrected as follows:
int BelongsToArray(int value, int &array[])
I have a suggestion. Because the output of the function is boolean, it is better to use
bool
instead of
int
in the header of the function. However, if this is not done, the code will still work correctly.
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External answer — Stack Overflow Stack Exchange Author: Jalal Nouri Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/a/76205105 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. This function only accepts integer type array, but in the body of your code, you must have given it an array that is not an integer type (such as double ) as input. So, to find the cause of the error, refer to the places in your code where you have called this function (that is, BelongsToArray ). Also in the function argument part, the second input, the array must be passed by reference. Therefore, it should be corrected as follows: int BelongsToArray(int value, int &array[]) I have a suggestion. Because the output of the function is boolean, it is better to use bool instead of int in the header of the function. However, if this is not done, the code will still work correctly.
Checking account access…