//+------------------------------------------------------------------+
//|                                                        Oscar.mq4 |
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_level1 75
#property indicator_level2 25
#property indicator_levelcolor DarkSlateGray

#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red

//---- input parameters
extern  int iLookBack = 8;
extern int OscarAve = 5;
extern int highstop= 3;
extern int lowstop = 2;


/* unused code
double  spr, pnt, tickval;
int     dig;
string  IndiName, ccy;
*/

string  IndiName;

//---- buffers
double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()   {
   IndicatorBuffers(2);
//---- indicators



 //----
//   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2, indicator_color1);
   SetIndexBuffer(0, Buffer1);
//   SetIndexStyle(1, DRAW_LINE, STYLE_DOT, 0, indicator_color2);
   SetIndexBuffer(1, Buffer2);
  
/* useless code  
  int checksum = 0;
  string str = "1";
  for (int i=0; i<StringLen(str); i++)  
    checksum += i * StringGetChar(str,i);
  IndiName = "Oscar-" + checksum;
*/

  IndiName = "Oscar(" + iLookBack + ")";
  IndicatorShortName(IndiName);
  SetIndexLabel(1,"MA("+OscarAve+")");

/* useless code
  ccy     = Symbol();
  pnt     = MarketInfo(ccy,MODE_POINT);
  dig     = MarketInfo(ccy,MODE_DIGITS);
  spr     = MarketInfo(ccy,MODE_SPREAD);
  tickval = MarketInfo(ccy,MODE_TICKVALUE);
  if (dig == 3 || dig == 5) {
    pnt     *= 10;
    spr     /= 10;
    tickval *= 10;
  }
*/

  return(0);
}

//+------------------------------------------------------------------+
int deinit()  {
//+------------------------------------------------------------------+
  return(0);
}

//+------------------------------------------------------------------+
int start()  {
  double Y = 0;
  for (int i=Bars-(iLookBack+2); i>=0; i--)  {
    double X = Y;
    double A = 0;
    double B = 999999;
    for(int j=i; j<i+iLookBack; j++)   {
      A = MathMax(High[j],A);
      B = MathMin(Low[j],B);
    }
    double C = Close[i];  
    double rough  = (C-B)/(A-B)*100;
    Y = X/3*2 + rough/3;
    Buffer1[i] = Y;
    Buffer3[i] = (A + highstop/10000); 
    Buffer4[i] = (B- lowstop/10000);    
  }
  	i = Bars - (iLookBack+2);
	while(i>=0)
	{
		Buffer2[i]=iMAOnArray(Buffer1,0,OscarAve,0,MODE_LWMA,i);
		i--;	
	}
  return(0);
}


