Here are more lines of code that show how I evaluated the average fractal directional bias values. Those values were shown as different colors of a histogram so I could see what they were currently, and historically to see how well it worked in the past to predict good trades. Just compile the code below and it should work. Please let me know if you get any errors.
Code: Select all
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_minimum 0
#property indicator_maximum 1
#property strict
extern string TimeFrames = "M5;M15;M30;H1;H4"; // Time frames to use (separated by ";" in the list)
extern int MaxBars = 500; // Maximum Bars
extern bool UseOrigFormula = false; // Use Original Formula
extern bool UseDpsAvg = true; // Use FG Average
extern color StrongUp = clrAqua; // Color for strong up
extern color MidUp = clrDodgerBlue; // Color for mid up
extern color WeakUp = clrDarkSlateBlue; // Color for weak up
extern color NoMove = clrSilver; // Color for no trend
extern color WeakDown = clrMaroon; // Color for weak down
extern color MidDown = clrFireBrick; // Color for mid down
extern color StrongDown = clrRed; // Color for strong down
extern int HistogramWidth = 3; // Histogram width
double buffer1[], buffer2[], buffer3[], buffer4[], buffer5[], buffer6[], Bias[];
int ctimesLen, aTimes[];
bool returnBars;
string indyFractalGeo="Fractals Geometry v1.4_mt_fix3";
double value;
int OnInit()
{
IndicatorBuffers(7);
SetIndexBuffer(0,buffer1); SetIndexLabel(0,"StrongUp");
SetIndexBuffer(1,buffer2); SetIndexLabel(1,"MidUp");
SetIndexBuffer(2,buffer3); SetIndexLabel(2,"WeakUp");
SetIndexBuffer(3,buffer4); SetIndexLabel(3,"StrongDown");
SetIndexBuffer(4,buffer5); SetIndexLabel(4,"MidDown");
SetIndexBuffer(5,buffer6); SetIndexLabel(5,"WeakDown");
SetIndexBuffer(6,Bias); SetIndexStyle(6,DRAW_NONE); SetIndexLabel(6,"Bias");
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,HistogramWidth,StrongUp);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,HistogramWidth,MidUp);
SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,HistogramWidth,WeakUp);
SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,HistogramWidth,StrongDown);
SetIndexStyle(4,DRAW_HISTOGRAM,STYLE_SOLID,HistogramWidth,MidDown);
SetIndexStyle(5,DRAW_HISTOGRAM,STYLE_SOLID,HistogramWidth,WeakDown);
ctimesLen = ArraySize(aTimes);
int s = 0, i = StringFind(TimeFrames,";",s);
while(i > 0)
{
string current = StringSubstr(TimeFrames,s,i-s);
int time = stringToTimeFrame(current);
if(time > 0)
{
ArrayResize(aTimes,ArraySize(aTimes)+1);
aTimes[ArraySize(aTimes)-1] = time;
}
s = i + 1;
i = StringFind(TimeFrames,";",s);
}
IndicatorDigits(Digits);
return(INIT_SUCCEEDED);
}
int start()
{
int counted_bars=IndicatorCounted();
int pos,limit;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=MathMin(Bars-counted_bars,Bars-1);
if(MaxBars>0 && limit>MaxBars) limit=MaxBars;
if(returnBars) { buffer1[0] = MathMin(limit+1,Bars-1); return(0); }
double sumvalue=0;
double DpsAvg=0;
int ReduceDiv=0;
color theColor = NoMove;
string eToolTip = "NoMove";
for(pos=limit; pos>=0 && !_StopFlag; pos--)
{
for(int t = 0; t < ctimesLen; t++)
{
//+-----------------------------------------------------------------------------------------------------------+
// indyFractalGeo="Fractals Geometry v1.4_mtf_fix3";
// extern ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; // Time frame
// For non-MTF version of Fractals Geometry v1.4
// double value=iCustom(NULL,aTimes[t],indyFractalGeo,5,pos);
// For MTF version of Fractals Geometry v1.4_mtf_fix3
// double value=iCustom(NULL,0,indyFractalGeo,aTimes[t],5,pos);
value=iCustom(NULL,0,indyFractalGeo,aTimes[t],5,pos);
// if(pos==0 && aTimes[t]==240) Comment(value);
if(t==0) { sumvalue=0; DpsAvg=0; ReduceDiv=0; }
if(UseOrigFormula)
{
if(value==1 || value==-1) value=0;
else if(value==2) value=1;
else if(value==-2) value=-1;
}
sumvalue+=value;
if(value==0) ReduceDiv++;
if(t==ArraySize(aTimes)-1)
{
DpsAvg=DivZero(sumvalue,ArraySize(aTimes)-ReduceDiv);
// Display as a colored histogram in the subwindow.
Bias[pos]=DpsAvg;
buffer1[pos] = EMPTY_VALUE; //StrongUp
buffer2[pos] = EMPTY_VALUE; //MidUp
buffer3[pos] = EMPTY_VALUE; //WeakUp
buffer4[pos] = EMPTY_VALUE; //StrongDown
buffer5[pos] = EMPTY_VALUE; //MidDown
buffer6[pos] = EMPTY_VALUE; //WeakDown
if(UseDpsAvg)
{
theColor = NoMove;
eToolTip="NoMove";
if(DpsAvg>1) { buffer1[pos] = 1; theColor = StrongUp; eToolTip="StrongUp"; } // StrongUp;
// else if(DpsAvg==1) { buffer2[pos] = 1; theColor = MidUp; eToolTip="MidUp"; } // MidUp;
else if(DpsAvg>0.5) { buffer2[pos] = 1; theColor = MidUp; eToolTip="MidUp"; } // MidUp;
else if(DpsAvg>0) { buffer3[pos] = 1; theColor = WeakUp; eToolTip="WeakUp"; } // WeakUp;
else if(DpsAvg<-1) { buffer4[pos] = 1; theColor = StrongDown; eToolTip="StrongDown"; } // StrongDown;
// else if(DpsAvg==-1) { buffer5[pos] = 1; theColor = MidDown; eToolTip="MidDown"; } // MidDown;
else if(DpsAvg<-0.5) { buffer5[pos] = 1; theColor = MidDown; eToolTip="MidDown"; } // MidDown;
else if(DpsAvg<0) { buffer6[pos] = 1; theColor = WeakDown; eToolTip="WeakDown"; } // WeakDown;
}
else
{
theColor = NoMove;
eToolTip="NoMove";
if((int)DpsAvg>1) { buffer1[pos] = 1; theColor = StrongUp; eToolTip="StrongUp"; } // StrongUp;
else if((int)DpsAvg==1) { buffer2[pos] = 1; theColor = MidUp; eToolTip="MidUp"; } // MidUp;
else if((int)DpsAvg>0) { buffer3[pos] = 1; theColor = WeakUp; eToolTip="WeakUp"; } // WeakUp;
else if((int)DpsAvg<-1) { buffer4[pos] = 1; theColor = StrongDown; eToolTip="StrongDown"; } // StrongDown;
else if((int)DpsAvg==-1) { buffer5[pos] = 1; theColor = MidDown; eToolTip="MidDown"; } // MidDown;
else if((int)DpsAvg<0) { buffer6[pos] = 1; theColor = WeakDown; eToolTip="WeakDown"; } // WeakDown;
}
} // if(t==ArraySize(aTimes)-1)
} // for(int t = 0; t < ctimesLen; t++)
} //for(pos=limit; pos>=0 && !_StopFlag; pos--)
return(0);
}
//+------------------------------------------------------------------+
//| TimeFrame Functions |
//+------------------------------------------------------------------+
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)
{
StringToUpper(tfs);
for(int i=ArraySize(iTfTable)-1; i>=0; i--)
if(tfs==sTfTable[i] || tfs==""+(string)iTfTable[i]) return(iTfTable[i]);
return(_Period);
}
string timeFrameToString(int tf)
{
for(int i=ArraySize(iTfTable)-1; i>=0; i--)
if(tf==iTfTable[i]) return(sTfTable[i]);
return("");
}
//+------------------------------------------------------------------+
//| DivZero: Divides N by D, and returns 0 if the denominator (D) = 0| |
//+------------------------------------------------------------------+
double DivZero(double n,double d)
{
// Usage: double x = DivZero(y,z) sets x = y/z
// Use DivZero(y,z) instead of y/z to eliminate division by zero errors
if(d == 0) return(0); else return(1.0*n/d);
}