// +------------------------------------------------------------------------------------------+ //
// |    .-._______                           XARD777                            _______.-.    | //
// |---( )_)______)                 Knowledge of the ancients                  (______(_( )---| //
// |  (    ()___)                              \�/                               (___()    )  | //
// |       ()__)                              (o o)                               (__()       | //
// |--(___()_)__________________________oOOo___(_)___oOOo___________________________(_()___)--| //
// |______|______|______|______|______|______|______|______|______|______|______|______|______| //
// |___|______|_Cam__|______|______|______|______|______|______|______|Ismael|______|______|__| //
// |______|______|______|______|______|______|__Big_Joe____|______|______|______|______|______| //
// |___|______|______|______|_Mundu|______|______|______|______|______|______|______|______|__| //
// |______|__cja_|______|______|______|__Hendrik____|______|______|______|______|______|______| //
// |___|______|______|______|______|______|______|______|Tzuman|______|______|______|______|__| //
// |______|______|______|Hercs_|______|______|______|______|______|______|Joy22_|______|______| //
// |___|______|______|______|______|______|___Poruchik__|______|______|______|______|______|__| //
// |______|___Pava_the_Clown___|______|______|______|______|__Leledc_____|______|______|_Xard_| //
// |                                                                                     2011 | //
// |                 File:     !XPS v8 OSCILLATOR.mq4                                         | //
// | Programming language:     MQL4                                                           | //
// | Development platform:     MetaTrader 4                                                   | //
// |          End product:     THIS SOFTWARE IS FOR FOREX TRADERS                             | //
// |                                                                                          | //
// |                                                                                          | //
// |     Online Resources:     http://search4metatrader.com/index.php                         | //
// |                           www.2bgoogle.com/forex4.html                                   | //
// |                           www.forex-tsd.com                                              | //
// |                           www.forexstrategiesresources.com                               | //
// |                           www.traderszone.com                                            | //
// |                           http://fxcoder.ru/indicators                                   | //
// |                           www.worldwide-invest.org/                                      | //
// |                           http://indo-investasi.com                                      | //
// |                                                                                          | //
// |                                                           [Xard777 Proprietory Software] | //
// +------------------------------------------------------------------------------------------+ //

#property  indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1
#property  indicator_buffers 3
#property indicator_color2 C'72,49,255'
#property indicator_color3 C'255,49,72'


#property indicator_width2 6
#property indicator_width3 6
 
int period;
extern bool alarm=false;


double         ExtBuffer0[];
double         ExtBuffer1[];
double         ExtBuffer2[];

double alertBar;
double last;

int init() {

   //-----------------------------
   
   switch ( Period() )
   {
   case     1: period = 2880;break;
   case     5: period = 576;break;
   case    15: period = 192;break;
   case    30: period = 96;break;
   case    60: period = 48;break;
   case   240: period = 48;break;
   case  1440: period = 48;break;
   case 10080: period = 48;break;
   default   : period = 48;break;
   }
   
   //-----------------------------
   
   SetIndexStyle(0,DRAW_NONE);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   IndicatorDigits(Digits+1);

   SetIndexBuffer(0,ExtBuffer0);
   SetIndexBuffer(1,ExtBuffer1);
   SetIndexBuffer(2,ExtBuffer2);

   IndicatorShortName("");// X :-)");
   SetIndexLabel(0, NULL);
   SetIndexLabel(1, NULL);
   SetIndexLabel(2, NULL);


   return(0);
  }


int deinit()
  {
//----
  ObjectDelete("XPS");
  ObjectDelete("XPS2");
  ObjectDelete("XPS3");
//----
   return(0);
  }


