//------------------------------------------------------------------
#property  copyright "mladen"
#property  link      "www.forex-station.com"
//------------------------------------------------------------------
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_minimum 0
#property indicator_maximum 1
#property indicator_color1  Green
#property indicator_color2  Red
#property indicator_color3  Gold
#property indicator_width1  2
#property indicator_width2  2
#property indicator_width3  2

//
//
//
//
//

extern int    OsmaFast         = 12;
extern int    OsmaSlow         = 26;
extern int    OsmaPrice        = PRICE_CLOSE;
extern int    OsmaMode         = MODE_LWMA;
extern int    OsmaSignalPeriod = 9;
extern int    OsmaSignalMode   = MODE_LWMA;
extern int    RsiPeriod        = 14;
extern double upperLevel       = 60;
extern double lowerLevel       = 40;

double value[];
double valueda[];
double valuedb[];
double valuedc[];
double macd[];
double slope[];
double osma[];
double sign[];

//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
//
//
//
//
//

int init()
{
   IndicatorBuffers(8);
   SetIndexBuffer(0,valueda); SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(1,valuedb); SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(2,valuedc); SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexBuffer(3,value);
   SetIndexBuffer(4,macd);
   SetIndexBuffer(5,sign);
   SetIndexBuffer(6,osma);
   SetIndexBuffer(7,slope);
return(0);
}
int deinit() { return(0); }

//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
//
//
//
//
//

int start()
{
   int i,counted_bars=IndicatorCounted();
      if(counted_bars<0) return(-1);
      if(counted_bars>0) counted_bars--;
         int limit = MathMin(Bars-counted_bars,Bars-1);

   //
   //
   //
   //
   //
   
   for(i=limit; i>=0; i--) macd[i] = iMA(NULL,0,OsmaFast,0,OsmaMode,OsmaPrice,i)-iMA(NULL,0,OsmaSlow,0,OsmaMode,OsmaPrice,i);
   for(i=limit; i>=0; i--) sign[i] = iMAOnArray(macd,0,OsmaSignalPeriod,0,OsmaSignalMode,i);
   for(i=limit; i>=0; i--) osma[i] = macd[i]-sign[i];
   for(i=limit; i>=0; i--)
   {
      value[i]   = iRSIOnArray(osma,0,RsiPeriod,i);
      valueda[i] = EMPTY_VALUE;
      valuedb[i] = EMPTY_VALUE;
      valuedc[i] = EMPTY_VALUE;
      slope[i]   = 0;      
         if (value[i]>upperLevel)                        slope[i] =  1;
         if (value[i]<lowerLevel)                        slope[i] = -1;
         if (value[i]<upperLevel && value[i]>upperLevel) slope[i] =  0;
         if (slope[i]== 1) valueda[i] = 1;
         if (slope[i]==-1) valuedb[i] = 1;
         if (slope[i]== 0) valuedc[i] = 1;
   }         
return(0);
}