//+------------------------------------------------------------------+
//|                       double dynamic zone williams percent range |
//|                                                           mladen |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      "mladenfx@gmail.com"

#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1  DeepSkyBlue
#property indicator_color2  LimeGreen
#property indicator_color3  Red
#property indicator_color4  LimeGreen
#property indicator_color5  Red
#property indicator_color6  Gold
#property indicator_width1  2
#property indicator_style2  STYLE_DOT
#property indicator_style3  STYLE_DOT
#property indicator_minimum -100
#property indicator_maximum 0

//
//
//
//
//

#import "dynamicZone.dll"
   double dzBuy(double& sourceArray[],double initValue, int lookBack, int bars, int i );
   double dzSell(double& sourceArray[],double initValue, int lookBack, int bars, int i );
#import

//
//
//
//
//

extern int    WprLength               = 14;
extern int    WprSmooth               =  3;
extern int    WprSmoothMode           = MODE_SMA;
extern int    DzLookBackBars          = 70;
extern double DzStartBuyProbability1  = 0.20;
extern double DzStartSellProbability1 = 0.20;
extern double DzStartBuyProbability2  = 0.06;
extern double DzStartSellProbability2 = 0.06;

//
//
//
//
//

double wps[];
double wpr[];
double bli1[];
double sli1[];
double bli2[];
double sli2[];
double slic[];

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int init()
{
   IndicatorBuffers(7);
   SetIndexBuffer(0,wps);
   SetIndexBuffer(1,bli1);
   SetIndexBuffer(2,sli1);
   SetIndexBuffer(3,bli2);
   SetIndexBuffer(4,sli2);
   SetIndexBuffer(5,slic);
   SetIndexBuffer(6,wpr);

   //
   //
   //
   //
   //
   
   WprLength = MathMax(WprLength ,1);
   IndicatorShortName ("Dynamic zone WPR ("+WprLength+","+WprSmooth+","+DzLookBackBars+","+DoubleToStr(DzStartBuyProbability1,3)+","+DoubleToStr(DzStartSellProbability1,3)+","+DoubleToStr(DzStartBuyProbability2,3)+","+DoubleToStr(DzStartSellProbability2,3)+")");
   return(0);
}
int deinit()
{
   return(0);
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int start()
{
   int counted_bars=IndicatorCounted();
   int i,limit;

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
         limit = MathMin(Bars-counted_bars,Bars-1);

   //
   //
   //
   //
   //
   //

   for(i=limit; i >= 0; i--) wpr[i] = iWPR(NULL,0,WprLength,i);
   for(i=limit; i >= 0; i--)
   {
      wps[i] = iMAOnArray(wpr,0,WprSmooth,0,WprSmoothMode,i);
      bli1[i] = dzBuy (wps, DzStartBuyProbability1,  DzLookBackBars, Bars, i);
      sli1[i] = dzSell(wps, DzStartSellProbability1, DzLookBackBars, Bars, i);
      bli2[i] = dzBuy (wps, DzStartBuyProbability2,  DzLookBackBars, Bars, i);
      sli2[i] = dzSell(wps, DzStartSellProbability2, DzLookBackBars, Bars, i);
      slic[i] = dzSell(wps, 0.5                    , DzLookBackBars, Bars, i);
   }
   return(0);
}

