How to display, with a indicator, the Weekly Close, in a Daily or H4 graph ?

 

Hello,

How to display, with a indicator, the Weekly Close, in a Daily or H4 graph ?

Any helps welcome.

Regards,

 
iClose(...)
 
Thanks, but it's just the beginning.
I think there is a work to select the right Close[] with Time[]
 
tintin92:
Thanks, but it's just the beginning.
I think there is a work to select the right Close[] with Time[]
What have you tried ?
 
tintin92:
Thanks, but it's just the beginning.
I think there is a work to select the right Close[] with Time[]
Not Close[] . . . or Time[]. iClose() <---- click me
 
Tested with period of time 5 minutes and 1 mins:

Surely improvable.

//+------------------------------------------------------------------+
//|                                                      idClose.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

#property indicator_chart_window 
#property indicator_buffers 1 
#property indicator_color1 Red 

//---- buffers 
double Close_Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Close_Buffer);
   SetIndexLabel(0,"Close");
//---
   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[])
  {
//---

   datetime DateScan,DateWeek;
   int iWeek;
   int limit=(Bars-IndicatorCounted())-1;
   int limitWeek=iBars(NULL,PERIOD_M5)-1;
   for(int i=limit; i>=0; i--)
     {
      DateScan=Time[i];
      for(iWeek=limitWeek; iWeek>=0; iWeek--)
        {
         DateWeek=iTime(NULL,PERIOD_M5,iWeek);
         if(DateWeek>DateScan)
           {
            iWeek++;
            iWeek++;
            break;
           }
        }
      if(iWeek<0)
        {Close_Buffer[i]=iClose(NULL,PERIOD_M5,1);}
      else
        {Close_Buffer[i]=iClose(NULL,PERIOD_M5,iWeek);}
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

 
maximagreenpips:
<REMOVED>
Please use the SRC button to post code . . .
 
//+------------------------------------------------------------------+
//|                                                      idClose.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

#property indicator_chart_window 
#property indicator_buffers 1 
#property indicator_color1 Yellow 

//---- buffers 
double Close_Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Close_Buffer);
   SetIndexLabel(0,"Close");
//---
   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[])
  {
//---

   datetime DateScan,DateWeek;
   int iWeek;
   int limit=(Bars-IndicatorCounted())-1;
   int limitWeek=iBars(NULL,PERIOD_W1)-1;
   for(int i=limit; i>=0; i--)
     {
      DateScan=Time[i];
      for(iWeek=limitWeek; iWeek>=0; iWeek--)
        {
         DateWeek=iTime(NULL,PERIOD_W1,iWeek);
         if(DateWeek>DateScan)
           {
            iWeek++;
            iWeek++;
            break;
           }
        }
      if(iWeek<0)
        {Close_Buffer[i]=iClose(NULL,PERIOD_W1,1);}
      else
        {Close_Buffer[i]=iClose(NULL,PERIOD_W1,iWeek);}
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
RaptorUK:
Please use the SRC button to post code . . .


ok bro, thanks...
Reason: