Navigation´╝ÜHome > Content >

Dynamic_zone_CFP.mq4

Time: 2013-11-05 | Download file:Dynamic_zone_CFP.mq4

//+------------------------------------------------------------------+
//|                                                 Dynamic zone CFP |
//|                                                                  |
//| original CFP by SemSemFX@rambler.ru                              |
//| http://onix-trade.net/forum/index.php?showtopic=107              |
//|                                                                  |
//| rewritten by mladen                                              |
//+------------------------------------------------------------------+
#property copyright "www.forex-tsd.com"
#property link      "www.forex-tsd.com"

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1  DeepSkyBlue
#property indicator_color2  LimeGreen
#property indicator_color3  Red
#property indicator_color4  DimGray
#property indicator_width1  2
#property indicator_style4  STYLE_DOT

//
//
//
//
//

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

//
//
//
//
//

extern string TimeFrame              = "Current time frame";
extern string Prefix                 = "";
extern string Suffix                 = "";
extern int    MaMethod               = MODE_SMMA;
extern int    FastMaPeriod           = 3;
extern int    SlowMaPeriod           = 5;
extern int    Price                  = 6;
extern bool   USD                    = true;
extern bool   EUR                    = true;
extern bool   GBP                    = true;
extern bool   CHF                    = true;
extern bool   JPY                    = true;
extern bool   AUD                    = true;
extern bool   CAD                    = true;
extern bool   NZD                    = true;
extern int    DzLookBackBars         = 70;
extern double DzStartBuyProbability  = 0.16;
extern double DzStartSellProbability = 0.16;

extern bool   Interpolate = true;


//
//
//
//
//

double OUT[];
double cen[];
double bli[];
double sli[];

//
//
//
//
//

string symbols[];
string indicatorFileName;
bool   returnBars;
bool   calculateValue;
int    timeFrame;

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

int init()
{
   SetIndexBuffer(0,OUT); SetIndexLabel(0, Symbol()); 
   SetIndexBuffer(1,bli);
   SetIndexBuffer(2,sli);
   SetIndexBuffer(3,cen);
   
   //
   //
   //
   //
   //

      
      indicatorFileName = WindowExpertName();
      returnBars        = (TimeFrame=="returnBars"); if (returnBars) return(0);

            if (EUR) addSymbol("EURUSD");
            if (GBP) addSymbol("GBPUSD");
            if (AUD) addSymbol("AUDUSD");
            if (NZD) addSymbol("NZDUSD");
            if (CAD) addSymbol("USDCAD");
            if (CHF) addSymbol("USDCHF");
            if (JPY) addSymbol("USDJPY");
      
      calculateValue = (TimeFrame=="calculateValue"); if (calculateValue) return(0);
      timeFrame      = stringToTimeFrame(TimeFrame);

   //
   //
   //
   //
   //         
      
   IndicatorShortName(timeFrameToString(timeFrame)+" CFP "+Symbol());      
   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);
         if (returnBars) { OUT[0] = limit; return(0); }

   //
   //
   //
   //
   //

   if (calculateValue || timeFrame==Period())
   {
      for (int k=0; k3)
               double precision = 0.001;
         else         precision = 0.1;            
         for(; i>=0; i--)
         {
            bli[i] = dzBuyP (OUT, DzStartBuyProbability,  DzLookBackBars, Bars, i, precision);
            sli[i] = dzSellP(OUT, DzStartSellProbability, DzLookBackBars, Bars, i, precision);
            cen[i] = dzSellP(OUT, 0.5,                    DzLookBackBars, Bars, i, precision);
         }
      return(0);
   }      

   //
   //
   //
   //
   //

   for (k=0; k=0; i--)
   {
      int y = iBarShift(NULL,timeFrame,Time[i]);
         OUT[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",Prefix,Suffix,MaMethod,FastMaPeriod,SlowMaPeriod,Price,USD,EUR,GBP,CHF,JPY,AUD,CAD,NZD,DzLookBackBars,DzStartBuyProbability,DzStartSellProbability,0,y);
         bli[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",Prefix,Suffix,MaMethod,FastMaPeriod,SlowMaPeriod,Price,USD,EUR,GBP,CHF,JPY,AUD,CAD,NZD,DzLookBackBars,DzStartBuyProbability,DzStartSellProbability,1,y);
         sli[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",Prefix,Suffix,MaMethod,FastMaPeriod,SlowMaPeriod,Price,USD,EUR,GBP,CHF,JPY,AUD,CAD,NZD,DzLookBackBars,DzStartBuyProbability,DzStartSellProbability,2,y);
         cen[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",Prefix,Suffix,MaMethod,FastMaPeriod,SlowMaPeriod,Price,USD,EUR,GBP,CHF,JPY,AUD,CAD,NZD,DzLookBackBars,DzStartBuyProbability,DzStartSellProbability,3,y);

         //
         //
         //
         //
         //
      
            if (y==iBarShift(NULL,timeFrame,Time[i-1]) || !Interpolate) continue;

         //
         //
         //
         //
         //

         datetime time = iTime(NULL,timeFrame,y);
            for(int n = 1; i+n < Bars && Time[i+n] >= time; n++) continue;	
            for(int j = 1; j < n; j++)
            {
               OUT[i+j] = OUT[i] + (OUT[i+n]-OUT[i])*j/n;
               bli[i+j] = bli[i] + (bli[i+n]-bli[i])*j/n;
               sli[i+j] = sli[i] + (sli[i+n]-sli[i])*j/n;
               cen[i+j] = cen[i] + (cen[i+n]-cen[i])*j/n;
            }               
   }

   //
   //
   //
   //
   //
      
   return(0);
}

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

void addSymbol(string symbol)
{
   ArrayResize(symbols,ArraySize(symbols)+1); symbols[ArraySize(symbols)-1] = Prefix+symbol+Suffix;
}

//
//
//
//
//

int getLimit(int limit, string symbol)
{
   if (symbol!=Symbol())
          limit = MathMin(Bars-1,MathMax(iCustom(symbol,0,indicatorFileName,"returnBars",0,0),limit));
   return(limit);
}
int getTfLimit(int limit, string symbol)
{
   return(MathMin(Bars-1,MathMax((iCustom(symbol,timeFrame,indicatorFileName,"returnBars",0,0)+1)*timeFrame/Period(),limit)));
}



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

bool getMaValues(bool doIt, string symbol, double& fast, double& slow,int i)
{
   if (doIt)
   {
      fast = ma(Prefix+symbol+Suffix,FastMaPeriod,MaMethod,Price,i);
      slow = ma(Prefix+symbol+Suffix,SlowMaPeriod,MaMethod,Price,i);
            return(fast!=0 && slow!=0);
   }
   return(true);
}

//
//
//
//
//
  
double ma(string sym, int per, int Mode, int Price, int i)
  {
   double res = 0; int k = 1;
   switch(Period())
   {
       case 1:     res += iMA(sym, 0, per*k, 0, Mode, Price,i); k += 5;
       case 5:     res += iMA(sym, 0, per*k, 0, Mode, Price,i); k += 3;
       case 15:    res += iMA(sym, 0, per*k, 0, Mode, Price,i); k += 2;
       case 30:    res += iMA(sym, 0, per*k, 0, Mode, Price,i); k += 2;
       case 60:    res += iMA(sym, 0, per*k, 0, Mode, Price,i); k += 4;
       case 240:   res += iMA(sym, 0, per*k, 0, Mode, Price,i); k += 6;
       case 1440:  res += iMA(sym, 0, per*k, 0, Mode, Price,i); k += 4;
       case 10080: res += iMA(sym, 0, per*k, 0, Mode, Price,i); k += 4;
       case 43200: res += iMA(sym, 0, per*k, 0, Mode, Price,i);
   }
   return(res);
}


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

string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
int    iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};

//
//
//
//
//

int stringToTimeFrame(string tfs)
{
   tfs = stringUpperCase(tfs);
   for (int i=ArraySize(iTfTable)-1; i>=0; i--)
         if (tfs==sTfTable[i] || tfs==""+iTfTable[i]) return(MathMax(iTfTable[i],Period()));
                                                      return(Period());
}
string timeFrameToString(int tf)
{
   for (int i=ArraySize(iTfTable)-1; i>=0; i--) 
         if (tf==iTfTable[i]) return(sTfTable[i]);
                              return("");
}

//
//
//
//
//

string stringUpperCase(string str)
{
   string   s = str;

   for (int length=StringLen(str)-1; length>=0; length--)
   {
      int char = StringGetChar(s, length);
         if((char > 96 && char < 123) || (char > 223 && char < 256))
                     s = StringSetChar(s, length, char - 32);
         else if(char > -33 && char < 0)
                     s = StringSetChar(s, length, char + 224);
   }
   return(s);
}

Recommend