

#property copyright "Copyright 2013, gioooooo"
#property link      "gioooooo@hotmail.it"
//+------------------------------------------------------------------+
//| Extern Variables                                                 |
//+------------------------------------------------------------------+


#property indicator_chart_window
#property indicator_buffers 9
#property indicator_plots 9
#property indicator_color1  Pink
#property indicator_color2  Blue
#property indicator_color3  Aqua
#property indicator_color4  Red
#property indicator_color5  Red
#property indicator_color6  Red
#property indicator_color7  Red
#property indicator_style1  DRAW_LINE
#property indicator_style2  DRAW_LINE
#property indicator_style3  DRAW_LINE
#property indicator_style4  DRAW_LINE
#property indicator_style5  DRAW_LINE
#property indicator_style6  DRAW_LINE
#property indicator_style7  DRAW_LINE


input int numeroBarre= 100;
input double Level1 = 1;
input double Level2 = 1.50;
input double Level3 = 2;
input double Level4 = 2.5;
input double Level5 = 3;
input double Level6 = 3.50;
input double Level7 = 4;
input double Level8 = 4.5;



double  pips2dbl;

 
//+------------------------------------------------------------------+
//| Global Variables                                                 |
//+------------------------------------------------------------------+
  
double buff1[];
double buff2[];
double buff3[];
double buff4[];
double buff5[];
double buff6[]; 
double buff7[];                                                              

double buff8[]; 
double buff9[]; 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   SetIndexBuffer(0,buff1);
   PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_LINE);
   SetIndexBuffer(1,buff2);
   PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_LINE);
   SetIndexBuffer(2,buff3);
   PlotIndexSetInteger(2,PLOT_DRAW_TYPE,DRAW_LINE);
   SetIndexBuffer(3,buff4);
   PlotIndexSetInteger(3,PLOT_DRAW_TYPE,DRAW_LINE);
   SetIndexBuffer(4,buff5);
   PlotIndexSetInteger(4,PLOT_DRAW_TYPE,DRAW_LINE);
   SetIndexBuffer(5,buff6);
   PlotIndexSetInteger(5,PLOT_DRAW_TYPE,DRAW_LINE);
   SetIndexBuffer(6,buff7);
   PlotIndexSetInteger(6,PLOT_DRAW_TYPE,DRAW_LINE);
   
   SetIndexBuffer(7,buff8);
   PlotIndexSetInteger(7,PLOT_DRAW_TYPE,DRAW_LINE);
   SetIndexBuffer(8,buff9);
   PlotIndexSetInteger(8,PLOT_DRAW_TYPE,DRAW_LINE);
   
      
   ArraySetAsSeries(buff1,false);
   ArraySetAsSeries(buff2,false);
   ArraySetAsSeries(buff3,false);
   ArraySetAsSeries(buff4,false);
   ArraySetAsSeries(buff5,false);
   ArraySetAsSeries(buff6,false);
   ArraySetAsSeries(buff7,false);

   ArraySetAsSeries(buff8,false);
   ArraySetAsSeries(buff9,false);
   
   ArrayInitialize(buff1,EMPTY_VALUE);
   ArrayInitialize(buff2,EMPTY_VALUE);
   ArrayInitialize(buff3,EMPTY_VALUE);
   ArrayInitialize(buff4,EMPTY_VALUE);
   ArrayInitialize(buff5,EMPTY_VALUE);
   ArrayInitialize(buff6,EMPTY_VALUE);
   ArrayInitialize(buff7,EMPTY_VALUE);
   
   ArrayInitialize(buff8,EMPTY_VALUE);
   ArrayInitialize(buff9,EMPTY_VALUE);
   

int     pips2points;    
//double  pips2dbl;       
int     Digits_pips;    

     if (Digits() % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262
                pips2dbl    = Point()*10; pips2points = 10;   Digits_pips = 1;
    } else {    pips2dbl    = Point();    pips2points =  1;   Digits_pips = 0; }
    
     
    Print("pips2dbl=",DoubleToString(pips2dbl,Digits())); 
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {


  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
 
 ArraySetAsSeries(high,false);
 ArraySetAsSeries(time,false);
  
for (int i=(int)MathMax(prev_calculated-1,0); i<rates_total; i++)
      { 
      
      int posizioneMassimo;   

               posizioneMassimo=i;
               
               int u=0;
               for(int k=i;k>i-numeroBarre+1 && k>0 ;k--) { //if(time[i]==StringToTime("2016.11.10 18:23"))Print("k=",k); u++; 
                                        
                                                 if (high[k]>high[posizioneMassimo] ){  posizioneMassimo=k;}
                                                 }
                                              
              
               double MaxPrice = high[posizioneMassimo];
               //Print("MaxPrice =",MaxPrice);
               double First = NormalizeDouble(high[posizioneMassimo] -(high[posizioneMassimo]*Level1)/100,Digits());
               //Print("First =",First);
               double Second = NormalizeDouble(high[posizioneMassimo] -(high[posizioneMassimo]*Level2)/100,Digits());
               //Print("Second =",Second);
               double Third = NormalizeDouble(high[posizioneMassimo] -(high[posizioneMassimo]*Level3)/100,Digits());
               //Print("Third =",Third);
               double Fourth = NormalizeDouble(high[posizioneMassimo] -(high[posizioneMassimo]*Level4)/100,Digits());
               //Print("Fourth =",Fourth);
               double Fifth = NormalizeDouble(high[posizioneMassimo] -(high[posizioneMassimo]*Level5)/100,Digits());
               //Print("Fifth =",Fifth);
               double sixth = NormalizeDouble(high[posizioneMassimo] -(high[posizioneMassimo]*Level6)/100,Digits());
               //Print("sixth =",sixth

               double Seventh = NormalizeDouble(high[posizioneMassimo] -(high[posizioneMassimo]*Level7)/100,Digits());
               //Print("Fifth =",Fifth);
               double Eighth = NormalizeDouble(high[posizioneMassimo] -(high[posizioneMassimo]*Level8)/100,Digits());
               //Print("sixth =",sixth

               
               buff1[i] = MaxPrice;
               buff2[i] = First;
               buff3[i] = Second;
               buff4[i] = Third;
               buff5[i] = Fourth;
               buff6[i] = Fifth;
               buff7[i] = sixth;
               
               buff8[i] = Seventh;
               buff9[i] = Eighth;                
             
               
//               } 

      }            
    
   return(rates_total);
  }
//+------------------------------------------------------------------+
/*
int iHighest(string symbol,ENUM_TIMEFRAMES tf,int count,int start,  const double& high[])
{
int  posizione=start;
for (int k=0;k<count;k++) 
{
   if(start> count) { 
               
              // Print("barra partenza=",start," k=",k," pos assoluta=", start-k," valore=",low[start-k]);
               if (high[posizione]< high[start-k]) { posizione=start-k; //Print("Si");
                                                 }
                  }

 }
 
 //Print("Restituisco:",posizione);
return(posizione);
} 
 
 */

