Modifying a simple indi?

 

Dear guys,

 any chance to help me modify "daily open line" indicator into "H1 open line" indi??

 Cheers guys! 

Files:
 
charles1234:

Dear guys,

 any chance to help me modify "daily open line" indicator into "H1 open line" indi??

 Cheers guys! 

Use this - it can show open line for any available time frame

//------------------------------------------------------------------
#property copyright "Copyright 2016, mladen - MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//------------------------------------------------------------------
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1  clrDeepSkyBlue
#property indicator_style1  STYLE_DOT
#property strict

extern ENUM_TIMEFRAMES TimeFrame      = PERIOD_D1; // Time frame to use
extern int             TimeZoneOFData = 0;         // TimeZone
double line[];

//------------------------------------------------------------------
//
//------------------------------------------------------------------

int OnInit() { SetIndexBuffer(0, line); TimeFrame = MathMax(TimeFrame,_Period); return(0); }
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 counted_bars = prev_calculated;
      if(counted_bars < 0) return(-1);
      if(counted_bars > 0) counted_bars--;
           int limit=MathMin(rates_total-counted_bars,rates_total-1);

           for(int i=limit; i>=0; i--) line[i] = (i<Bars-1) ? (iBarShift(NULL,TimeFrame,time[i]+TimeZoneOFData*3600)==iBarShift(NULL,TimeFrame,time[i+1]+TimeZoneOFData*3600)) ? line[i+1] : open[i] : open[i];
   return(rates_total);
}
Files:
Open_line.mq4  2 kb
 
Mladen Rakic:

Use this - it can show open line for any available time frame

//------------------------------------------------------------------
#property copyright "Copyright 2016, mladen - MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//------------------------------------------------------------------
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1  clrDeepSkyBlue
#property indicator_style1  STYLE_DOT
#property strict

extern ENUM_TIMEFRAMES TimeFrame      = PERIOD_D1; // Time frame to use
extern int             TimeZoneOFData = 0;         // TimeZone
double line[];

//------------------------------------------------------------------
//
//------------------------------------------------------------------

int OnInit() { SetIndexBuffer(0, line); TimeFrame = MathMax(TimeFrame,_Period); return(0); }
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 counted_bars = prev_calculated;
      if(counted_bars < 0) return(-1);
      if(counted_bars > 0) counted_bars--;
           int limit=MathMin(rates_total-counted_bars,rates_total-1);

           for(int i=limit; i>=0; i--) line[i] = (i<Bars-1) ? (iBarShift(NULL,TimeFrame,time[i]+TimeZoneOFData*3600)==iBarShift(NULL,TimeFrame,time[i+1]+TimeZoneOFData*3600)) ? line[i+1] : open[i] : open[i];
   return(rates_total);
}

Hi!! Thanks a lot MLaden!!! :)

But could you kindly see if you can make it into something like this? (similar to "daily open line", H1 and H4 lines were drawn manually to show example)

http://i.imgur.com/D7terXF.png

So it's not a continuous line like a moving average. But a horizontal line that stop extending at the bar of chosen timeframe.

Thanks in advance, sir!!

Regards 

Files:
Screenshot2.png  43 kb
 
charles1234:

Hi!! Thanks a lot MLaden!!! :)

But could you kindly see if you can make it into something like this? (similar to "daily open line", H1 and H4 lines were drawn manually to show example)

http://i.imgur.com/D7terXF.png

So it's not a continuous line like a moving average. But a horizontal line that stop extending at the bar of chosen timeframe.

Thanks in advance, sir!!

Regards 

In that case you have to have a bit more complicated code

Like this :

//------------------------------------------------------------------
#property copyright "Copyright 2016, mladen - MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//------------------------------------------------------------------
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1  clrDeepSkyBlue
#property indicator_style1  STYLE_DOT
#property strict

extern ENUM_TIMEFRAMES TimeFrame      = PERIOD_D1; // Time frame to use
extern int             TimeZoneOFData = 0;         // TimeZone
double line[];

//------------------------------------------------------------------
//
//------------------------------------------------------------------

int OnInit() { SetIndexBuffer(0, line); TimeFrame = MathMax(TimeFrame,_Period); return(0); }
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 counted_bars = prev_calculated;
      if(counted_bars < 0) return(-1);
      if(counted_bars > 0) counted_bars--;
           int limit=MathMin(rates_total-counted_bars,rates_total-1);

           for(int i=limit; i>=0; i--)
               if (i<Bars-1)
                  if (iBarShift(NULL,TimeFrame,time[i]+TimeZoneOFData*3600)==iBarShift(NULL,TimeFrame,time[i+1]+TimeZoneOFData*3600))
                         line[i] =  line[i+1];
                  else { line[i] =  open[i]; if (TimeFrame!=_Period) line[i+1] = EMPTY_VALUE; }
               else      line[i] =  open[i];
   return(rates_total);
}
Replace the previous version with this one and you shall have discontinued lines - without a need to create objects - object could be more precise (you would not have that one empty bar) but would also create a whole lot of objects that is never a good idea with terminal, so this way would be something of a most efficient way for that task
Files:
Open_line.mq4  2 kb
 

Oh Man!!! Thank you soooooooooooo much Mladen!!!

This is  exactly what I'm looking for!! What a great coder you are to consider about the object and stuffs!!! Totally thankful for your kind thought and effort to code the indi!!! This is amazing! :)

God bless you, my friend!

Cheers and green pips to you!