Can someone explain me how this inicial values are calculated?

To add comments, please log in or register
Pedro Severin
1086
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.


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){
             if (lastAlert!=2) doAlerts("TRADE ALLOWED AGAIN - VOLATILITY OK!",SoundFileTradeAllowed); lastAlert=2;//alert stuff
             SignalBuffer[0]=1.0;//set buffer
             IndicatorShortName("Damiani: TRADE "
             +" 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 {
             if (lastAlert!=1) doAlerts("DO NOT TRADE - LOW VOLATILITY!",SoundFileTradeAllowed); lastAlert=1;//alert stuff
             SignalBuffer[0]=2.0;//set buffer
             IndicatorShortName("Damiani: DO NOT trade "
             +"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;   
   }
William Roeder
18310
William Roeder  
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
Pedro Severin
1086
Pedro Severin  
whroeder1:
How should we know? You didn't show the code that initializes vol_t[].

Hi whroeder, thank you for your reply.

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

William Roeder
18310
William Roeder  

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

I already answered that question by quoting the documentation.

Pedro Severin
1086
Pedro Severin  
whroeder1:

I already answered that question by quoting the documentation.

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.

William Roeder
18310
William Roeder  
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.
    You should encapsulate your iCustom calls to make your code self-documenting.
              Detailed explanation of iCustom - MQL4 and MetaTrader 4 - MQL4 programming forum

  2. Why did you start a new post when you already had one about this indicator already open? Don't double post!
              General rules and best pratices of the Forum. - General - MQL5 programming forum
Pedro Severin
1086
Pedro Severin  
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.
    You should encapsulate your iCustom calls to make your code self-documenting.
              Detailed explanation of iCustom - MQL4 and MetaTrader 4 - MQL4 programming forum

  2. Why did you start a new post when you already had one about this indicator already open? Don't double post!
              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
William Roeder
18310
William Roeder  
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
lippmaje
610
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.
Sanbach21
18
Sanbach21  
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?

Pedro Severin
1086
Pedro Severin  
Messeňger HệŢhống:

I did not understand anything you said, sorry.

12
To add comments, please log in or register