Consecutive higher highs / lower lows determined by input variable

 

Hi

 

I am trying to create a signal where the entry bar must appear after a certain number of higher highs or lower lows.

eg like an outside bar / inside bar / pin bar.

So affectively i want a check to make sure the bar is in a good "location" ie top or bottom of a swing for example.

 

I tried to using this code, which works to a degree, but it will only give my the high or low based on the mVal setting. ie if i set the mVal variable to 3 then only the third high or low is reported.

What i would like to do is make mVal be the minimum number of bars that need to be considered.

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue  
#property indicator_color2 Red
#property indicator_width1  0
#property indicator_width2  0

extern int mHist = 1000, mVal = 5;
extern double mGap = 0;
extern bool mAlert = true;
double mHigh[], mLow[];
int mHighCount = 0, mLowCount = 0, mTime = 0;

//-----------------------------------------------------------------------------
void init() {
  SetIndexBuffer(0, mHigh);
  SetIndexBuffer(1, mLow);
  
  SetIndexEmptyValue(0, 0);
  SetIndexEmptyValue(1, 0);
  
  SetIndexStyle(0, DRAW_ARROW);
  SetIndexArrow(0, 233);

  SetIndexStyle(1, DRAW_ARROW);
  SetIndexArrow(1, 234);  
  
  if(Digits == 3 || Digits ==5)
    mGap = mGap * Point * 10;
  else
    mGap = mGap * Point;
}

//-----------------------------------------------------------------------------
void start() 
{
    
  for (int i = mHist; i >= mVal; i--) // replace 1 with mval
  {
    if(High[i] >= High[i+1]) 
      {
       mHighCount++;
       if(mHighCount == mVal)
        {
         mHigh[i] = High[i] - mGap;
         if(mAlert && i == 1 && Time[i] > mTime)
          {
           Alert(TimeHour(TimeCurrent()), ":", TimeMinute(TimeCurrent()), "  ", 
                  Symbol(), "  ", Period(), "m  High ", High[i]);
           mTime = Time[i];
          }
        }
      }
    else
      mHighCount = 0;

    if(Low[i] <= Low[i+1]) 
      {
       mLowCount++;
       if(mLowCount == mVal)
        {
         mLow[i] = Low[i] + mGap;
         if(mAlert && i == 1 && Time[i] > mTime)
          {
           Alert(TimeHour(TimeCurrent()), ":", TimeMinute(TimeCurrent()), "  ", 
                  Symbol(), "  ", Period(), "m  Low ", Low[i]);
           mTime = Time[i];
          }
        }
      }
    else
      mLowCount = 0;
      
  }

  return(0);
}

//-----------------------------------------------------------------------------
void deinit()
 {

 }

 

 in the for loop i changed 

 for (int i = mHist; i >= 1; i--)

 to be >= mVAL  but this didin't seem to make a difference.

 

Any ideas how i can make mVal effectively be the minimum value, so that when  i use the icustom function in the EA, it then returns the last high or low even if there are a greater number of consecutive bars, than specified by mVal?

 

eg

ll = iCustom(NULL,ExtPinBarTF,"SCS_ConsecHL",mHist,mVal,mGap,mAlert,1,1);

hh = iCustom(NULL,ExtPinBarTF,"SCS_ConsecHL",mHist,mVal,mGap,mAlert,0,1);

 

 

thanks

Simon 

 

The only way  I have found to do that :

  static int cpte_higher =0;
  double atr = iATR(NULL,0,500,i);

      if(High[i] >= High[i+1])   higher[i]= High[i]+0.25*atr;
      if(High[i] < High[i+1])     higher[i] = 0.0;  

       if(higher[i] != 0.0 )  cpte_higher++;
       if(higher[i] == 0.0 )  cpte_higher=0;
    
       cpte_high[i] = cpte_higher;
       
      if( cpte_high[i+1] > 4.0 &&   cpte_high[i] == 0) mHigh[i] = High[i]+atr;
      else                                             mHigh[i] = 0.0;
       


You have to use an array to count the higher high, but doing cpte_high[i]++; do not work;

one's have to use a static intermediary counter cpte_higher++;

then pass it to the array : cpte_high[i] = cpte_higher;


For the high only :

Files:
 
simoncs: So affectively i want a check to make sure the bar is in a good "location" ie top or bottom of a swing for example.
See my code last swing high or swing low - MQL4 forum
 

thanks ffoorr - i looked at your code and it seemed to be adding a dot to bars that were also lower highs? so i wasn't sure what the intention was. I also didn't quite understand the relevance of using ATR? can you elaborate further please?

 

WHR - i am not sure i follow that code -  a little complex for me :( - if seemed to relate to picking swing tops/bottoms in a similar way to fractals? ie one would need to wait for the bars either side of the high or low to confirm the swing? I don;t really want to wait that long.

I have attached a pic that might explain better.

There are 5 lower lows, the fifth in this case being the signal bar, and the entry would be the bar afterwards (indicated by red arrow). I would like to be able to set an external variable to say 3 as a minimum, so that if there were more lower lows than that, the signal is still valid. 

 As the entry bar (current bar) is the other side of the signal bar i was using icustom with a shift of 1.

 

Would i be better off trying to count bars? and record this in a static variable where they meet the criteria? 

 

 

 
any thoughts?
Reason: