MQL4 Crossover function?

SanMiguel

Experienced member
Messages
1,136
Likes
25
I am modifying the alligator indicator.
I want it to send me a screen alert when the green line crfosses the red line but it does this constantly, not just once and then again on the next cross
Any ideas:
for(int i=0; i<limit; i++)
{
//---- ma_shift set to 0 because SetIndexShift called abowe
ExtBlueBuffer=iMA(NULL,0,JawsPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);
ExtRedBuffer=iMA(NULL,0,TeethPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);
//Print(iMA(NULL,0,TeethPeriod,0,MODE_SMMA,PRICE_MEDIAN,i));
ExtLimeBuffer=iMA(NULL,0,LipsPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);
int isCrossed = Crossed (iMA(NULL,0,TeethPeriod,0,MODE_SMMA,PRICE_MEDIAN,i),iMA(NULL,0,LipsPeriod,0,MODE_SMMA,PRICE_MEDIAN,i));
//if (isCrossed==1) {Alert("Teeth have crossed lips");}
}


Crossed function:
int Crossed (double line1 , double line2)
{
static int last_direction = 0;
static int current_direction = 0;
if(line1>line2)current_direction = 1; //up
if(line1<line2)current_direction = 2; //down
if(current_direction != last_direction) //changed
{
last_direction = current_direction;
return (last_direction);
}
else
{
return (0);
}
}
 
Hi SanMiguel,
I'm trying to do the same thing; be alerted when the alligator lines cross. Code below notifies me when the price has crossed the line.

//---- Test if price is crossing lips, teeth, jaws or tail
lips = ExtLimeBuffer;
teeth = ExtRedBuffer;
jaws = ExtBlueBuffer;
tail = ExtDarkSlateGrayBuffer;

if ( lips < Bid ) { PriceIsAboveLips = true; }
if ( lips > Bid ) { PriceIsAboveLips = false; }



if ( PriceIsAboveLips )
{
if ( PriceWasBelowLips )
{
Print(Symbol()," ",Period()," Price: ",Bid, " may soon break UP through lips:", lips);
PriceWasBelowLips = false;
}

}

if ( PriceIsAboveLips == false )
{
if ( PriceWasBelowLips == false )
{
Print(Symbol()," ",Period()," Price: ",Bid, " may soon break DOWN through lips:", lips);
PriceWasBelowLips = true;
}

}
 
Top