//+------------------------------------------------------------------+
//|                                           SRDC Fibo AHA V0_4a.mq4 |
//|                                             Copyright ?2006, AHA |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2006, AHA"
#property link      ""

// v0.4a_reversed
// Reversed by itLogics

// v0.4a
// Modified by Proverbs to include more Fibo levels.

// v0.4
// Fixed a minor bug about displaying level 0 description and prices.

// v0.3
// Allow to show the price level of each fibo level.

// v0.2
// Draw Monday Fibo from Friday's data instead of Sunday.


#property indicator_chart_window
extern color dailyfibocolor=Blue;
extern bool  showprice=true;

string fiboobjname="Daily Fibo from SRDC Fibo AHA";
bool startup;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   startup=true;
   ObjectDelete(fiboobjname);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectDelete(fiboobjname);
   
//----
   return(0);
  }
void drawdailyfibo()
{
   if(TimeDay(Time[0])==TimeDay(Time[1])&&!startup&&ObjectFind(fiboobjname)!=-1) return;
   ObjectDelete(fiboobjname);
   
   datetime aday=iTime(NULL,PERIOD_D1,1);
   if(TimeDayOfWeek(aday)==0) aday=iTime(NULL,PERIOD_D1,2);
   int bar=iBarShift(NULL,0,aday);
   double dailyhigh=0.0, dailylow=100000.0;
   int highbar, lowbar, i=bar;
   string temp_str="     %$";
   if(!showprice) temp_str="";
   
   while(TimeDay(iTime(NULL,0,i))==TimeDay(iTime(NULL,0,bar)))
   {
      if(iHigh(NULL,0,i)>dailyhigh)
      {
         dailyhigh=iHigh(NULL,0,i);
         highbar=i;
      }
      if(iLow(NULL,0,i)<dailylow)
      {
         dailylow=iLow(NULL,0,i);
         lowbar=i;
      }
      i--;
   }
   if (highbar>lowbar) 
     ObjectCreate(fiboobjname, OBJ_FIBO, 0, Time[highbar], dailyhigh, Time[lowbar], dailylow);   
   else if (highbar<lowbar) 
     ObjectCreate(fiboobjname, OBJ_FIBO, 0, Time[lowbar], dailylow, Time[highbar], dailyhigh);
   else 
   {
      if (Close[highbar]>Open[highbar])
         ObjectCreate(fiboobjname, OBJ_FIBO, 0, Time[highbar], dailyhigh, Time[lowbar], dailylow);
      else if (Close[highbar]>Open[highbar])
         ObjectCreate(fiboobjname, OBJ_FIBO, 0, Time[lowbar], dailylow, Time[highbar], dailyhigh);
   }   
   ObjectSet(fiboobjname, OBJPROP_LEVELCOLOR, dailyfibocolor);
   ObjectSet(fiboobjname, OBJPROP_FIBOLEVELS, 21);
   ObjectSet(fiboobjname, OBJPROP_LEVELSTYLE, STYLE_DOT);
   ObjectSet(fiboobjname, OBJPROP_FIRSTLEVEL+0, -1.764);
   ObjectSetFiboDescription(fiboobjname,0,"176.4e"+temp_str);
   ObjectSet(fiboobjname, OBJPROP_FIRSTLEVEL+1, -1.618);
   ObjectSetFiboDescription(fiboobjname,1,"161.8e"+temp_str);
   ObjectSet(fiboobjname, OBJPROP_FIRSTLEVEL+2, -1.382);
   ObjectSetFiboDescription(fiboobjname,2,"138.2e"+temp_str);
   ObjectSet(fiboobjname, OBJPROP_FIRSTLEVEL+3, -1.236);
   ObjectSetFiboDescription(fiboobjname,3,"123.6e"+temp_str);
   ObjectSet(fiboobjname, OBJPROP_FIRSTLEVEL+4, -1);
   ObjectSetFiboDescription(fiboobjname,4,"100.0e"+temp_str);
   ObjectSet(fiboobjname, OBJPROP_FIRSTLEVEL+5, -0.764);
   ObjectSetFiboDescription(fiboobjname,5,"76.4e"+temp_str);
   ObjectSet(fiboobjname, OBJPROP_FIRSTLEVEL+6, -0.618);
   ObjectSetFiboDescription(fiboobjname,6,"61.8e"+temp_str);
   ObjectSet(fiboobjname, OBJPROP_FIRSTLEVEL+7, -0.5);
   ObjectSetFiboDescription(fiboobjname,7,"50.0e"+temp_str);
   ObjectSet(fiboobjname, OBJPROP_FIRSTLEVEL+8, -0.382);
   ObjectSetFiboDescription(fiboobjname,8,"38.2e"+temp_str);
   ObjectSet(fiboobjname, OBJPROP_FIRSTLEVEL+9, -0.236);
   ObjectSetFiboDescription(fiboobjname,9,"23.6e"+temp_str);
   ObjectSet(fiboobjname, OBJPROP_FIRSTLEVEL+10, 0.0);
   ObjectSetFiboDescription(fiboobjname,10,"0.0"+temp_str);
   ObjectSet(fiboobjname, OBJPROP_FIRSTLEVEL+11, 0.236);
   ObjectSetFiboDescription(fiboobjname,11,"23.6"+temp_str);
   ObjectSet(fiboobjname, OBJPROP_FIRSTLEVEL+12, 0.382);
   ObjectSetFiboDescription(fiboobjname,12,"38.2"+temp_str);
   ObjectSet(fiboobjname, OBJPROP_FIRSTLEVEL+13, 0.50);
   ObjectSetFiboDescription(fiboobjname,13,"50.0"+temp_str);
   ObjectSet(fiboobjname, OBJPROP_FIRSTLEVEL+14, 0.618);
   ObjectSetFiboDescription(fiboobjname,14,"61.8"+temp_str);
   ObjectSet(fiboobjname, OBJPROP_FIRSTLEVEL+15, 0.764);
   ObjectSetFiboDescription(fiboobjname,15,"76.4"+temp_str);
   ObjectSet(fiboobjname, OBJPROP_FIRSTLEVEL+16, 1.000);
   ObjectSetFiboDescription(fiboobjname,16,"100.0"+temp_str);
   ObjectSet(fiboobjname, OBJPROP_FIRSTLEVEL+17, 1.236);
   ObjectSetFiboDescription(fiboobjname,17,"123.6"+temp_str);
   ObjectSet(fiboobjname, OBJPROP_FIRSTLEVEL+18, 1.382);
   ObjectSetFiboDescription(fiboobjname,18,"138.2"+temp_str);
   ObjectSet(fiboobjname, OBJPROP_FIRSTLEVEL+19, 1.618);
   ObjectSetFiboDescription(fiboobjname,19,"161.8"+temp_str);
   ObjectSet(fiboobjname, OBJPROP_FIRSTLEVEL+20, 1.764);
   ObjectSetFiboDescription(fiboobjname,20,"176.4"+temp_str);
      ObjectsRedraw();
   
   return;
}//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   //int    counted_bars=IndicatorCounted();
//----
   drawdailyfibo();

   startup=false;
//----
   return(0);
  }
//+------------------------------------------------------------------+