Merci d'ameliorer cet EA...
Code
//+------------------------------------------------------------------+
//| DOUDOU.mq4 |
//| QPG |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "QPG"
#property link "https://www.mql5.com"
#property version "1.00"
//#property strict
//+------------------------------------------------------------------+
EURUSD 1 MN |
//+------------------------------------------------------------------+
extern string mm="MONEY MANAGEMENT";
double lot;
extern double LotFactor = 145; //lotsize factor
extern bool trail = true;
extern double TrailingStop = 67;
extern int StopLoss=5000; //stop loss
extern int TakeProfit=70; //take profit
extern double pips = 0.00001; //leave as default for 5 digit brokers
extern int Slippage=3;
extern int MagicNumber=20180807; //magic
sinput string RSI_Settings;
input int period=12; // Averagin period for calculation
input ENUM_APPLIED_PRICE appPrice=PRICE_HIGH; // Applied price
input int OverSold=85; // Over bought level
input int OverBought=15; // Over sold level
extern int a=2;
extern int b=3;
extern int c=3;
extern int d=3;
extern int e=3;
extern int f=2;
extern int g=3;
extern int h=3;
extern int x=2;
extern int j=3;
extern int k=0;
extern int l=3;
extern string bo="BOOSTER";
extern int adxthreshold = 33; //adx threshold - must be greater than this to trade
extern int adxperiod = 24; //adx period
extern int rsiperiod = 4; //rsi period
extern int rsiupper = 90; //rsi upper bound, wont buy above this value
extern int rsilower = 70; //rsi lower bound, wont sell below this value
//----
double TP=0,SL=0,TR;
//+------------------------------------------------------------------+
//| Hidden StopLoss Calculations |
//+------------------------------------------------------------------+
void StpLoss()
{
double MyPoint=Point;
if(Digits==3 || Digits==5) MyPoint=Point*10;
TP=TakeProfit*MyPoint;
SL=StopLoss*MyPoint;
double OrdP=0,OrdTP=0,OrdSL=0;
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if(OrderMagicNumber()==MagicNumber && Symbol()==OrderSymbol())
{
OrdP=OrderProfit()-MathAbs(OrderSwap())-MathAbs(OrderCommission());
OrdSL=(-1)*SL*OrderLots()*MarketInfo(OrderSymbol(),MODE_TICKVALUE)/Point;
OrdTP=TP*OrderLots()*MarketInfo(OrderSymbol(),MODE_TICKVALUE)/Point;
if(OrdP>OrdTP || OrdP<OrdSL)
{
if(OrderType()==OP_BUY)
bool OrdClP=OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,clrGreen);
if(OrderType()==OP_SELL)
bool OrdClL=OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,clrYellow);
}
}
}
}
//+------------------------------------------------------------------+
//| Trailing Stop |
//+------------------------------------------------------------------+
void trail()
{
for (int i = 0; i < OrdersTotal(); i++) {
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
if ( OrderSymbol()==Symbol() )
{
if (OrderType() == OP_BUY) {
if (Bid - OrderOpenPrice() > TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT)) {
if (OrderStopLoss() < Bid - TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT)) {
bool modify1=OrderModify(OrderTicket(), OrderOpenPrice(), Bid - TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT), OrderTakeProfit(), Red);
}
}
} else if (OrderType() == OP_SELL) {
if (OrderOpenPrice() - Ask > TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT)) {
if ((OrderStopLoss() > Ask + TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT)) ||
(OrderStopLoss() == 0)) {
bool modify2=OrderModify(OrderTicket(), OrderOpenPrice(),
Ask + TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT), OrderTakeProfit(), Red);
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
if (trail) trail();
double MyPoint=Point;
if(Digits==3 || Digits==5) MyPoint=Point*10;
//----
if(IsNewCandle())
{
trenddirection(); //find trend direction
logic(); //apply indicator logic
Lot_Volume(); //calc lotsize
buyorsell(); //trade - buy or sell
return(0);
}
return(0);
}
//+------------------------------------------------------------------+
//insuring its a new candle function
//+------------------------------------------------------------------+
bool IsNewCandle()
{
static int BarsOnChart=0;
if (Bars == BarsOnChart)
return (false);
BarsOnChart = Bars;
return(true);
}
//+------------------------------------------------------------------+
//identifies the direction of the current trend
//+------------------------------------------------------------------+
bool trenddirection()
{
//----
double rsi=iRSI(_Symbol,PERIOD_CURRENT,period,appPrice,1);
bool orderOpended=false;
if(rsi<OverBought &&
iOpen(NULL,0,a)>iClose(NULL,0,b) && // Place Buy logic in if statemet
iOpen(NULL,0,c)<iClose(NULL,0,d) && // Buy logic
iOpen(NULL,0,e)<iClose(NULL,0,f)) // Buy logic
{
return(true);
}
if(rsi>OverSold &&
iOpen(NULL,0,g)<iClose(NULL,0,h) && // Place Sell logic in if satement
iOpen(NULL,0,x)>iClose(NULL,0,j) && // Sell logic
iOpen(NULL,0,k)>iClose(NULL,0,l)) // Sell logic
{
return(false);
}
return(0);
}
//+------------------------------------------------------------------+
//Applies Logic from Indicators ADX and RSI to determine if we can trade
//+------------------------------------------------------------------+
int logic()
{
double adx,rsi;
adx = iADX(Symbol(),0,adxperiod,PRICE_CLOSE,MODE_MAIN,0);
rsi = iRSI(Symbol(),0,rsiperiod,PRICE_CLOSE,0);
if(adx > adxthreshold)
{
if(rsi > rsilower && rsi < rsiupper)
{
return(1);
}
}
return(0);
}
//+------------------------------------------------------------------+
//Opens Trades
//+------------------------------------------------------------------+
int buyorsell()
{
bool trenddirectionx, logicx;
int TicketNumber;
trenddirectionx = trenddirection();
logicx = logic();
if(OrdersTotal() == 0)
{
if(trenddirectionx == 1 && logicx == 1 )
if (!IsTradeContextBusy() && IsTradeAllowed())
{
//buy
TicketNumber = OrderSend(Symbol(),OP_BUY,NR(Lot_Volume()),Ask,3,Ask-(StopLoss*pips),Ask+(TakeProfit*pips),NULL,MagicNumber,0,Green);
if( TicketNumber > 0 )
{
Print("Order placed # ", TicketNumber);
}
else
{
Print("Order Send failed, error # ", GetLastError() );
}
}
}
if(OrdersTotal() == 0)
{
if(trenddirectionx == 0 && logicx == 1 )
//sell
if (!IsTradeContextBusy() && IsTradeAllowed())
{
TicketNumber = OrderSend(Symbol(),OP_SELL,NR(Lot_Volume()),Bid,3,Bid+(StopLoss*pips),Bid-(TakeProfit*pips),NULL,MagicNumber,0,Red);
if( TicketNumber > 0 )
{
Print("Order placed # ", TicketNumber);
}
else
{
Print("Order Send failed, error # ", GetLastError() );
}
}
}
return(0);
}
//+------------------------------------------------------------------+
//Calculates Lot Size based on balance and factor
//+------------------------------------------------------------------+
double NR(double thelot)
{
double maxlots=MarketInfo(Symbol(),MODE_MAXLOT),
minilot=MarketInfo(Symbol(),MODE_MINLOT),
lstep=MarketInfo(Symbol(),MODE_LOTSTEP);
double lots=lstep*NormalizeDouble(thelot/lstep,0);
lots=MathMax(MathMin(maxlots,lots),minilot);
return (lots);
}
//+------------------------------------------------------------------+
double Lot_Volume()
{
lot=AccountBalance() * 0.01 /LotFactor ;
return(lot);
}
//+------------------------------------------------------------------+