This is the function that has error. When i used debugger, Exception thrown at 0x00509159 in FA.exe: 0xC0000005: Access violation reading location 0x0040400C. was shown at line at price_total += forex[i].price;.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
void calculate_SMA(int time_frame, int count, DATA forex[])
{
double sma, price_total;
for (int j = time_frame - 1; j < count; j++)
{
price_total = 0.0;
for (int i = 0; i < i + time_frame; i++)
price_total += forex[i].price;
forex[j].SMA = price_total / time_frame;
cout << forex[j].SMA << endl;
}
}
Although why is price in the struct at all? It's a number, you use it as a number, you never actually use the price value in the struct; why does it exist at all in the struct?
Why is SMA and EMA ten objects, instead of just one? Why is it not this?
1 2 3 4
struct DATA
{
double SMA;
};
which is everything being used. Which raises the question, why does this struct exist at all?
oh yeah... but how can i make it increase accordingly everytime my i increase, for example, if my time_frame=5, i want the loop to add all numbers from array index 0 to 4, then for the second time, i want the loop to add all the numbers from array index 1 to 5