Hello,
although both Moving Average lines are equal an order where send by my script. But I donīt wants this.
Here some code:
PHP Code:
//Crossed function for example
int Crossed (double line1 , double line2)
{
static int last_direction = 0;
static int current_direction = 0;
if(line1==line2)return (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);
}
}
//Call of the function inside start()
SEma = iMA(NULL,0,ShortEma,0,MODE_EMA,PRICE_CLOSE,1);
LEma = iMA(NULL,0,LongEma,0,MODE_EMA,PRICE_CLOSE,1);
int isCrossed = 0;
isCrossed = Crossed(SEma,LEma);
if(isCrossed == 1)
{
OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-StopLoss*Point,Ask+TakeProfit*Point,Name_Expert,MAGIC,0,Green);
return(0);
}
if(isCrossed == 2)
{
OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Bid+StopLoss*Point,Bid-TakeProfit*Point,Name_Expert,MAGIC,0,Red);
return(0);
}
Although both Moving Average lines are equivalent high often simply an order are made.
I understand that not, can me someone help?