3 bear (or more) 3 bull(or more) 3 bear(or more) - page 2

 
Dimitar Pavlov:
i already tried that  , and is not what i need  :/  i need something to count candles maybe. For example  we have 3 bearish (can be more but at least 3) then we have 3 bullish (can be more but at least 3) and finally we have to have 3 bearish , and we have alert.I hope you got what i mean :)

You do not have to re-invent the wheel it has all been done before.

long bar=Bars;

while(bar>0)
 {
  //Do something... 
  bar--;
 }
 
//+------------------------------------------------------------------+
//| 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[])
  {
//--- bars to count
   int begin=(prev_calculated<1)?rates_total-1:rates_total-prev_calculated;
//--- main loop
   for(int i=begin;i>=0;i--)
      Bull[i]=IsBull(rates_total,close,i)?low[i]-50*_Point:0xfff;
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool IsBull(int rates_total,const double &close[],int idx)
  {
   if(idx+60>rates_total)
      return(false);   
   int bull1=0,bear=0,bull2=0;
   for(int i=idx;i<idx+20;i++)
     { 
      if(close[i]>close[i+1])
         bull1++;
      else
         break;
     }
   if(bull1<3)
      return(false);   
//---
   for(int j=idx+bull1;j<idx+bull1+20;j++)
     {
      if(close[j]<close[j+1])
         bear++;
      else
         break;
     }
   if(bear<3)
      return(false);   
//---
   for(int k=idx+bull1+bear;k<idx+bull1+bear+20;k++)
     {
      if(close[k]>close[k+1])
         bull2++;
      else
         break;
     }
   if(bull2>2)
      return(true);
//---
   return(false);   
  }
//+------------------------------------------------------------------+
 

yes Ernst Van Der Merwe :) thanks , however i got error  on your code : 

'Bull' - undeclared identifier  

 
Dimitar Pavlov:

yes Ernst Van Der Merwe :) thanks , however i got error  on your code : 

'Bull' - undeclared identifier  

That's the index buffer.

double Bull[];
double Bear[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Bull);
   SetIndexStyle(0,DRAW_ARROW); 
   SetIndexArrow(0,233);
   SetIndexBuffer(1,Bear);
   SetIndexStyle(1,DRAW_ARROW); 
   SetIndexArrow(1,234);
   SetIndexEmptyValue(0,0xfff);
   SetIndexEmptyValue(1,0xfff);
//---
   return(INIT_SUCCEEDED);
  }
 

Ernst Van Der Merwe Is this correct ? because when i put on chart i dont see the arrows i even tried in strategy tester and still no arrows 

 

#property indicator_buffers 2
#property indicator_chart_window 
double Bull[];
double Bear[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Bull);
   SetIndexStyle(0,DRAW_ARROW); 
   SetIndexArrow(0,233);
   SetIndexBuffer(1,Bear);
   SetIndexStyle(1,DRAW_ARROW); 
   SetIndexArrow(1,234);
   SetIndexEmptyValue(0,0xfff);
   SetIndexEmptyValue(1,0xfff);
//---
   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[])
                
  {
//--- bars to count
   int begin=(prev_calculated<1)?rates_total-1:rates_total-prev_calculated;
//--- main loop
   for(int i=begin;i>=0;i--)
      Bull[i]=IsBull(rates_total,close,i)?low[i]-50*_Point:0xfff;
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool IsBull(int rates_total,const double &close[],int idx)
  {
   if(idx+60>rates_total)
      return(false);   
   int bull1=0,bear=0,bull2=0;
   for(int i=idx;i<idx+20;i++)
     { 
      if(close[i]>close[i+1])
         bull1++;
      else
         break;
     }
   if(bull1<3)
      return(false);   
//---
   for(int j=idx+bull1;j<idx+bull1+20;j++)
     {
      if(close[j]<close[j+1])
         bear++;
      else
         break;
     }
   if(bear<3)
      return(false);   
//---
   for(int k=idx+bull1+bear;k<idx+bull1+bear+20;k++)
     {
      if(close[k]>close[k+1])
         bull2++;
      else
         break;
     }
   if(bull2>2)
      return(true);
//---
   return(false);   
  }
//+------------------------------------------------------------------+
 

Colours...

#property indicator_color1 clrLimeGreen
#property indicator_color2 clrFireBrick
 
Thank you 
 
Dimitar Pavlov:
Thank you 
You're welcome.