mql4mql

Collect Price values High[0] to High[50] mql4


I was creating a for loop that looks for mean of price within a set array of 50. the difficulty I am having is with the collection and storage of High[0] to High[50] (Low[0] to Low[50]) data for the mean equation M= (Total Value/nbars)

I was trying to follow C++:

float arithmeticMean(float [], int);
int main()
{
    int n, i;
    float arr[50], armean;
    cout<<"Enter the Size (maz. 50): ";
    cin>>n;
    cout<<"\nEnter "<<n<<" Numbers: ";
    for(i=0; i<n; i++)
        cin>>arr[i];
    armean = arithmeticMean(arr, n);
    cout<<"\nArithmetic Mean = "<<armean;
    cout<<endl;
    return 0;
}
float arithmeticMean(float arr[], int n)
{
    int i;
    float sum=0, am;
    for(i=0; i<n; i++)
        sum = sum+arr[i];
    am = sum/n;
    return am;
}

And I attempted to resize the buffer and store price values, but this isn't correct, ideas?:

{
int d = High[50]+Low[50];
double rb[],armean;
for(int s=-1; Close[s]<d; Close[s++]) //Array Iteration Loop Forward BarsToCheck
{
double Meansize = ArrayResize(rb,s);
double sum = Meansize+rb[s];
}
armean = sum/d;
}

Solution

  • You are really getting things confused, just keep it simple. Also remember that arrays are 0 based, therefore, if you want to count 50 items you will run from 0 to 49.

    double total=0.0;
    int count=50;
    for(int i=count-1; i>=0; i--) total+=High[i];
    double mean=total/count;