//+------------------------------------------------------------------+
//|                                           !WA PowerBS Ribbon.mq4 |
//|                                      Copyright © 2010, wongangon |
//|                                              wongangon@gmail.com |
//+------------------------------------------------------------------+



#property copyright "Copyright © 2010, wongangon"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 8

extern bool ShowRibbon=1;
extern bool ShowBands=1;
int Price_Type=0;
int Periode;

//---- buffers
double LSMAD1[];
double HiBand[];
double LoBand[];
double BSBand[];
double Seller[];
double Buyer[];
double GantiLSMA[];
double GantiBSB[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   if (ShowRibbon)
      {
      SetIndexStyle(0,DRAW_HISTOGRAM,2,0,Indigo);
      SetIndexBuffer(0,GantiLSMA);
      SetIndexLabel(0,"LSMA_rib");
      SetIndexStyle(1,DRAW_HISTOGRAM,2,0,Brown);
      SetIndexBuffer(1,GantiBSB);
      SetIndexLabel(1,"BSB_rib");
      }
   if (ShowBands)
      {
      SetIndexStyle(2,DRAW_LINE,0,0,Navy);
      SetIndexBuffer(2,HiBand);
      SetIndexLabel(2,"Last High");
      SetIndexStyle(3,DRAW_LINE,0,0,Crimson);
      SetIndexBuffer(3,LoBand);
      SetIndexLabel(3,"Last Low");
      SetIndexStyle(4,DRAW_LINE,2,0,Blue);
      SetIndexBuffer(4,Buyer);
      SetIndexLabel(4,"Buyer Band");
      SetIndexStyle(5,DRAW_LINE,2,0,Red);
      SetIndexBuffer(5,Seller);
      SetIndexLabel(5,"Seller Band");
      }
   SetIndexStyle(6,DRAW_LINE,0,1,LimeGreen);
   SetIndexBuffer(6,BSBand);
   SetIndexLabel(6,"Average");
   SetIndexStyle(7,DRAW_LINE,0,1,LimeGreen);
   SetIndexBuffer(7,LSMAD1);
   SetIndexLabel(7,"LSMA D1");
   IndicatorShortName("MMR HighLow Lines"); 
   getPeriod();

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectDelete("LSMA_rib");
   ObjectDelete("BSB_rib");
   ObjectDelete("Last High");
   ObjectDelete("Last Low");
   ObjectDelete("Average");
   ObjectDelete("Buyer Band");
   ObjectDelete("Seller Band");
   ObjectDelete("LSMA D1");

   ObjectDelete("MMR HighLow Lines"); 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   double h,l;
   int counted_bars=IndicatorCounted();
   int limit=Bars-counted_bars;
   if(counted_bars>0) limit++;

   for(int i=0; i<limit; i++)
      {
      if (Period() < PERIOD_H1)  
         {
         double hh=High[iHighest(NULL,0,MODE_HIGH,Periode,i)];
         double ll=Low[iLowest(NULL,0,MODE_LOW,Periode,i)];
         double av=(hh+ll)/2;
         double bb=(av+hh)/2;
         double ss=(av+ll)/2;
         HiBand[i]=hh;
         LoBand[i]=ll; 
         BSBand[i]=av;
         Buyer[i]=bb;
         Seller[i]=ss;

         LSMAD1[i]=3*iMA(Symbol(),0,Periode,0,MODE_LWMA,Price_Type,i)-2*iMA(Symbol(),0,Periode,0,MODE_SMA,Price_Type,i);
   
         GantiLSMA[i]=LSMAD1[i];
         GantiBSB[i]=BSBand[i];
         }
      }

   return(0);
  }
//+------------------------------------------------------------------+

void getPeriod()
{
   switch(Period()) 
      {
         case 1: 
            Periode=1440;
            break;
         case 5: 
            Periode=288;
            break;
         case 15: 
            Periode=96;
            break;
         case 30: 
            Periode=48;
            break;
         case 60: 
            Periode=24;
            break;
         case 120: 
            Periode=12;
            break;
         case 240: 
            Periode=6;
            break;
         case 1440: 
            Periode=0;
            break;
         case 10080: 
            Periode=0;
            break;
         case 43200: 
            Periode=0;
            break;
         
      }
 }