//+------------------------------------------------------------------+
//|                                                 Crystal Ball.mq4 |
//+------------------------------------------------------------------+

#property indicator_chart_window

extern int     ProjectionPoints = 15;

string  IndiName         = "Crystal";

//+------------------------------------------------------------------+
int init()  {
//+------------------------------------------------------------------+
  double x = MathAbs(Close[1]-Close[2])/Point;
  MathSrand(x);
  double r = 0;
  for (int i=1; i<=20; i++)  {
    r += (High[i] - Low[i]) / 10;
  }
  
  datetime t = Time[0];
  datetime tp = t;
  x = Close[0];
  double xp = x;
  for (i=1; i<ProjectionPoints; i++)  {
    double p = (MathRand()*r/32767) - r/2;
    xp = x;
    x += p;
    tp = t;
    t += Period()*60;
    ObjectCreate("Crystal"+i,OBJ_TREND,0,tp,xp,t,x);
    ObjectSet("Crystal"+i,OBJPROP_COLOR,Red);
    ObjectSet("Crystal"+i,OBJPROP_STYLE,STYLE_DOT);
    ObjectSet("Crystal"+i,OBJPROP_RAY,false);
  }
  return(0);

}

//+------------------------------------------------------------------+
int deinit()  {
//+------------------------------------------------------------------+
  int k=0;
  while (k<ObjectsTotal())   {
    string objname = ObjectName(k);
    if (StringSubstr(objname,0,StringLen(IndiName)) == IndiName)  
      ObjectDelete(objname);
    else
      k++;
  }    
  return(0);
}


//+------------------------------------------------------------------+
int start()   {
//+------------------------------------------------------------------+
  return(0);
}
//+------------------------------------------------------------------+