#property copyright "*"
#property link      "*"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots   2
//--- plot buy
#property indicator_label1  "buy"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot sell
#property indicator_label2  "sell"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrLime
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1



input double UpST = 90;
input double DnST = 10;
input double UpWPR = -0.8;
input double DnWPR = -99.2;

input  int PerWPR = 10;

input int SignalLineSt = 5;
input int ShiftLineSt = 5;
extern color    BuyColor=clrGreen;
extern color    SellColor=clrRed;
extern int      BuySellWidth=2;
//--- indicator buffers
double         buy[];
double         sell[];
double         ST[];
double         WPR[];

int st,wpr;
bool ind = false;
datetime counted_bar = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+



int OnInit(){

  

   st = iStochastic(_Symbol,0,SignalLineSt,3,ShiftLineSt,MODE_SMA,STO_LOWHIGH,PRICE_CLOSE,0);
   wpr = iWPR(_Symbol,0,PerWPR,0);

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

//--- indicator buffers mapping
   SetIndexBuffer(0,buy);
   SetIndexBuffer(1,sell);

   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,233);
   SetIndexShift(0,10);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,234);
   SetIndexShift(1,-10);

   SetIndexLabel(0,"Buy");
   SetIndexLabel(1,"Sell");

   

   SetIndexBuffer(2,ST,INDICATOR_CALCULATIONS);
   SetIndexBuffer(3,WPR,INDICATOR_CALCULATIONS);

   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int start;
 

   
   
   if(prev_calculated==0){
      start=3;
   }
   else{
      start=prev_calculated-1;
   }
   
    if(
     CopyBuffer(st,0,0,rates_total-start,ST)==-1 ||
     CopyBuffer(wpr,0,0,rates_total-start,WPR)==-1
      
   ){
      return(0);
   }   






   for(int i=start;i<rates_total-1;i++){
   
     
      
      
   buy[i]=EMPTY_VALUE; 
   sell[i]=EMPTY_VALUE;
      
      
           if((ST[i]<=DnST && ST[i-1]>DnST && WPR[i]<=DnWPR && WPR[i-1]>DnWPR) || (ST[i]<=DnST && ST[i-1]<=DnST && WPR[i]<=DnWPR && WPR[i-1]<=DnWPR))
         
            buy[i]=low[i]; 
            sell[i]=EMPTY_VALUE;  
         
         
        if((ST[i]>=UpST && ST[i-1]<UpST && WPR[i]>=UpWPR && WPR[i-1]<UpWPR) || (ST[i]>=UpST && ST[i-1]>=UpST && WPR[i]>=UpWPR && WPR[i-1]>=UpWPR) )
        
            sell[i]=high[i];  
            buy[i]=EMPTY_VALUE;   
   
  
   
     
   
   }
   
     

   return(rates_total);
  }
//+------------------------------------------------------------------+
 