# Can someone explain me how this inicial values are calculated? - page 2

1086

whroeder1:

Your question in #2 is about an EA. What part of "There are no IndicatorCounted()" is unclear?

Hi whroeder,

Maybe I'm wrong or I don't really understand how this works, but there is an IndicatorCounted() right at after the start() function.

```int start()
{
double vol=0;
//Print(ArraySize(vol_t));
int    not_changed_bars=IndicatorCounted();
.
.
.
}```

Isn't this what you are saying? If not, I guess I don't understand the real use of this or I'm not understanding you.

1086

lippmaje:
You can move the indicator logic into your EA but this requires quite some experience. You'd have to check when a new bar emerges and do the resizing of vol_t on your own. Should the EA be reloaded, all of those previously computed indicator values within vol_t would be gone.

How!! How can I do that! haha I'm trying but I can't manage it to work :(

So frustrating haha.

610

Pedro Severin:

How!! How can I do that! haha I'm trying but I can't manage it to work :(

So frustrating haha.

Why being frustrated about that if you have iCustom at least?

First, you need to detect when a new bar emerges. That is programmatically easy to handle and I advise you to search for it. I have no link at hand at the moment.

The more tricky part is to resize your array, so that vol_t[0] becomes vol_t[1], that is:

1. your array is being resized by +1, and
2. all values are shifted by 1 to the back, so that vol_t[0] is freed for the current bar.

Now, if you resize vol_t by +1 this would look like: ArrayResize(vol_t, ArraySize(vol_t)+1)

This is ok, but the problem here is that the new array element is at the bottom. But what you need is the new element at the top (vol_t[0]). You can handle this by reverting the array ordering before and after the resize operation.

Like so:

```double vol_t[];

int OnInit() {
ArraySetAsSeries(vol_t,false);
...
}

void OnTick() {
if(IsNewBar()) {
ArraySetAsSeries(vol_t,true);
ArrayResize(vol_t,ArraySize(vol_t)+1); // creates a new element at the end of vol_t
ArraySetAsSeries(vol_t,false); // the end of vol_t is now vol_t[0]
}
...
}
```

This is part two of the three problems I mentioned earlier. Part one, you have to find a solution for IsNewBar(), part three, what do you do if the EA is reloaded and all the content of vol_t is gone. Think about this, and bear in mind that you are not experienced in coding. I still advise that you stay with iCustom.

18310

Pedro Severin: Maybe I'm wrong or I don't really understand how this works, but there is an IndicatorCounted() right at after the start() function.

Isn't this what you are saying? If not, I guess I don't understand the real use of this or I'm not understanding you.

You can place one in your EA, that doesn't mean it works. Again What part of "There are no IndicatorCounted()" in EAs is unclear? What part of no auto-sizing/auto-initializing buffers in EAs is unclear?
Pedro Severin: . Should that work? I would like to have the EA work not depending of other files. Is this a good idea?
1. You've been told five times (5) that is is not a good idea.
2. If you don't want the EA's EX4 to require the indicator, just embed the other indicator(s) inside your indicator/EA. Add the CI(s) to your code as a resource.
Use the publicly released code - Expert Advisors and Automated Trading - MQL5 programming forum