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

1264

Hi!

I'm trying to understand how the s1 and s3 values are calculated in this for loop. How the initial values are calculated? Shouldn't be 0?

This is a for loop in the Damiani Volatmeter indicator.

```for(int i=loop_size;i>=0;i--)
{

double sa=iATR(NULL,0,Vis_atr,i);
double s1=vol_t[i+1];
double s3=vol_t[i+3];
if(lag_supressor)
vol= sa/iATR(NULL,0,Sed_atr,i)+lag_s_K*(s1-s3);
else
vol= sa/iATR(NULL,0,Sed_atr,i);

double anti_thres=iStdDev(NULL,0,Vis_std,0,MODE_LWMA,PRICE_TYPICAL,i);
anti_thres=anti_thres/
iStdDev(NULL,0,Sed_std,0,MODE_LWMA,PRICE_TYPICAL,i);

double t=Threshold_level;
t=t-anti_thres;

if(i==0)
{
if (vol>t){
SignalBuffer[0]=1.0;//set buffer
+" A("+ DoubleToStr(Vis_atr,0) +"/"+ DoubleToStr(Sed_atr,0) +")= "+DoubleToStr(vol,2)+ ", "
+DoubleToStr(Threshold_level,1)+" - S("+ DoubleToStr(Vis_std,0)+"/"+ DoubleToStr(Sed_std,0)  +")= "+DoubleToStr(t,2)+" ");}
else {
SignalBuffer[0]=2.0;//set buffer
+"A("+ DoubleToStr(Vis_atr,0) +"/"+ DoubleToStr(Sed_atr,0) +")= "+DoubleToStr(vol,2)+ ", "
+DoubleToStr(Threshold_level,1)+" - S("+ DoubleToStr(Vis_std,0)+"/"+ DoubleToStr(Sed_std,0)  +")= "+DoubleToStr(t,2)+" ");}
}

if (vol>t){vol_t[i]=vol;vol_m[i]=-1;}
else {vol_t[i]=vol;vol_m[i]=0.03;}

thresholdBuffer[i]=t;
}```
21956

Pedro Severin: I'm trying to understand how the s1 and s3 values are calculated in this for loop. How the initial values are calculated? Shouldn't be 0?
```      double s1=vol_t[i+1];
double s3=vol_t[i+3];
```
How should we know? You didn't show the code that initializes vol_t[].
If a variable is not initialized explicitly, the value stored in this variable can be any. Implicit initialization is not used.
Initialization of Variables - Variables - Language Basics - MQL4 Reference
1264

whroeder1:
How should we know? You didn't show the code that initializes vol_t[].

vol_t[] is defined as double vol_t[]; and not initialized at any particular value (as far as I understand).

I'm attaching the full code of the indicator. I don't understand how the initial values are calculated.

And how I can add this to an EA without using iCustom()? I would like to know how to code the logic behind of this.

Regards,

PS

Files:
21956

Pedro Severin: not initialized at any particular value (as far as I understand). I don't understand how the initial values are calculated.

1264

whroeder1:

Oh okay. Then would you mind explaining me how this indicator works?

I mean, how can I add this logic to an EA without using iCustom()? When I start the part that should do the calculations, I'm getting something different and it varies from time to time when I run the backtest.

21956

Pedro Severin: how can I add this logic to an EA without using iCustom()?
1. Don't try do that. There are no buffers, no IndicatorCounted() or prev_calculated. No way to know if older bars have changed or been added (history update.)
Just get the value(s) of the indicator(s) into the EA (using iCustom) and do what you want with it.
Detailed explanation of iCustom - MQL4 and MetaTrader 4 - MQL4 programming forum

General rules and best pratices of the Forum. - General - MQL5 programming forum
1264

whroeder1:
1. Don't try do that. There are no buffers, no IndicatorCounted() or prev_calculated. No way to know if older bars have changed or been added (history update.)
Just get the value(s) of the indicator(s) into the EA (using iCustom) and do what you want with it.
Detailed explanation of iCustom - MQL4 and MetaTrader 4 - MQL4 programming forum

General rules and best pratices of the Forum. - General - MQL5 programming forum
Hi whroeder,

1. I'm not in front of my pc right now, but I think there is an IndicatorCounted() at the very start of the start() function. Should that work? I would like to have the EA work not depending of other files. Is this a good idea?

2. As said before, this is the mt4 part of the forum and I asked an mt4 related question. Its true that I asked a similar question in the mt5 part of the forum, but also I asked other things and, most important, the question was mt5 related. Does this counts as double posting?

Regards,
PS
21956

Pedro Severin: Should that work?

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

The function returns the amount of bars not changed after the indicator had been launched last.
IndicatorCounted - Custom Indicators - MQL4 Reference
1194

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.
120

Pedro Severin:

Hi!

I'm trying to understand how the s1 and s3 values are calculated in this for loop. How the initial values are calculated? Shouldn't be 0?

This is a for loop in the Damiani Volatmeter indicator.

Hi jus I want to know how I ask something or open a new subject in the forum?

1264

Messeňger HệŢhống:

I did not understand anything you said, sorry.