'How do I resize and populate an array using price values?

I’m looking for some help in methods to vary the size of an array which is automatically filled with data.

For example, I would like to plot a chart of EMA values with a user input to choose how many x-values are displayed.

I can do this manually, say by deciding to plot 5 values:

double x_axis[] = {1,2,3,4,5};
double y_axis[] = {ema[5],ema[4], ema[3], ema[2], ema[1]};

But say for example I wanted 100 values on the x-axis, how could I automate this?

Would I use a for loop using the input value?

Please help!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source