J'ai trouvé un indicateur sympa qui signale le croisement de 2 moyennes mobiles. Le soucis c'est qu'il le signale à chaque croisement.
Quelqu'un serait-il le modifier pour qu'il ne signale que en un croisement franc ?
Merci d'avance.
Code : Tout sélectionner
//+------------------------------------------------------------------+
//| croisement de moyenne mobile.mq4 |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Croisement moyenne mobile.mq4 |
//| By Zed |
//| |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
//---- input parameters
extern int fastperiod=12;
extern int slowperiod=36;
extern bool EnableAlert=true;
//---- buffers
double val1[];
double val2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicator line
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,234);
SetIndexBuffer(0,val1);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,233);
SetIndexBuffer(1,val2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| ema cross |
//+------------------------------------------------------------------+
int start()
{
int i,shift,counted_bars=IndicatorCounted();
double fastEma, slowEma,fastEmaPrev, slowEmaPrev;
bool IsLong=false;
bool IsShort=false;
int tendance;
for (shift = counted_bars; shift>=0; shift--)
{
fastEma = iMA(NULL,0,fastperiod,0,MODE_SMA,PRICE_CLOSE,shift);
slowEma = iMA(NULL,0,slowperiod,0,MODE_SMA,PRICE_CLOSE,shift);
fastEmaPrev = iMA(NULL,0,fastperiod,0,MODE_SMA,PRICE_CLOSE,shift+1);
slowEmaPrev = iMA(NULL,0,slowperiod,0,MODE_SMA,PRICE_CLOSE,shift+1);
val1[shift]=0;
val2[shift]=0;
if ((fastEma>slowEma)&&(fastEmaPrev<slowEmaPrev))
{
val1[shift]=0;
val2[shift]=Low[shift]-10*Point;
if ((EnableAlert)&&(shift==0))
{
Alert("Croisement à la Hausse");
}
}
if ((fastEma<slowEma)&&(fastEmaPrev>slowEmaPrev))
{
val1[shift]=High[shift]+10*Point;
val2[shift]=0;
if ((EnableAlert)&&(shift==0))
{
Alert("Croisement à la baisse");
}
}
}
return(0);
}
//+------------------------------------------------------------------+