Simple Bug......

 

i have this indicator but the sound and the indicator don't work. If you compile it has an error.

here is the code as well as the indicator.....I would be very grateful for your time as well as your solution.


//+------------------------------------------------------------------+
//| TrendMagic.mq4 |
//| Tidied up by TudorGirl 28 May 2009 |
//| AnneTudor@ymail.com |
//+------------------------------------------------------------------+

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

//+------------------------------------------------------------------+
//---- indicator parameters
extern int CCI = 50;
extern int ATR = 5;
//---- indicator parameters
//-------------------------------------------------------------------
//extern int TRIX_Period = 3;
//extern int Signal_Period = 0;
extern bool Signals = false;
extern int CountBars = 1500;
//-------------------------------------------------------------------
//+------------------------------------------------------------------+

double bufferUp[];
double bufferDn[];
//---- variables
static bool TurnedUp = false;
static bool TurnedDown = false;
//+------------------------------------------------------------------+

int init()
{
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(0, bufferUp);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(1, bufferDn);
return (0);
}

//+------------------------------------------------------------------+

int deinit()
{
return (0);
}

//+------------------------------------------------------------------+

int start()
{

double thisCCI;
double lastCCI;

int counted_bars = IndicatorCounted();
if (counted_bars < 0) return (-1);
if (counted_bars > 0) counted_bars--;
int limit = Bars - counted_bars;

for (int shift = limit; shift >= 0; shift--)
{
thisCCI = iCCI(NULL, 0, CCI, PRICE_TYPICAL, shift);
lastCCI = iCCI(NULL, 0, CCI, PRICE_TYPICAL, shift + 1);

if (thisCCI >= 0 && lastCCI < 0) bufferUp[shift + 1] = bufferDn[shift + 1];
if (thisCCI <= 0 && lastCCI > 0) bufferDn[shift + 1] = bufferUp[shift + 1];

if (thisCCI >= 0)
{
bufferUp[shift] = Low[shift] - iATR(NULL, 0, ATR, shift);
if (bufferUp[shift] < bufferUp[shift + 1])
bufferUp[shift] = bufferUp[shift + 1];
}
else
{
if (thisCCI <= 0)
{
bufferDn[shift] = High[shift] + iATR(NULL, 0, ATR, shift);
if (bufferDn[shift] > bufferDn[shift + 1])
bufferDn[shift] = bufferDn[shift + 1];
}
}
}
//---- signals
shift=limit-1;
while(shift>=0)
{
if (Signals==true)
{
if (bufferUp < bufferDn && bufferUp[shift] < bufferDn[shift + 1] && TurnedUp==false);
if (bufferUp > bufferDn && bufferUp[shift] > bufferDn[shift + 1] && TurnedUp==true);
// if (ind_buffer2a[i]<ind_buffer1a[i] && ind_buffer2a[i+1]>=ind_buffer1a[i+1]) ind_buffer3[i]=ind_buffer2a[i]-0.0001;
// if (ind_buffer2a[i]>ind_buffer1a[i] && ind_buffer2a[i+1]<=ind_buffer1a[i+1]) ind_buffer4[i]=ind_buffer2a[i]+0.0001;

// if (ind_buffer3[0]==ind_buffer2a[0]-0.0001 && TurnedUp==false)
{
Alert("Trend Magic Buy: ",Symbol()," - ",Period()," at ", Close[0]," - ", TimeToStr(CurTime(),TIME_SECONDS));
TurnedDown = false;
TurnedUp = true;
}
// if (ind_buffer4[0]==ind_buffer2a[0]+0.0001 && TurnedDown==false)
{
Alert("Trend Magic SELL: ",Symbol()," - ",Period()," at ", Close[0]," - ", TimeToStr(CurTime(),TIME_SECONDS));
TurnedUp = false;
TurnedDown = true;
}
}
shift--;
}
//---- done
return (0);




Files:
 
//+------------------------------------------------------------------+
//| TrendMagic.mq4 |
//| Tidied up by TudorGirl 28 May 2009 |
//| AnneTudor@ymail.com |
//+------------------------------------------------------------------+

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

//+------------------------------------------------------------------+
//---- indicator parameters
extern int CCI = 50;
extern int ATR = 5;
//---- indicator parameters
//-------------------------------------------------------------------
//extern int TRIX_Period = 3;
//extern int Signal_Period = 0;
extern bool Signals = false;
extern int CountBars = 1500;
//-------------------------------------------------------------------
//+------------------------------------------------------------------+

double bufferUp[];
double bufferDn[];
//---- variables
static bool TurnedUp = false;
static bool TurnedDown = false;
//+------------------------------------------------------------------+

int init()
{
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(0, bufferUp);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(1, bufferDn);
return (0);
}

//+------------------------------------------------------------------+

int deinit()
{
return (0);
}

//+------------------------------------------------------------------+

int start()
{
double thisCCI;
double lastCCI;

int counted_bars = IndicatorCounted();
if (counted_bars < 0) return (-1);
if (counted_bars > 0) counted_bars--;
int limit = Bars - counted_bars;
for (int shift = limit; shift >= 0; shift--)
{
	thisCCI = iCCI(NULL, 0, CCI, PRICE_TYPICAL, shift);
	lastCCI = iCCI(NULL, 0, CCI, PRICE_TYPICAL, shift + 1);

	if (thisCCI >= 0 && lastCCI < 0) bufferUp[shift + 1] = bufferDn[shift + 1];
	if (thisCCI <= 0 && lastCCI > 0) bufferDn[shift + 1] = bufferUp[shift + 1];

	if (thisCCI >= 0)
	{
	bufferUp[shift] = Low[shift] - iATR(NULL, 0, ATR, shift);
	if (bufferUp[shift] < bufferUp[shift + 1])
	bufferUp[shift] = bufferUp[shift + 1];
	}
	else
	{
	if (thisCCI <= 0)
		{
		bufferDn[shift] = High[shift] + iATR(NULL, 0, ATR, shift);
		if (bufferDn[shift] > bufferDn[shift + 1])
		bufferDn[shift] = bufferDn[shift + 1];
		}
	}
}


//---- signals
shift=limit-1;
while(shift>=0)
   {
  // if (bufferUp > bufferDn && bufferUp[shift] > bufferDn[shift + 1] && TurnedUp==true);
   //if (bufferUp < bufferDn && bufferUp[shift] < bufferDn[shift + 1] && TurnedUp==false);

// if (ind_buffer2a[i]<ind_buffer1a[i] && ind_buffer2a[i+1]>=ind_buffer1a[i+1]) ind_buffer3[i]=ind_buffer2a[i]-0.0001;
// if (ind_buffer2a[i]>ind_buffer1a[i] && ind_buffer2a[i+1]<=ind_buffer1a[i+1]) ind_buffer4[i]=ind_buffer2a[i]+0.0001;

// if (ind_buffer3[0]==ind_buffer2a[0]-0.0001 && TurnedUp==false)
{ 
Alert("Trend Magic Buy: ",Symbol()," - ",Period()," at ", Close[0]," - ", TimeToStr(CurTime(),TIME_SECONDS));
TurnedDown = false;
TurnedUp = true;
} 
// if (ind_buffer4[0]==ind_buffer2a[0]+0.0001 && TurnedDown==false)
{ 
Alert("Trend Magic SELL: ",Symbol()," - ",Period()," at ", Close[0]," - ", TimeToStr(CurTime(),TIME_SECONDS));
TurnedUp = false;
TurnedDown = true;
} 

   }
shift--;
return (0);
}
check this out
 
fx1.net:
check this out


The code that you modified seems not to work....it makes ma meta-trader hang...I have to switch off the meta-trader and restart it again...I think there's an error i the code. have alook again. THANK YOU VERY MUCH FOR YOUR HELP.......=)
 
I think there's an error i the code. have alook again.

Infinite loop. shift-- in the wrong place.

 
My friend i did not modify nothing; i simply commented some lines out because they are not valid and put brackets to right place. its 100% your code, nothing changed. have fun
 
I went through the code and since am so good in programming i was able to notice that the Trend Magic indicator is based on the 50 cci zero-line crossover. so i searched the net and i got an alternative....thanks for your help anyway....keep up the good work
Reason: