Download MetaTrader 5
To add comments, please log in or register
Sell your CPU capacity and earn money!
Pierre Rougier
386
Pierre Rougier 2014.02.18 16:49 

Hello,

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

Any helps welcome.

Regards,

qjol
3243
qjol 2014.02.18 17:02  
iClose(...)
Pierre Rougier
386
Pierre Rougier 2014.02.18 17:18  
Thanks, but it's just the beginning.
I think there is a work to select the right Close[] with Time[]
Alain Verleyen
Moderator
28520
Alain Verleyen 2014.02.18 17:21  
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 ?
Simon Gniadkowski
Moderator
17962
Simon Gniadkowski 2014.02.18 17:42  
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
Pierre Rougier
386
Pierre Rougier 2014.02.18 22:19  
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);
  }
//+------------------------------------------------------------------+

Simon Gniadkowski
Moderator
17962
Simon Gniadkowski 2014.02.18 22:52  
maximagreenpips:
<REMOVED>
Please use the SRC button to post code . . .
Hybrid Theories
6
Hybrid Theories 2014.02.18 22:55  
//+------------------------------------------------------------------+
//|                                                      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);
  }
//+------------------------------------------------------------------+
Hybrid Theories
6
Hybrid Theories 2014.02.18 22:59  
RaptorUK:
Please use the SRC button to post code . . .


ok bro, thanks...
/
To add comments, please log in or register