The fact that it is a globally scoped variable means that it does not need to be passed as a parameter. It can be accessed directly.
// Untested, uncompiled example code — simply typed out double g_adbPrices[]; int GetPoints( int index ) { return (int) round( g_adbPrices[ index ] / _Point ); };
Do not post code that will not even compile.
myGvar[0]='123';
«'123'» is not a string (e.g. «"123"»). It is not a single charter (short). The array type is a double. So neither will work.
- ReLor2: After calling the function in global scope \
You can not call functions on global scope, call them in OnTick.
Is it possible to pass this array to a function, work, fill and change his values at the end at global scope, without knowing/working with the name of the global var inside the function?
Sure. Pass an array to a function by reference. Read the paragraph "References: Modifier & and Keyword this" from the documentation.
I use this very often.
Example:
double globalArr1[5]; double globalArr2[10]; void OnStart() { ArrayInitialize(globalArr1, 1.23); ArrayInitialize(globalArr2, 2.34); Print("first:"); printLastElement(globalArr1); Print("second:"); printLastElement(globalArr2); } void printLastElement(double &arr[]) { int lastIndex = ArraySize(arr) - 1; PrintFormat("Last index %i, value %.2f", lastIndex, arr[lastIndex]); }
- www.mql5.com
Sure. Pass an array to a function by reference. Read the paragraph "References: Modifier & and Keyword this" from the documentation.
I use this very often.
Example:
But in my example, it would be correct to use the const access specifier to explicitly indicate that the array cannot be modified by the function.
void printLastElement(const double &arr[]) { int lastIndex = ArraySize(arr) - 1; PrintFormat("Last index %i, value %.2f", lastIndex, arr[lastIndex]); }
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
i've the following basic question.
if i define a array in global scope.
Is it possible to pass this array to a function, work, fill and change his values at the end at global scope, without knowing/working with the name of the global var inside the function? For Example
I call the function
After calling the function in global scope Print(" Now it should be 123:"+myglobalarray[0]);
Is it possible, how? Is there may something special at passing the var to the function ?