Voilà
j'ai ajouté 3 variable
UseTrainling = qui permet d'activer le traling ou pas;
TrailingValue = la valeur en point du trailing stop;
MinimumWin = permet de faire en sorte que le trailing ne soit actif que si ton trade gagne cette valeur en point ... à 0 le trailing est actif dès le départ du trade.
Voilà voilà .. bons trades
:)
#property copyright "Copyright © 2011, Damien Soudant"
#property link "
[email protected]"
#define _STRAT "Forexagone Help"
//---- Input Paramettres
extern bool UseSl = true;
extern int SlSize = 500;
extern bool UseTp = true;
extern int TpSize = 500;
extern double Lots = 0.1;
extern int Ea_ID = 5555;
//----
extern double PointsDif = 500;
extern bool UseTrailing = true;
extern int TrailingValue = 250;
extern int MinimumWin = 250;
bool IsBuy;
bool IsSell;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
IsSell = false;
IsBuy = false;
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
Print("De- initialisation de l ea"
;);
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
IsSell = false;
IsBuy = false;
for(int i= 0; i<=OrdersTotal(); i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()!= Symbol()) continue;
if(OrderMagicNumber() !=Ea_ID)continue;
if(OrderType() == OP_BUY)
{
IsBuy = true;
if(UseSl && OrderStopLoss()<=0)
{
if(OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(OrderOpenPrice()-SlSize*Point, Digits),OrderTakeProfit(), 0, CLR_NONE))
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
Print(_STRAT+" Validation du stop loss à " + DoubleToStr(OrderStopLoss(), Digits));
}
}
if(UseTp && OrderTakeProfit()<=0)
{
if(OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), NormalizeDouble(OrderOpenPrice()+TpSize*Point, Digits), 0, CLR_NONE))
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
Print(_STRAT+" Validation du take profit à " + DoubleToStr(OrderTakeProfit(), Digits));
}
}
if(UseTrailing)
{
double sl = OrderStopLoss();
if(Ask-(TrailingValue*Point)>=sl&&(Ask-OrderOpenPrice())/Point>=MinimumWin)
{
sl = NormalizeDouble(Ask-(TrailingValue*Point), Digits);
if(OrderStopLoss() !=sl)OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), NULL, CLR_NONE);
}
}
}// Fin de gestion des ordres achats
if(OrderType() == OP_SELL)
{
IsSell = true;
if(UseSl && OrderStopLoss()<=0)
{
if(OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(OrderOpenPrice()+SlSize*Point, Digits),OrderTakeProfit(), 0, CLR_NONE))
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
Print(_STRAT+" Validation du stop loss à " + DoubleToStr(OrderStopLoss(), Digits));
}
}
if(UseTp && OrderTakeProfit()<=0)
{
if(OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), NormalizeDouble(OrderOpenPrice()-TpSize*Point, Digits), 0, CLR_NONE))
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
Print(_STRAT+" Validation du take profit à " + DoubleToStr(OrderTakeProfit(), Digits));
}
}
if(UseTrailing)
{
sl = OrderStopLoss();
if(Bid+(TrailingValue*Point)<=sl && (OrderOpenPrice()-Bid)/Point>=MinimumWin)
{
sl = NormalizeDouble(Bid+(TrailingValue*Point), Digits);
if(OrderStopLoss() !=sl)OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), NULL, CLR_NONE);
}
}
} // fin de gestion des ordres de ventes
}// fin boucle ordres ouverts
if(!IsSell && !IsBuy)
{
if(BuySignal())
{
// a faire lors d'une contiion d'achat;
if(Trade(OP_BUY, Ask, Lots, Ea_ID))
{
Print(_STRAT+" Succes to open buy position"
;);
}
}
if(SellSignal())
{
// a faire lors d'une condition de vente;
if(Trade(OP_SELL, Bid, Lots, Ea_ID))
{
Print(_STRAT+" Succes to open sell position"
;);
}
}
}// fin block non trade
//----
return(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Buy Conditions |
//+------------------------------------------------------------------+
bool BuySignal()
{
if((Close[0]-Open[0])/Point>=PointsDif)
{
return(true);
}
return(false);
}
//+------------------------------------------------------------------+
//| Sell Conditions |
//+------------------------------------------------------------------+
bool SellSignal()
{
if((Open[0]-Close[0])/Point>=PointsDif)
{
return(true);
}
return(false);
}
//+------------------------------------------------------------------+
//| Send Order Function |
//+------------------------------------------------------------------+
bool Trade(int type, double price, double vol, int magic)
{
if(type != OP_SELL && type!=OP_BUY)
{
Print(_STRAT+" Error top open trade := False argument"
;);
return(false);
}
int ticket = OrderSend(Symbol(), type, vol, NormalizeDouble(price, Digits), 300, 0, 0, "", magic, 0, CLR_NONE);
if(ticket>0)
{
return(true);
}
return(false);
}