HELP! Custom Indicator

 

Please help me to design a custom indicator or point to one like this, that shows when 1)the current bar high is greater than the previous bar high

and the current bar close is higher than the previous bar close and 2)the current bar low is lower than the previous bar low

and the current bar close is lower than the previous bar close. I know it's a simple code but I'm an old log that can't rap his brain around it.

Thanks in advance!

 
jazzidee:

Please help me to design a custom indicator or point to one like this, that shows when 1)the current bar high is greater than the previous bar high

and the current bar close is higher than the previous bar close and 2)the current bar low is lower than the previous bar low

and the current bar close is lower than the previous bar close. I know it's a simple code but I'm an old log that can't rap his brain around it.

Thanks in advance!

Here you are:

//+------------------------------------------------------------------+
//|                                                    Indicator.mq4 |
//|                                                           GGekko |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "GGekko"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Lime
#property indicator_width1 2
#property indicator_width2 2

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,217);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,218);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexEmptyValue(1,0.0);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;


   for(int i=0; i<limit; i++)
      {
      if(High[i]>High[i+1] && Close[i]>Close[i+1])
      ExtMapBuffer1[i]=High[i];
      }
      
   for(i=0; i<limit; i++)
      {
      if(Low[i]<Low[i+1] && Close[i]<Close[i+1])
      ExtMapBuffer2[i]=Low[i];
      }
   
//---- done
   return(0);
  }
//+------------------------------------------------------------------+
Cheers
 
ggekko:

Here you are:

Cheers

Thank very much! You are the best

 
jazzidee:

Thank very much! You are the best

Hi jazzidee,


In the previous one there was a little bug: the last candle didn't redraw properly.

Here is the proper one:

//+------------------------------------------------------------------+
//|                                                    Indicator.mq4 |
//|                                                           GGekko |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "GGekko"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Lime
#property indicator_width1 1
#property indicator_width2 1

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,217);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,EMPTY_VALUE);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,218);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexEmptyValue(1,EMPTY_VALUE);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;


   for(int i=0; i<limit; i++)
      {
      if(High[i]>High[i+1] && Close[i]>Close[i+1]) ExtMapBuffer1[i]=High[i];
      else ExtMapBuffer1[i]=EMPTY_VALUE;
      }
      
   for(i=0; i<limit; i++)
      {
      if(Low[i]<Low[i+1] && Close[i]<Close[i+1]) ExtMapBuffer2[i]=Low[i];
      else ExtMapBuffer2[i]=EMPTY_VALUE;
      }
   
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

Hope, it helps.

Cheers

 
ggekko:

Hi jazzidee,


In the previous one there was a little bug: the last candle didn't redraw properly.

Here is the proper one:

Hope, it helps.

Cheers



OK, Thanks