How to separate day of the week in indicator?

To add comments, please log in or register
Flat_white-1s
7
Flat_white-1s  

Hi guys, 

I have just started learning coding with mql4 and really need someone to help me and to teach. I am trying to make an indicator that shows a chart of average volatility of an hour of one day of the week fro n-weeks.

So, calculations are following: I take an hour (for an example 1 am on Monday) and find its volatility. Then I do the same for same 1 am but for the Monday from the week before, then for 1 am Monday from 2 weeks before and so on. Then I take an average of volatility  for all 1 am hours for n-weeks.

The current code draws it for all days of a week as one line and I want to learn how to make it to calculate only one specific day of the week and void calculating the others. Hopefully I was clear enough, sorry for my English

Code is following:

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1 
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrBlue 
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2

//--- input parameters
input int      CountBars=1400; 
input int      k=700;
//--- indicator buffers
double         Label1Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         | 
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping 
   SetIndexBuffer(0,Label1Buffer);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              | 
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated, 
                const datetime &time[],
                const double &open[], 
                const double &high[],
                const double &low[], 
                const double &close[],
                const long &tick_volume[], 
                const long &volume[],
                const int &spread[]) 
  {
      int shift, j, shet;
      datetime barhour, barminute, bardayofweek;
      double Vola; 


//----

//----
j=k; 
while(j>=0)
   {
      shift = CountBars+j;
      bardayofweek = TimeDayOfWeek( Time[j]); 
      barhour = TimeHour( Time[j]);
      barminute = TimeMinute( Time[j]); 
      Vola = High[j] - Low[j]; 
      shet = 1;
         while(shift > j )
            { 
               if( barhour == TimeHour( Time[shift]) && barminute == TimeMinute( Time[shift]) && bardayofweek == TimeDayOfWeek( Time[shift]))  
                  { 
                     Vola = Vola + (High[shift]-Low[shift]); 
                     shet++;
                  }   
               shift--;
            }
     Label1Buffer[j]= (Vola/Point)/shet; 
j--;

   }   
//----
return(0);
}
William Roeder
20233
William Roeder  
Flat_white-1s: d I want to learn how to make it to calculate only one specific day of the week and void calculating the others.
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. Why did you post your MT4 question in the Root / MT5 Indicators section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  3. You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
              No free help
              urgent help.


  4. input int      k=700;
    int OnCalculate(…){
    j=k;
    while(j>=0)
    Don't compute all bars, every tick.
              How to do your lookbacks correctly.

To add comments, please log in or register