Bonjour,
J’ai trouvé le code MQL4 suivant, correspondant à l’indicateur Composite Fractal Behavior de Mark Jurik.
Est-il possible de le convertir en langage Probuilder (le code a l’air complexe) ?
Voici le code :
//+------------------------------------------------------------------+
//| cfb.mq4 |
//| mladen |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link "mladenfx@gmail.com"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_minimum 0
//
//
//
//
//
extern string _ = "Parameters";
extern int Depth = 3;
extern int Price = PRICE_WEIGHTED;
extern int BarsToCount = 1000;
extern int Smooth = 8;
extern int SmoothResultPeriod = 5;
extern double SmoothSpeed = 3.0;
extern bool SmoothAdaptive = true;
//
//
//
//
//
double buffer1[];
double storec[][5];
double stored[][35];
string IndicatorFileName;
bool CalculatingCFB=false;
int Depths[] = {2,3,4,6,8,12,16,24,32,48,64,96,128,192};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int init()
{
SetIndexBuffer(0,buffer1);
//
//
//
//
//
CalculatingCFB = (_=="CalculateCFB");
if (!CalculatingCFB)
{
Depth = MathMax(MathMin(Depth,7),1)+7;
SmoothResultPeriod = MathMax(SmoothResultPeriod,1);
SmoothSpeed = MathMax(SmoothSpeed,-1.5);
SetIndexDrawBegin(0,Depths[Depth-1]);
}
//
//
//
//
//
IndicatorFileName = WindowExpertName();
IndicatorShortName("cfb ("+(Depth-7)+")");
return(0);
}
int deinit() { return(0); }
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int start()
{
double avg;
int counted_bars=IndicatorCounted();
int i,k,r,limit;
if(counted_bars < 0) return(-1);
if(counted_bars > 0) counted_bars--;
limit = Bars-counted_bars;
if (BarsToCount>100)
limit = MathMin(limit,BarsToCount+192);
//
//
//
//
//
if (CalculatingCFB)
{
if (ArrayRange(storec,0) != Bars) ArrayResize(storec,Bars);
for(i=limit, r=Bars-i-1; i>=0; i--, r++) buffer1[i] = calculateCFB(i,r,Depth);
return(0);
}
if (ArrayRange(stored,0) != Bars) ArrayResize(stored,Bars);
//
//
//
//
//
if (BarsToCount>100) SetIndexDrawBegin(0,Bars-BarsToCount);
for(i=limit, r=Bars-i-1; i>=0; i--, r++)
{
double suma = 0;
double sumb = 0;
double cfb = 0;
double evenCoef = 1;
double oddCoef = 1;
//
//
//
//
//
for (k=Depth-1; k>=0; k--)
{
stored[r][k] = iCustom(NULL,0,IndicatorFileName,"CalculateCFB",Depths[k],Price,BarsToCount,0,i);
stored[r][k+14] = stored[r-1][k+14] + (stored[r][k]-stored[r-Smooth][k])/Smooth;
if ((k%2)==0)
{ avg = oddCoef * stored[r][k+14]; oddCoef = oddCoef * (1 - avg); }
else { avg = evenCoef * stored[r][k+14]; evenCoef = evenCoef * (1 - avg); }
suma += avg*avg*Depths[k];
sumb += avg;
}
//
//
//
//
//
if (sumb != 0) cfb = suma/sumb;
if (SmoothResultPeriod>1)
buffer1[i] = iAverage(cfb,SmoothResultPeriod,SmoothSpeed,SmoothAdaptive,r,28);
else buffer1[i] = cfb;
}
//
//
//
//
//
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
#define _prices 0
#define _roc 1
#define _value1 2
#define _value2 3
#define _value3 4
//
//
//
//
double calculateCFB(int i, int r, int depth)
{
storec[r][_prices] = iMA(NULL,0,1,0,MODE_SMA,Price,i);
//
//
//
//
//
storec[r][_roc] = MathAbs(storec[r][_prices] - storec[r-1][_prices]);
storec[r][_value1] = storec[r-1][_value1] - storec[r-depth][_roc] + storec[r][_roc];
storec[r][_value2] = storec[r-1][_value2] - storec[r-1][_value1] + storec[r][_roc]*depth;
storec[r][_value3] = storec[r-1][_value3] - storec[r-1-depth][_prices] + storec[r-1][_prices];
double dividend = MathAbs(depth*storec[r][_prices]-storec[r][_value3]);
//
//
//
//
//
if (storec[r][_value2] != 0)
return( dividend / storec[r][_value2]);
else return(0.00);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
#define E1 0
#define E2 1
#define E3 2
#define E4 3
#define E5 4
#define E6 5
#define res 6
//
//
//
//
//
double iAverage(double price, double averagePeriod, double const, bool adaptive, int r, int s)
{
double e1=stored[r-1][E1+s]; double e2=stored[r-1][E2+s];
double e3=stored[r-1][E3+s]; double e4=stored[r-1][E4+s];
double e5=stored[r-1][E5+s]; double e6=stored[r-1][E6+s];
//
//
//
//
//
if (adaptive && (averagePeriod > 1))
{
double minPeriod = averagePeriod/2.0;
double maxPeriod = minPeriod*5.0;
int endPeriod = MathCeil(maxPeriod);
double signal = MathAbs((price-stored[r-endPeriod][res+s]));
double noise = 0.00000000001;
for(int k=1; k<endPeriod; k++) noise=noise+MathAbs(price-stored[r-k][res+s]);
averagePeriod = ((signal/noise)*(maxPeriod-minPeriod))+minPeriod;
}
//
//
//
//
//
double alpha = (2.0+const)/(1.0+const+averagePeriod);
e1 = e1 + alpha*(price-e1); e2 = e2 + alpha*(e1-e2); double v1 = 1.5 * e1 - 0.5 * e2;
e3 = e3 + alpha*(v1 -e3); e4 = e4 + alpha*(e3-e4); double v2 = 1.5 * e3 - 0.5 * e4;
e5 = e5 + alpha*(v2 -e5); e6 = e6 + alpha*(e5-e6); double v3 = 1.5 * e5 - 0.5 * e6;
//
//
//
//
//
stored[r][E1+s] = e1; stored[r][E2+s] = e2;
stored[r][E3+s] = e3; stored[r][E4+s] = e4;
stored[r][E5+s] = e5; stored[r][E6+s] = e6;
stored[r][res+s] = price;
return(v3);
}
Merci