//+------------------------------------------------------------------+
//|                                                     FiboDraw.mq4 |
//|                                                      nicholishen |
//|                                   www.reddit.com/u/nicholishenFX |
//+------------------------------------------------------------------+
#property copyright "nicholishen"
#property link      "www.reddit.com/u/nicholishenFX"
#property version   "1.00"
#property strict
#include <ChartObjects\ChartObjectsFibo.mqh>
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{
//---
  // ObjectDelete(0,"myFibo");
   //--- getting fibo anchor points from zigzag
   struct myAnchors 
   { 
      double price; 
      datetime time; 
      myAnchors():price(0.0),time(NULL){} 
   }  anchors[2];


/*   int index = -1;
   for(int i=0;i<Bars(Symbol(),Period());i++)
   {
      double val = iCustom(Symbol(),Period(),"ZigZag",15,5,3,0,i);
      if((val != 0.0 || val != EMPTY_VALUE) && val > 0.0)
      {
         if(index >=0)
         {
            anchors[index].price = val;
            anchors[index].time  = iTime(Symbol(),Period(),i);
         }
         index++;
         if(index >=2)
            break;
      }
   }
 */ 
            anchors[1].price = High[0];
            anchors[1].time  = iTime(Symbol(),Period(),0);
            anchors[0].price = High[0]-((High[0]-Low[0])/2);
            anchors[0].time  = iTime(Symbol(),Period(),0);
 
   //--- declare and create an object of fibo class
   CChartObjectFibo fibo;
   fibo.Create(0,                //chartID
               "myFibo"+TimeToStr(TimeLocal(),TIME_DATE|TIME_SECONDS),         //chart object name
               0,                //subwindow
               anchors[1].time,  //time 1
               anchors[1].price, //price 1
               anchors[0].time,  //time 2
               anchors[0].price  //price 2
               );
   
   //--- setting new levels because we want 76.4 and no extensions, otherwise this step is not necessary 
   double levels[10] = {-9, -7, -5, -3, -1, 1, 3, 5, 7, 9} ;
   string levelname[10] = {"4R","3R","2R","1R","S","L","1R","2R","3R","4R"}; 
   fibo.LevelsCount(10);   
   for(int i=0;i<ArraySize(levels);i++)
   {
      fibo.LevelValue(i,levels[i]);
      fibo.LevelDescription(i,levelname[i]);
      fibo.LevelColor(i,clrBlack);
   }    
// turn off ray
   fibo.RayRight(0);
   //leave object on chart after object is destroyed
   fibo.Detach();
  
}
//+------------------------------------------------------------------+