Error Indicator MTF don't work correctly

 
Greetings everyone, I need a little help from you .
//---- ma_angle_mtf.mql4

//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 LimeGreen
#property indicator_color2 FireBrick 
#property indicator_color3 Yellow
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_level1 2
#property indicator_level2 -2


//---- indicator parameters
extern int    TimeFrame     = 60;
extern int    MAMode        = 0;
extern int    MAPeriod      = 3;
extern int    Price         = 0;
extern double AngleTreshold = 0.25;
extern int    StartMAShift  = 2;
extern int    EndMAShift    = 0;

extern int    MaxBars       = 1000;

string TF1;
//---- indicator buffers
double UpBuffer[];
double DownBuffer[];
double ZeroBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 2 additional buffers are used for counting.
IndicatorBuffers(3);
//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexStyle(2,DRAW_HISTOGRAM);

IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2 );

//---- 3 indicator buffers mapping
if(!SetIndexBuffer(0,UpBuffer) &&
!SetIndexBuffer(1,DownBuffer) &&
!SetIndexBuffer(2,ZeroBuffer))
Print("cannot set indicator buffers!");

SetIndexLabel(0,"");
SetIndexLabel(1,"");
SetIndexLabel(2,"");

                switch(TimeFrame)
        {
                case 1:         TF1="M1";  break;
                case 5:         TF1="M5";  break;
                case 15:                TF1="M15"; break;
                case 30:                TF1="M30"; break;
                case 60:                TF1="H1";  break;
                case 240:       TF1="H4";  break;
                case 1440:      TF1="D1";  break;
                case 10080:     TF1="W1";  break;
                case 43200:     TF1="MN1"; break;
                default:          {TimeFrame = Period(); init(); return(0);}
        }
IndicatorShortName("MAAngle MTF * "+TF1+" *");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| The angle for EMA |
//+------------------------------------------------------------------+
int start()
{
double fEndMA, fStartMA;
double fAngle, mFactor, dFactor;
int nLimit, i;
int nCountedBars;
double angle;
int ShiftDif;
string Sym;

if (MAMode >= 4) MAMode = 0;

if(EndMAShift >= StartMAShift)
{
Print("Error: EndMAShift >= StartMAShift");
StartMAShift = 6;
EndMAShift = 0; 
} 

nCountedBars = IndicatorCounted();

dFactor = 2*3.14159/180.0;
mFactor = 10000.0;
Sym = StringSubstr(Symbol(),3,3);
if (Sym == "JPY") mFactor = 100.0;
ShiftDif = StartMAShift-EndMAShift;
mFactor /= ShiftDif; 

//---- check for possible errors
     if(nCountedBars<0) return(-1);
//---- last counted bar will be recounted
     if(nCountedBars>0) nCountedBars--;
     nLimit=Bars-nCountedBars;
     nLimit=MathMax(nLimit,TimeFrame/Period());
     nLimit=MathMin(nLimit,MaxBars );  
//---- main loop
for(i=0; i<nLimit; i++)
{

 int y = iBarShift(NULL,TimeFrame,Time[i]);
 if (TimeFrame<Period()) TimeFrame=Period();
fEndMA=iMA(NULL,TimeFrame,MAPeriod,0,MAMode,Price,y+EndMAShift);
fStartMA=iMA(NULL,TimeFrame,MAPeriod,0,MAMode,Price,y+StartMAShift); 
 
// 10000.0 : Multiply by 10000 so that the fAngle is not too small
// for the indicator Window.
fAngle = mFactor * (fEndMA - fStartMA)/2.0;
//fAngle = MathArctan(fAngle)/dFactor;

DownBuffer[i] = 0.0;
UpBuffer[i] = 0.0;
ZeroBuffer[i] = 0.0;

if(fAngle > AngleTreshold)
UpBuffer[i] = fAngle;
else if (fAngle < -AngleTreshold)
DownBuffer[i] = fAngle;
else ZeroBuffer[i] = fAngle;
}

return(0);
}
//+------------------------------------------------------------------+




        
Files:
ayuda_mql5.png  103 kb
 
Error in my indicator MTF
Very grateful for your time everyone. This indicator helps my system
 
  1. Why did you post your MT4 question in the Root / MT5 Systems section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Looks like you checked indicator → Properties → Common → Fixed minimum.
 
Sorry I'm new member.

I have tried everything and could not find the solution
 
danielocash:
Sorry I'm new member.

I have tried everything and could not find the solution

These lines:

if(!SetIndexBuffer(0,UpBuffer) &&
!SetIndexBuffer(1,DownBuffer) &&
!SetIndexBuffer(2,ZeroBuffer))
Print("cannot set indicator buffers!");

should be changed to:

if (!(SetIndexBuffer(0,UpBuffer) &&
      SetIndexBuffer(1,DownBuffer) &&
      SetIndexBuffer(2,ZeroBuffer))
   Print("cannot set indicator buffers!");
Reason: