#property copyright "Levix95"

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 LightSeaGreen
#property indicator_color2 clrGray
#property indicator_color3 clrLime
#property indicator_color4 clrRed
#property indicator_style1 0
#property indicator_style2 2
#property indicator_style3 2
#property indicator_style4 2
#property indicator_width1 1
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2

input int MAPeriod = 200;//MA Period
input ENUM_MA_METHOD MAType = MODE_EMA; //MA Mode

//---- buffers
double OBVBuffer[];
double MABuffer[];
double MABuffer1[];
double MABuffer2[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {

    SetIndexStyle(0, DRAW_LINE);
    SetIndexBuffer(0, OBVBuffer);

    SetIndexStyle(1, DRAW_LINE);
    SetIndexBuffer(1, MABuffer);
    
    SetIndexStyle(2, DRAW_LINE);
    SetIndexBuffer(2, MABuffer1);
    
     SetIndexStyle(3, DRAW_LINE);
    SetIndexBuffer(3, MABuffer2);
    
    IndicatorShortName("OBV");
    SetIndexLabel(0, " OBV ");
    SetIndexLabel(1, " OBV-MA ");    
//---
    return(0);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
  for(int i = 0 ; i < Bars ; i++ ){ 
      OBVBuffer[i]= iOBV(NULL, 0, PRICE_CLOSE, i);
  }
  for( i = 0 ; i < Bars ; i++ ){ 
      MABuffer[i]= iMAOnArray(OBVBuffer, 0 , MAPeriod , 0, MAType , i) ;
  }
  for( i = 0 ; i < Bars ; i++ ){ 
  if(MABuffer[i]>MABuffer[i+1]){MABuffer1[i]=MABuffer[i]; MABuffer2[i]=EMPTY_VALUE;}
  else if(MABuffer[i]<MABuffer[i+1]){MABuffer2[i]=MABuffer[i]; MABuffer1[i]=EMPTY_VALUE;}
  }
  return(0); 
 }