int start() {
   
   int    limit;
   int    counted_bars=IndicatorCounted();
   double prev,current,old;
   double Value=0,Value1=0,Value2=0,Fish=0,Fish1=0,Fish2=0;
   double price;
   double MinL=0;
   double MaxH=0;  
   

   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

   for(int i=0; i<limit; i++)
   
    { MaxH = High[Highest(NULL,0,MODE_HIGH,period,i)];
      MinL = Low[Lowest(NULL,0,MODE_LOW,period,i)];
      price = (High[i]+Low[i])/2;
      
      Value = 0.33*2*((price-MinL)/(MaxH-MinL)-0.5) + 0.67*Value1;     
      Value=MathMin(MathMax(Value,-0.999),0.999); 
      
      ExtBuffer0[i]=0.5*MathLog((1+Value)/(1-Value))+0.5*Fish1;
      
      Value1=Value;
      Fish1=ExtBuffer0[i];  
    }


   bool up = TRUE;
   for(i=limit-2; i>=0; i--)
     
     {
      current=ExtBuffer0[i];
      prev=ExtBuffer0[i+1];
           
      if (((current<0)&&(prev>0))||(current<0))   up= false;    
      if (((current>0)&&(prev<0))||(current>0))   up= true;
      
      if(!up) {
         ExtBuffer2[i]=1;
         ExtBuffer1[i]=0;
      
      if (alarm && i==0 && last != 2 && ExtBuffer1[i] == 0 && Bars>alertBar) 
        {
            Alert("OSC... Possible Trend going DOWN on ",Period()," ",Symbol());
            alertBar = Bars;last = 2;
        }      
        }
        
       else {
          ExtBuffer1[i]=1;
          ExtBuffer2[i]=0;
      
      if (alarm && i==0 && last != 1 && ExtBuffer2[i] == 0 && Bars>alertBar) 
        {
            Alert("OSC... Possible Trend going UP on ",Period()," ",Symbol());
            alertBar = Bars;
            last = 1;
        }   
        }
  }//End Loop


   ObjectDelete("XPS");
   ObjectCreate("XPS", OBJ_LABEL, 2, 0, 0);
   ObjectSetText("XPS","!XPS v8", 28, "Arial Black", C'46,46,46');
   ObjectSet("XPS", OBJPROP_CORNER, 2);
   ObjectSet("XPS", OBJPROP_BACK, 0);
   ObjectSet("XPS", OBJPROP_XDISTANCE, 6);
   ObjectSet("XPS", OBJPROP_YDISTANCE, 8);     
      
   ObjectDelete("XPS2");
   ObjectCreate("XPS2", OBJ_LABEL, 2, 0, 0);
   ObjectSetText("XPS2","!XPS v8", 28, "Arial Black", Silver);
   ObjectSet("XPS2", OBJPROP_CORNER, 2);
   ObjectSet("XPS2", OBJPROP_BACK, 0);
   ObjectSet("XPS2", OBJPROP_XDISTANCE, 4);
   ObjectSet("XPS2", OBJPROP_YDISTANCE, 10); 
   
   ObjectDelete("XPS3");
   ObjectCreate("XPS3", OBJ_LABEL, 2, 0, 0);
   ObjectSetText("XPS3","Trade like a BOSS", 9, "Arial Black", Silver);
   ObjectSet("XPS3", OBJPROP_CORNER, 2);
   ObjectSet("XPS3", OBJPROP_BACK, 0);
   ObjectSet("XPS3", OBJPROP_XDISTANCE, 7);
   ObjectSet("XPS3", OBJPROP_YDISTANCE, 3); 

   
   return(0);
   }
// ------------------------------------------------------------------------------------------ //
//                                     E N D   P R O G R A M                                  //
// ------------------------------------------------------------------------------------------ //
/*                                                         
                                        ud$$$**BILLION$bc.                          
                                    u@**"        PROJECT$$Nu                       
                                  J                ""#$$$$$$r                     
                                 @                       $$$$b                    
                               .F                        ^*3$$$                   
                              :% 4                         J$$$N                  
                              $  :F                       :$$$$$                  
                             4F  9                       J$$$$$$$                 
                             4$   k             4$$$$bed$$$$$$$$$                 
                             $$r  'F            $$$$$$$$$$$$$$$$$r                
                             $$$   b.           $$$$$$$$$$$$$$$$$N                
                             $$$$$k 3eeed$$b    XARD777."$$$$$$$$$                
              .@$**N.        $$$$$" $$$$$$F'L $$$$$$$$$$$  $$$$$$$                
              :$$L  'L       $$$$$ 4$$$$$$  * $$$$$$$$$$F  $$$$$$F         edNc   
             @$$$$N  ^k      $$$$$  3$$$$*%   $F4$$$$$$$   $$$$$"        d"  z$N  
             $$$$$$   ^k     '$$$"   #$$$F   .$  $$$$$c.u@$$$          J"  @$$$$r 
             $$$$$$$b   *u    ^$L            $$  $$$$$$$$$$$$u@       $$  d$$$$$$ 
              ^$$$$$$.    "NL   "N. z@*     $$$  $$$$$$$$$$$$$P      $P  d$$$$$$$ 
                 ^"*$$$$b   '*L   9$E      4$$$  d$$$$$$$$$$$"     d*   J$$$$$r   
                      ^$$$$u  '$.  $$$L     "#" d$$$$$$".@$$    .@$"  z$$$$*"     
                        ^$$$$. ^$N.3$$$       4u$$$$$$$ 4$$$  u$*" z$$$"          
                          '*$$$$$$$$ *$b      J$$$$$$$b u$$P $"  d$$P             
                             #$$$$$$ 4$ 3*$"$*$ $"$'c@@$$$$ .u@$$$P               
                               "$$$$  ""F~$ $uNr$$$^&J$$$$F $$$$#                 
                                 "$$    "$$$bd$.$W$$$$$$$$F $$"                   
                                   ?k         ?$$$$$$$$$$$F'*                     
                                    9$$bL     z$$$$$$$$$$$F                       
                                     $$$$    $$$$$$$$$$$$$                        
                                      '#$$c  '$$$$$$$$$"                          
                                       .@"#$$$$$$$$$$$$b                          
                                     z*      $$$$$$$$$$$$N.                       
                                   e"      z$$"  #$$$k  '*$$.                     
                                .u*      u@$P"      '#$$c   "$$c                   
                        u@$*"""       d$$"            "$$$u  ^*$$b.               
                      :$F           J$P"                ^$$$c   '"$$$$$$bL        
                     d$$  ..      @$#                      #$$b         '#$       
                     9$$$$$$b   4$$                          ^$$k         '$      
                      "$$6""$b u$$                             '$    d$$$$$P      
                        '$F $$$$$"                              ^b  ^$$$$b$       
                         '$W$$$$"                                'b@$$$$"         
                                                                  ^$$$*/