Divergent Bar

 

Hi all,

Does anybody know how to program a divergent bar (Bill Williams)? Basically I need to program 2 types of bars (candles) based on different time frames. The first is the bullish divergent bar where the low price is lower than the previous bar and the close price is within the top half between High/Low. Reverse for the bearish divergent bar where the high of the bar is higher than the one prior and the close price is within the bottom half bewteen High/Low. What I would like is a warning that there is a divergent bar on a particular currency at a particular time frame. I would then check the bar and its angle to the Alligator and decide if I want to make the trade.

Thanks for the help.

 
This should do. Not tested though.

bool bullish, bearish;
int BarsCount;
 
int start()
  {
    bullish = false;
    bearish = false; 

    if (Bars > BarsCount)
    {
      //bullish bar 
      if ( (Low[1] < Low[2]) && (Close[1] > (High[1] + Low[1])/2) )  bullish = true;
      //bearish bar 
      if ( (High[1] > High[2]) && (Close[1] < (High[1] + Low[1])/2) )  bearish = true;
      
      //alerts
      if (bullish) Alert("Bullish divergent bar on  ", Symbol(), " ", Period());
      if (bearish) Alert("Bearish divergent bar on  ", Symbol(), " ", Period());
 
      BarsCount = Bars;
      
    }   
 
   return(0);
  }
Files:
 
janklimo:
This should do. Not tested though.

bool bullish, bearish;
int BarsCount;
 
int start()
  {
    bullish = false;
    bearish = false; 

    if (Bars > BarsCount)
    {
      //bullish bar 
      if ( (Low[1] < Low[2]) && (Close[1] > (High[1] + Low[1])/2) )  bullish = true;
      //bearish bar 
      if ( (High[1] > High[2]) && (Close[1] < (High[1] + Low[1])/2) )  bearish = true;
      
      //alerts
      if (bullish) Alert("Bullish divergent bar on  ", Symbol(), " ", Period());
      if (bearish) Alert("Bearish divergent bar on  ", Symbol(), " ", Period());
 
      BarsCount = Bars;
      
    }   
 
   return(0);
  }


janklimo wrote:

This should do. Not tested though.

bool bullish, bearish;
int BarsCount;
 
int start()
  {
    bullish = false;
    bearish = false; 

    if (Bars > BarsCount)
    {
      //bullish bar 
      if ( (Low[1] < Low[2]) && (Close[1] > (High[1] + Low[1])/2) )  bullish = true;
      //bearish bar 
      if ( (High[1] > High[2]) && (Close[1] < (High[1] + Low[1])/2) )  bearish = true;
      
      //alerts
      if (bullish) Alert("Bullish divergent bar on  ", Symbol(), " ", Period());
      if (bearish) Alert("Bearish divergent bar on  ", Symbol(), " ", Period());
 
      BarsCount = Bars;
      
    }   
 
   return(0);
  }

 
janklimo:
This should do. Not tested though.

bool bullish, bearish;
int BarsCount;
 
int start()
  {
    bullish = false;
    bearish = false; 

    if (Bars > BarsCount)
    {
      //bullish bar 
      if ( (Low[1] < Low[2]) && (Close[1] > (High[1] + Low[1])/2) )  bullish = true;
      //bearish bar 
      if ( (High[1] > High[2]) && (Close[1] < (High[1] + Low[1])/2) )  bearish = true;
      
      //alerts
      if (bullish) Alert("Bullish divergent bar on  ", Symbol(), " ", Period());
      if (bearish) Alert("Bearish divergent bar on  ", Symbol(), " ", Period());
 
      BarsCount = Bars;
      
    }   
 
   return(0);
  }

 
slibi11 wrote >>


all signals indicators by trading chaos strategy >>>>>
Reason: