//+------------------------------------------------------------------+
//|                                                          xxx.mq4 |
//|                                                              xxx |
//|                                                    xxx@gmail.com |
//+------------------------------------------------------------------+
#property copyright "xxx"

#property indicator_chart_window
#property  indicator_buffers 8
extern color   FiboColour=Yellow;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
double         SwingHigh, SwingLow;
double         BreakoutBuyLevel, BreakoutSellLevel;
double         BuyZone1Low, BuyZone1High, BuyZone2Low, BuyZone2High, SellZone1Low, SellZone1High, SellZone2High, SellZone2Low;
double         AlertZone;
double         BreakoutBuyTP, BreakoutSellTP;

int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectDelete("Fibo");
  
   Comment(" ");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+



 void GetSwing()
{

   SwingHigh = iHigh(NULL, PERIOD_D1, 1);
   SwingLow = iLow(NULL, PERIOD_D1, 1);
   

    
   CalculateTradeLevels();
   
   
   
}//void GetSwing()
  
void CalculateTradeLevels()
{
   
   double extent = SwingHigh - SwingLow;

   BreakoutBuyLevel = SwingHigh;
   BreakoutSellLevel = SwingLow;
   
   BuyZone1Low = NormalizeDouble(SwingLow + (extent * 13 / 100), Digits); 
   BuyZone1High = NormalizeDouble(SwingLow + (extent * 25 / 100), Digits);
   
   BuyZone2High = NormalizeDouble(SwingLow + (extent * -13 / 100), Digits);
   BuyZone2Low = NormalizeDouble(SwingLow + (extent * -25 / 100), Digits);
   
   SellZone1High = NormalizeDouble(SwingLow + (extent * 87 / 100), Digits); 
   SellZone1Low = NormalizeDouble(SwingLow + (extent * 75 / 100), Digits);
   
   SellZone2High = NormalizeDouble(SwingLow + (extent * 125 / 100), Digits);
   SellZone2Low = NormalizeDouble(SwingLow + (extent * 113 / 100), Digits);
   
   AlertZone = NormalizeDouble(SwingLow + (extent * 50 / 100), Digits);
       
   BreakoutBuyTP = NormalizeDouble(SwingLow + (extent * 161.8 / 100), Digits);
   BreakoutSellTP = NormalizeDouble(SwingLow + (extent * -61.8 / 100), Digits); 
   
}//End void CalculateTradeLevels()   

 
   
void DrawFib()
{

      
      double HighPrice, LowPrice;
      datetime OpenTime, CloseTime;
      
      
      HighPrice = SwingHigh;
      OpenTime = iTime(NULL, PERIOD_D1, 1);
      LowPrice = SwingLow;
      CloseTime = iTime(NULL, PERIOD_D1, 1);
         
      
            
      
            
      ObjectCreate("Fibo",OBJ_FIBO,0,OpenTime,HighPrice,CloseTime,LowPrice);
      ObjectSet("Fibo", OBJPROP_STYLE, STYLE_DASH);
      ObjectSet("Fibo", OBJPROP_COLOR, FiboColour);
      ObjectSet("Fibo", OBJPROP_LEVELCOLOR, FiboColour);
      ObjectSet("Fibo", OBJPROP_WIDTH, 1);
      ObjectSet("Fibo", OBJPROP_FIBOLEVELS, 13);
      ObjectSet("Fibo", OBJPROP_FIRSTLEVEL+0, 0);
      ObjectSet("Fibo", OBJPROP_FIRSTLEVEL+1, 100);
      
      ObjectSet("Fibo", OBJPROP_FIRSTLEVEL+0, 0);//Swing Low
      ObjectSet("Fibo", OBJPROP_FIRSTLEVEL+1, 0.13);//BuyZone1
      ObjectSet("Fibo", OBJPROP_FIRSTLEVEL+2, 0.25);//BuyZone1
      ObjectSet("Fibo", OBJPROP_FIRSTLEVEL+3, 0.50);//Alert
      ObjectSet("Fibo", OBJPROP_FIRSTLEVEL+4, 0.75);//SellZone1
      ObjectSet("Fibo", OBJPROP_FIRSTLEVEL+5, 0.87);//SellZone1
      ObjectSet("Fibo", OBJPROP_FIRSTLEVEL+6, 1);//Swing Hi
      ObjectSet("Fibo", OBJPROP_FIRSTLEVEL+7, 1.13);//SellZone2
      ObjectSet("Fibo", OBJPROP_FIRSTLEVEL+8, 1.25);//SellZone2
      ObjectSet("Fibo", OBJPROP_FIRSTLEVEL+9, 1.618);//TPBuy1
      ObjectSet("Fibo", OBJPROP_FIRSTLEVEL+10, -0.13);//BuyZone2
      ObjectSet("Fibo", OBJPROP_FIRSTLEVEL+11, -0.25);//BuyZone2
      ObjectSet("Fibo", OBJPROP_FIRSTLEVEL+12, -0.618);//TPSell1
     
      
      ObjectSetFiboDescription("Fibo", 0, " SNR H/L "+ "  %$");
      ObjectSetFiboDescription("Fibo", 1, " BuyZone1 Low "+ "  %$");
      ObjectSetFiboDescription("Fibo", 2, " BuyZone1 High"+ "  %$");
      ObjectSetFiboDescription("Fibo", 3, " Alert"+ "  %$");
      ObjectSetFiboDescription("Fibo", 4, " SellZone1 Low"+ "  %$");
      ObjectSetFiboDescription("Fibo", 5, " SellZone1 High"+ "  %$");
      ObjectSetFiboDescription("Fibo", 6, " SNR H/L"+ "  %$");
      ObjectSetFiboDescription("Fibo", 7, " SellZone2 Low"+ "  %$");
      ObjectSetFiboDescription("Fibo", 8, " SellZone2 High"+ "  %$");
      ObjectSetFiboDescription("Fibo", 9, " Breakout TP1"+ "  %$");
      ObjectSetFiboDescription("Fibo", 10, " BuyZone2 High"+ "  %$");
      ObjectSetFiboDescription("Fibo", 11, " BuyZone2 Low"+ "  %$");
      ObjectSetFiboDescription("Fibo", 12, " Breakout TP1"+ "  %$");
      
            
      
}//End void DrawFib()
int start()
  { GetSwing();
  CalculateTradeLevels();
  DrawFib();
  }