voila le code modifié :
//+------------------------------------------------------------------+
//| Test Alligator.mq4 |
//| Merci à : Babs Assoc. |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, Cadmos"
//+------------------------------------------------------------------+
//| External Parameters |
//+------------------------------------------------------------------+
extern int MagicNumber = 69;
extern double lot = 0.05;
extern int TakeProfit = 10000;
extern int StopLoss = 9;
//+------------------------------------------------------------------+
//| Global Variable |
//+------------------------------------------------------------------+
int OpenedOrder; // 1=Buy , 2=Sell
double MyPoint;
int NbBars;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
OpenedOrder=FALSE;
NbBars=0;
if (Digits == 5 || Digits == 3) MyPoint = Point*10;
else MyPoint= Point;
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
double jaw_val, jaw_valPrev;
double lips_val, lips_valPrev;
//Acquisition des
indicateurs
jaw_val=iAlligator(NULL, 60, 10, 2, 8, 1, 6, 0, MODE_EMA, PRICE_MEDIAN, MODE_GATORJAW, 0);
jaw_valPrev=iAlligator(NULL, 60, 10, 2, 8, 1, 6, 0, MODE_EMA, PRICE_MEDIAN, MODE_GATORJAW, 1);
lips_val=iAlligator(NULL, 60, 10, 2, 8, 1, 6, 0, MODE_EMA, PRICE_MEDIAN, MODE_GATORLIPS, 0);
lips_valPrev=iAlligator(NULL, 60, 10, 2, 8, 1, 6, 0, MODE_EMA, PRICE_MEDIAN, MODE_GATORLIPS, 1);
//Verification des trades ouverts
CheckTrade();
//Logique
if(isNewBar())
{
if(lips_val>=jaw_val && lips_valPrev<jaw_valPrev && (OpenedOrder==2 || OpenedOrder==0)) //Croisement à la hausse
{
CloseTrade();
OpenBuy();
}
if(lips_val<=jaw_val && lips_valPrev>jaw_valPrev && (OpenedOrder==1 || OpenedOrder==0)) // Croisement à la baisse
{
CloseTrade();
OpenSell();
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| expert Close Buy/Sell order function |
//+------------------------------------------------------------------+
void CloseTrade()
{
for(int i= OrdersTotal()-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
int type = OrderType();
if (OrderMagicNumber() == MagicNumber && Symbol()==OrderSymbol()) {
switch(type)
{
//Fermeture des positions d’achat
case OP_BUY : OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(),MarketInfo(OrderSymbol(), MODE_BID), Red );
break;
// Fermeture des positions de vente
case OP_SELL : OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(),MarketInfo(OrderSymbol(), MODE_ASK), Red );
break;
}
}
}
}
//+------------------------------------------------------------------+
//| expert Open Buy order function |
//+------------------------------------------------------------------+
void OpenBuy() {
if (!IsTradeContextBusy() && IsTradeAllowed())
{
OrderSend(Symbol(),OP_BUY,lot,Ask,3,Bid-StopLoss*MyPoint,Ask+TakeProfit*MyPoint,"69 Année érotique",MagicNumber,0,Green);
}
}
//+------------------------------------------------------------------+
//| expert Open Sell order function |
//+------------------------------------------------------------------+
void OpenSell() {
if (!IsTradeContextBusy() && IsTradeAllowed())
{
OrderSend(Symbol(),OP_SELL,lot,Bid,3,Ask+StopLoss*MyPoint,Bid-TakeProfit*MyPoint,"69 Année érotique",MagicNumber,0,Green);
}
}
//+------------------------------------------------------------------+
//| Check order function |
//+------------------------------------------------------------------+
void CheckTrade() {
OpenedOrder=0;
for(int i= OrdersTotal()-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
int type = OrderType();
if (OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol())
{
switch(type)
{
case OP_BUY : OpenedOrder=1;
break;
case OP_SELL : OpenedOrder=2;
break;
}
}
}
}
//+------------------------------------------------------------------+
//| Check New Bar function |
//+------------------------------------------------------------------+
bool isNewBar() {
if (NbBars < Bars) {
NbBars = Bars;
return (TRUE);
}
return (FALSE);
}