//+------------------------------------------------------------------+
//|                                          dynamic zone price zone |
//|                                                           mladen |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      "mladenfx@gmail.com"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1  LimeGreen
#property indicator_color2  Red
#property indicator_width1  2
#property indicator_width2  2

//
//
//
//
//

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

//
//
//
//
//

extern int    DzPrice                = PRICE_CLOSE;
extern int    DzSmooth               = 1;
extern int    DzSmoothMode           = MODE_SMA;
extern int    DzLookBackBars         = 35;
extern double DzStartBuyProbability  = 0.02;
extern double DzStartSellProbability = 0.02;

//
//
//
//
//

double bli[];
double sli[];
double prc[];

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

int init()
{
   IndicatorBuffers(3);
   SetIndexBuffer(0,bli);
   SetIndexBuffer(1,sli);
   SetIndexBuffer(2,prc);
   
   //
   //
   //
   //
   //
   
   string PriceType;
      switch(DzPrice)
      {
         case PRICE_CLOSE:    PriceType = "Close";    break;  // 0
         case PRICE_OPEN:     PriceType = "Open";     break;  // 1
         case PRICE_HIGH:     PriceType = "High";     break;  // 2
         case PRICE_LOW:      PriceType = "Low";      break;  // 3
         case PRICE_MEDIAN:   PriceType = "Median";   break;  // 4
         case PRICE_TYPICAL:  PriceType = "Typical";  break;  // 5
         case PRICE_WEIGHTED: PriceType = "Weighted"; break;  // 6
      }      

   //
   //
   //
   //
   //
   
   IndicatorShortName ("Dynamic zone price zone ("+DzSmooth+","+PriceType+","+DzLookBackBars+","+DoubleToStr(DzStartBuyProbability,3)+","+DoubleToStr(DzStartSellProbability,3)+")");
   return(0);
}
int deinit()
{
   return(0);
}

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

int start()
{
   double normalizer;
   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);
         if (Digits == 4 || Digits == 5)
               normalizer = 100;
         else  normalizer = 1;                
         

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

   for(i=limit; i >= 0; i--) 
   for(i=limit; i >= 0; i--)
   {
      prc[i] = iMA(NULL,0,DzSmooth,0,DzSmoothMode,DzPrice,i)*normalizer;
      bli[i] = dzBuy (prc, DzStartBuyProbability,  DzLookBackBars, Bars, i)/normalizer;
      sli[i] = dzSell(prc, DzStartSellProbability, DzLookBackBars, Bars, i)/normalizer;
   }
   return(0);
}