//+------------------------------------------------------------------+
//|                                                     Astro.mq4 |
//|                      Copyright © 2009, Energiel |
//|                                                                   |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, Energiel"


#property indicator_separate_window
#property indicator_minimum -180
#property indicator_maximum 180
#property indicator_buffers 8
#property indicator_color1 Gray
#property indicator_color2 DarkOrchid
#property indicator_color3 Red
#property indicator_color4 DarkOrange
#property indicator_color5 Turquoise
#property indicator_color6 Blue
#property indicator_color7 Gold
#property indicator_color8 LimeGreen
//---- input parameters
extern int nbr_planet = 2;
extern bool      Mercure=true;
extern bool      Venus=true;
extern bool      Mars=false;
extern bool      Jupiter=false;
extern bool      Saturne=false;
extern bool      Uranus=false;
extern bool      Neptune=false;
extern bool      Pluton=false;
extern bool      Lune=false;

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
double ExtMapBuffer8[];
double time;
string venus_pos;
string nbr_line;
int handle;
string posneg;
double venneg;
int shift = 1;
int    draw_begin = 0;
double date1;
double old_venpos = 0;
double bar_shift = 50;
string planet_name;
string planet_file;
   string planet[8]; 

   
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
IndicatorShortName("Venus");

   SetIndexStyle(0,DRAW_LINE);
    SetIndexLabel(0,"Mercure");
    SetIndexShift(0,shift);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE);
    SetIndexLabel(1,"Venus");
     SetIndexShift(1,shift);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_LINE);
    SetIndexLabel(2,"Mars");
     SetIndexShift(2,shift);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle(3,DRAW_LINE);
    SetIndexLabel(3,"Jupiter");
     SetIndexShift(3,shift);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexStyle(4,DRAW_LINE);
    SetIndexLabel(4,"Saturne");
     SetIndexShift(4,shift);
   SetIndexBuffer(4,ExtMapBuffer5);
   SetIndexStyle(5,DRAW_LINE);
    SetIndexLabel(5,"Uranus");
     SetIndexShift(5,shift);
   SetIndexBuffer(5,ExtMapBuffer6);
   SetIndexStyle(6,DRAW_LINE);
   SetIndexLabel(6,"Neptune");
   SetIndexBuffer(6,ExtMapBuffer7);
   SetIndexStyle(7,DRAW_LINE);
   SetIndexLabel(7,"Pluton");
   SetIndexBuffer(7,ExtMapBuffer8);
   planet[0] = "Mercure";
   planet[1] = "Venus";
    planet[2] = "Mars";
     planet[3] = "Jupiter";
       planet[4] = "Saturne";
       planet[5] = "Uranus";
        planet[6] = "Neptune";
         planet[7] = "Pluton";
         planet[8] = "Lune";
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int m=0;
//----
  time = TimeCurrent();
 

int i =0; 
string date,nul;
double old_shift = 1000;
double venpos;
  
      
      // Set position of planets

    for(m=0;m<nbr_planet;m++)
     {
      planet_name = planet[m] + ".bin";
     shift = 1; 
           handle=FileOpen(planet_name, FILE_BIN |FILE_READ);
    if(handle<1)
      {
          Print("can't open file error-",GetLastError());
         return(0);
      }
      FileSeek(handle, 0, SEEK_SET);

    for(i=1;i<counted_bars;i++)
     {

           date = FileReadString(handle,10);
            date1=StrToTime(date);
            nul = FileReadString(handle,1);
           posneg = FileReadString(handle,1);
           if (posneg == "0")
           {
             venus_pos = FileReadString(handle,11);
            venpos = StrToDouble(venus_pos);
            }
              if (posneg == "-")
           {
         venus_pos = FileReadString(handle,12);
         venneg = StrToDouble(venus_pos);
         venpos = -(venneg);
            }
if (shift > 0)
{
      shift=iBarShift(0,0,date1);   
// if ((iTime(0,0,i))>=date1)


  if (m == 0 && Mercure==true)ExtMapBuffer1[shift] = venpos;      
 if (m==1 && Venus==true)ExtMapBuffer2[shift] = venpos;
   if (m==2 && Mars ==true)ExtMapBuffer3[shift] = venpos;            
  if (m==3 && Jupiter ==true)ExtMapBuffer4[shift] = venpos;
 if (m==4 && Saturne  ==true)ExtMapBuffer5[shift] = venpos;
  if (m==5 && Uranus ==true)ExtMapBuffer6[shift] = venpos;
   if (m==6 && Neptune ==true)ExtMapBuffer7[shift] = venpos;
    if (m==7 && Pluton ==true)ExtMapBuffer8[shift] = venpos;
    if (m==8 && Lune ==true)ExtMapBuffer8[shift] = venpos; 
}
else
{
i = counted_bars;
}
   }
      FileClose(handle);    
      
 }  
      
      

    Comment((iTime(0,0,i)),"   ",date1,"   ",planet_name);
   
   
//----
   return(0);
  }

//+------------------------------------------------------------------+