//+--------------------------------------------------------------------------------------+
//                                                F R A C T A L       C H A N N E L      |
//                                        Copyright © RickD  BJF Trading Group 2006      |
//                                                             http://fxstrategy.ca      |
//                                                                                       |
//Experts http://fxstrategy.ca/experts.php      SALE! 50% OFF                            |
//Indicators http://fxstrategy.ca/products.php  SALE!50% OFF                             |
//Digital Filters Strategy http://fxstrategy.ca/digital_filtrs.php  SALE!50% OFF         |
//Trading Signals http://fxstrategy.ca/signals.php Two weeks FREE! No CC.                |
// forex calendar, research, article ....                                                |
//+--------------------------------------------------------------------------------------+
#property copyright "© RickD  BJF Trading Group 2006"                                    
#property link      "http://fxstrategy.ca/products.php"
#property  indicator_chart_window
#property  indicator_buffers 0

extern int cnt = 20;
extern color HHTL_color =C'255,25,25';
extern color LLTL_color =C'45,45,255';




//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void init() {
  clear();
  show();
}

void deinit() {
  clear();
}

void start() 
{
  show();
}

void show() {
  
  string name = "";

  double fr1, fr2;
  int bar1, bar2;

  int i = 2;
  for (int j=0; j < cnt; j++) {
  
    for (; i < Bars; i++) {
      fr1 = iFractals(NULL, 0, MODE_UPPER, i);
      if (fr1 > 0) {
        bar1 = i;
        break;
      }
    }

    for (i=i+2; i < Bars; i++) {
      fr2 = iFractals(NULL, 0, MODE_UPPER, i);
      if (fr2 > 0) {
        bar2 = i;
        break;
      }
    }
  

    name ="R" + j;
    if (ObjectFind(name) == -1) {
      ObjectCreate(name, OBJ_TREND, 0, Time[bar2], fr2, Time[bar1], fr1);
      ObjectSet(name, OBJPROP_COLOR, HHTL_color);
      ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet(name, OBJPROP_WIDTH, 0);
      ObjectSet(name, OBJPROP_RAY, j==0);
      
     
    }
    else
    {
      ObjectMove(name, 0, Time[bar2], fr2);
      ObjectMove(name, 1, Time[bar1], fr1);
    }
  }

  i = 2;
  for (j=0; j < cnt; j++) {
    for (; i < Bars; i++) {
      fr1 = iFractals(NULL, 0, MODE_LOWER, i);
      if (fr1 > 0) {
        bar1 = i;
        break;
      }
    }

    for (i=i+2; i < Bars; i++) {
      fr2 = iFractals(NULL, 0, MODE_LOWER, i);
      if (fr2 > 0) {
        bar2 = i;
        break;
      }
    }

    name ="S" + j;
    if (ObjectFind(name) == -1) {
      ObjectCreate(name, OBJ_TREND, 0, Time[bar2], fr2, Time[bar1], fr1);
      ObjectSet(name, OBJPROP_COLOR, LLTL_color);
      ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet(name, OBJPROP_WIDTH, 0);
      ObjectSet(name, OBJPROP_RAY, j==0);
    }
    else
    {
      ObjectMove(name, 0, Time[bar2], fr2);
      ObjectMove(name, 1, Time[bar1], fr1);
    }
  }  
}

void clear() 
{
  string name = "";
  int res = -1;

  for (int j=0; j < cnt; j++) {  
    name = "R" + j;
    if (ObjectFind(name) != -1) ObjectDelete(name);

    name = "S" + j;
    if (ObjectFind(name) != -1) ObjectDelete(name);
  }
}