# Array size based on input.

I’ve made an EA which plots a small chart on the top left of the current chart.

Currently I’m using the CGraphic library to do this, and it needs x and y values to plot.

I’d want to have an input to the EA for the period, which would then change how far back the current chart goes, but I don’t know how I can vary the quantity of data points based on the input value.

Ie. If the input is 5 periods, the x[] array would be {1,2,3,4,5}, but if the input is 10 periods the x[] array would be {1,2,3,4,5,6,7,8,9,10}.

Please can someone point me in the right direction to do this?

Benjamin David Hardman: I don’t know how I can vary the quantity of data points based on the input value.

Ie. If the input is 5 periods, the x[] array would be {1,2,3,4,5}, but if the input is 10 periods the x[] array would be {1,2,3,4,5,6,7,8,9,10}.

Please can someone point me in the right direction to do this?
1. Resize your array. Perhaps you should read the manual. ArrayResize - Array Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
How To Ask Questions The Smart Way. (2004)
RTFM and STFW: How To Tell You've Seriously Screwed Up.

2. Populate your array. Perhaps you should read the manual. Loop Operator for - Operators - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
How To Ask Questions The Smart Way. (2004)
RTFM and STFW: How To Tell You've Seriously Screwed Up.

Okay, I thought id be able to use a for loop to do it, but I'm struggling to understand populating a series using a for loop.

```double   ema[];
int      ema_def = iMA(Symbol(),Period(),50,0,MODE_EMA,PRICE_CLOSE);
ArraySetAsSeries(ema,true);
CopyBuffer(ema_def,0,0,10,ema);```

And then I want to plot the the ema on my small chart for X periods depending on the input:

```input int periods = 5;
```

I'd want my x and y co-ordinate arrays to automatically resize using these values:

```double x[] = {1,2,3,4,5};
double y[] = {ema[4], ema[3], ema[2], ema[1], ema[0]};```

Could I use a combination of ArrayResize() and a for loop to do this?

Because if I wanted to plot 150 ema values, it would end up being a pain to do manually!