On est ici avec un capital de 250 €.....avec un capital plus conséquent ,on aurait beaucoup plus de trades.
Par exemple ,avec 2000 € on obtient une plus value de 1496.50 € avec 380 trades.
[ //+------------------------------------------------------------------+
//| RENGOU V4 1 MN CAC 40.mq4 |
//| QPG |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
//
#property copyright "QPG"
#property link "https://www.mql5.com"
#property version "1.00"
//#property strict
//+------------------------------------------------------------------+
extern int MagicNumber=18012019;
double lot;
double StopLoss=0;
double TakeProfit=0;
int TrailingStop=0;
extern int Slippage=3;
double point = MarketInfo(Symbol(), MODE_POINT);
int spread = MarketInfo(Symbol(), MODE_SPREAD);
extern int size = 140;
extern int shiftOpenBuy =4;
extern int shiftCloseBuy =4;
extern int shiftOpenSell =3;
extern int shiftCloseSell =3;
extern double LotFactor =20; //lotsize factor
int Amount = 250;
int LockDown = 310;
extern int Start_Hour = 1;
extern int End_Hour = 23;
extern string Name_EA = " RENGOU EURUSD 1MN V.4.mq4";
extern bool TrailingStop_ = true;
extern string tp="TP IN MONEY";
extern bool Tp_in_Money = true;
extern double TP_in_money = 4;//agir sur ce levier
double pt;
int ras;
//+------------------------------------------------------------------+
// expert start function
//+------------------------------------------------------------------+
int start()
{
if(TrailingStop_)dtrailing();
if(Tp_in_Money && TP_in_money<=money()) closeall();
double MyPoint=Point;
if(Digits==3 || Digits==5) MyPoint=Point*10;
double TheStopLoss=0;
double TheTakeProfit=0;
if( TotalOrdersCount()==0 )
{
int result=0;
//+------------------------------------------------------------------+
// Here is your open buy rule
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
// Here is the beginning of your open buy rule strategy
//+------------------------------------------------------------------+
if (iOpen(Symbol(),0, shiftOpenBuy)> iClose(Symbol(),0, shiftCloseBuy)+ (size + spread)*point)
//+------------------------------------------------------------------+
// Here is the end of your buy rule strategy
//+------------------------------------------------------------------+
if (!IsTradeContextBusy() && IsTradeAllowed())
{
result=OrderSend(Symbol(),OP_BUY, NR(Lot_Volume()),Ask,Slippage,0,0,"EA MODEL",MagicNumber,0,Blue);
if(result>0)
{
TheStopLoss=0;
TheTakeProfit=0;
if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
if(OrderSelect(result,SELECT_BY_TICKET))
bool modif1=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
}
return(0);
}
//+------------------------------------------------------------------+
// Here is your open sell rule
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
// Here is the beginning of your open sell rule strategy
//+------------------------------------------------------------------+
if ( iOpen(Symbol(),0, shiftOpenSell)< iClose(Symbol(),0, shiftCloseSell)- (size + spread)*point)
//+------------------------------------------------------------------+
// Here is the end of your sell rule strategy
//+------------------------------------------------------------------+
if (!IsTradeContextBusy() && IsTradeAllowed())
{
result=OrderSend(Symbol(),OP_SELL, NR(Lot_Volume()),Bid,Slippage,0,0,"EA MODEL",MagicNumber,0,Red);
if(result>0)
{
TheStopLoss=0;
TheTakeProfit=0;
if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
if(OrderSelect(result,SELECT_BY_TICKET))
bool modif2=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
}
return(0);
}
}
for(int cnt=0;cnt<OrdersTotal();cnt++)
{
if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
if(OrderType()<=OP_SELL &&
OrderSymbol()==Symbol() &&
OrderMagicNumber()==MagicNumber
)
{
if(OrderType()==OP_BUY)
{
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)
{
if(OrderStopLoss()<Bid-MyPoint*TrailingStop)
{
if(OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green))
return(0);
}
}
}
}
else
{
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))
{
if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0))
{
if(OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red))
return(0);
}
}
}
}
}
}
return(0);
}
int TotalOrdersCount()
{
int result=0;
for(int i=0;i<OrdersTotal();i++)
{
if (OrderSelect(i,SELECT_BY_POS ,MODE_TRADES))
if (OrderMagicNumber()==MagicNumber) result++;
}
return (result);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//*********************************************************************
//+------------------------------------------------------------------+
int Hour_trade()
{
bool trade=false;
if(Start_Hour>End_Hour)
{
if(Hour()>=Start_Hour || Hour()<End_Hour) trade=true;
}
else
if(Hour()>=Start_Hour && Hour()<End_Hour) trade=true;
return (trade);
}
//+------------------------------------------------------------------+
//
//+------------------------------------------------------------------+
int totalorder(int tipe)
{
int total=0;
for(int i=0; i<OrdersTotal(); i++)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber || OrderType()!=tipe) continue;
total++;
}
return(total);
}
//+------------------------------------------------------------------+
//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);
}
//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+
void dtrailing()
{
int i,r;double tpn;
for(i=0; i<OrdersTotal(); i++)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber) continue;
tpn=OrderTakeProfit();
if(OrderType()==OP_BUY)
{
if(Bid-OrderOpenPrice()>pt*TrailingStop)
{
if((OrderStopLoss()<Bid-pt*TrailingStop) || (OrderStopLoss()==0))
{
if(tpn) r=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-pt*TrailingStop,OrderTakeProfit(),0,Green);
}
}
}
if(OrderType()==OP_SELL)
{
if((OrderOpenPrice()-Ask)>(pt*TrailingStop))
{
if(OrderStopLoss()>(Ask+pt*TrailingStop) || (OrderStopLoss()==0))
{
if(tpn) r=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+pt*TrailingStop,OrderTakeProfit(),0,Red);
}
}
}
}
}
//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+
void closeall()
{
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber) continue;
if(OrderType()>1) ras=OrderDelete(OrderTicket());
else
{
if(OrderType()==0) ras=OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE);
else ras=OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);
}
}
}
//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+
double money()
{
double dp=0;
int i;
for(i=0; i<OrdersTotal(); i++)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber) continue;
dp+=OrderProfit();
}
return(dp);
}
//+------------------------------------------------------------------+
bool CheckMoneyForTrade(string symb,double lots,int type)
{
double free_margin=AccountFreeMarginCheck(symb,type, lots);
//-- if there is not enough money
if(free_margin<0)
{
string oper=(type==OP_BUY)? "Buy":"Sell";
//fPrint("Not enough money for ", oper," ",lots, " ", symb, " Error code=",GetLastError());
return(false);
}
//--- checking successful
return(true);
}
//---------------------------------------------------------------------------
int CheckForClose()
{
if(getProfit()>=Amount){CloseAll();}
if(LockDown>0)
{
for(int TradeNumber = OrdersTotal(); TradeNumber >= 0; TradeNumber--)
{
if (OrderSelect(TradeNumber, SELECT_BY_POS, MODE_TRADES)&&(LockDown>0))
{ int Pos=OrderType();
if((Pos==OP_BUY)&&(Bid-OrderOpenPrice()>Point*LockDown)&&(OrderStopLoss() == 0))
{bool modif1=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point,OrderTakeProfit(),0,CLR_NONE);}
if((Pos==OP_SELL)&&(OrderOpenPrice()-Ask>Point*LockDown)&&(OrderStopLoss() == 0))
{bool modif2=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Point,OrderTakeProfit(),0,CLR_NONE);}
}
}
}
return(0);
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
double getProfit()
{
double Profit = 0;
for (int TradeNumber = OrdersTotal(); TradeNumber >= 0; TradeNumber--)
{
if (OrderSelect(TradeNumber, SELECT_BY_POS, MODE_TRADES))
Profit = Profit + OrderProfit() + OrderSwap();
}
return (Profit);
}
//---------------------------------------------------------------------------
void CloseAll()
{
bool Result;
int i,Pos,Error;
int Total=OrdersTotal();
if(Total>0)
{
for(i=Total-1; i>=0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
Pos=OrderType();
if(Pos==OP_BUY)
{Result=OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, CLR_NONE);}
if(Pos==OP_SELL)
{Result=OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, CLR_NONE);}
if((Pos==OP_BUYSTOP)||(Pos==OP_SELLSTOP)||(Pos==OP_BUYLIMIT)||(Pos==OP_SELLLIMIT))
{Result=OrderDelete(OrderTicket(), CLR_NONE);}
//-----------------------
if(Result!=true)
{
Error=GetLastError();
Print("LastError = ",Error);
}
else Error=0;
//-----------------------
}
}
}
} /]
Par exemple ,avec 2000 € on obtient une plus value de 1496.50 € avec 380 trades.
[ //+------------------------------------------------------------------+
//| RENGOU V4 1 MN CAC 40.mq4 |
//| QPG |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
//
#property copyright "QPG"
#property link "https://www.mql5.com"
#property version "1.00"
//#property strict
//+------------------------------------------------------------------+
extern int MagicNumber=18012019;
double lot;
double StopLoss=0;
double TakeProfit=0;
int TrailingStop=0;
extern int Slippage=3;
double point = MarketInfo(Symbol(), MODE_POINT);
int spread = MarketInfo(Symbol(), MODE_SPREAD);
extern int size = 140;
extern int shiftOpenBuy =4;
extern int shiftCloseBuy =4;
extern int shiftOpenSell =3;
extern int shiftCloseSell =3;
extern double LotFactor =20; //lotsize factor
int Amount = 250;
int LockDown = 310;
extern int Start_Hour = 1;
extern int End_Hour = 23;
extern string Name_EA = " RENGOU EURUSD 1MN V.4.mq4";
extern bool TrailingStop_ = true;
extern string tp="TP IN MONEY";
extern bool Tp_in_Money = true;
extern double TP_in_money = 4;//agir sur ce levier
double pt;
int ras;
//+------------------------------------------------------------------+
// expert start function
//+------------------------------------------------------------------+
int start()
{
if(TrailingStop_)dtrailing();
if(Tp_in_Money && TP_in_money<=money()) closeall();
double MyPoint=Point;
if(Digits==3 || Digits==5) MyPoint=Point*10;
double TheStopLoss=0;
double TheTakeProfit=0;
if( TotalOrdersCount()==0 )
{
int result=0;
//+------------------------------------------------------------------+
// Here is your open buy rule
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
// Here is the beginning of your open buy rule strategy
//+------------------------------------------------------------------+
if (iOpen(Symbol(),0, shiftOpenBuy)> iClose(Symbol(),0, shiftCloseBuy)+ (size + spread)*point)
//+------------------------------------------------------------------+
// Here is the end of your buy rule strategy
//+------------------------------------------------------------------+
if (!IsTradeContextBusy() && IsTradeAllowed())
{
result=OrderSend(Symbol(),OP_BUY, NR(Lot_Volume()),Ask,Slippage,0,0,"EA MODEL",MagicNumber,0,Blue);
if(result>0)
{
TheStopLoss=0;
TheTakeProfit=0;
if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
if(OrderSelect(result,SELECT_BY_TICKET))
bool modif1=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
}
return(0);
}
//+------------------------------------------------------------------+
// Here is your open sell rule
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
// Here is the beginning of your open sell rule strategy
//+------------------------------------------------------------------+
if ( iOpen(Symbol(),0, shiftOpenSell)< iClose(Symbol(),0, shiftCloseSell)- (size + spread)*point)
//+------------------------------------------------------------------+
// Here is the end of your sell rule strategy
//+------------------------------------------------------------------+
if (!IsTradeContextBusy() && IsTradeAllowed())
{
result=OrderSend(Symbol(),OP_SELL, NR(Lot_Volume()),Bid,Slippage,0,0,"EA MODEL",MagicNumber,0,Red);
if(result>0)
{
TheStopLoss=0;
TheTakeProfit=0;
if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
if(OrderSelect(result,SELECT_BY_TICKET))
bool modif2=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
}
return(0);
}
}
for(int cnt=0;cnt<OrdersTotal();cnt++)
{
if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
if(OrderType()<=OP_SELL &&
OrderSymbol()==Symbol() &&
OrderMagicNumber()==MagicNumber
)
{
if(OrderType()==OP_BUY)
{
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)
{
if(OrderStopLoss()<Bid-MyPoint*TrailingStop)
{
if(OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green))
return(0);
}
}
}
}
else
{
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))
{
if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0))
{
if(OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red))
return(0);
}
}
}
}
}
}
return(0);
}
int TotalOrdersCount()
{
int result=0;
for(int i=0;i<OrdersTotal();i++)
{
if (OrderSelect(i,SELECT_BY_POS ,MODE_TRADES))
if (OrderMagicNumber()==MagicNumber) result++;
}
return (result);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//*********************************************************************
//+------------------------------------------------------------------+
int Hour_trade()
{
bool trade=false;
if(Start_Hour>End_Hour)
{
if(Hour()>=Start_Hour || Hour()<End_Hour) trade=true;
}
else
if(Hour()>=Start_Hour && Hour()<End_Hour) trade=true;
return (trade);
}
//+------------------------------------------------------------------+
//
//+------------------------------------------------------------------+
int totalorder(int tipe)
{
int total=0;
for(int i=0; i<OrdersTotal(); i++)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber || OrderType()!=tipe) continue;
total++;
}
return(total);
}
//+------------------------------------------------------------------+
//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);
}
//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+
void dtrailing()
{
int i,r;double tpn;
for(i=0; i<OrdersTotal(); i++)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber) continue;
tpn=OrderTakeProfit();
if(OrderType()==OP_BUY)
{
if(Bid-OrderOpenPrice()>pt*TrailingStop)
{
if((OrderStopLoss()<Bid-pt*TrailingStop) || (OrderStopLoss()==0))
{
if(tpn) r=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-pt*TrailingStop,OrderTakeProfit(),0,Green);
}
}
}
if(OrderType()==OP_SELL)
{
if((OrderOpenPrice()-Ask)>(pt*TrailingStop))
{
if(OrderStopLoss()>(Ask+pt*TrailingStop) || (OrderStopLoss()==0))
{
if(tpn) r=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+pt*TrailingStop,OrderTakeProfit(),0,Red);
}
}
}
}
}
//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+
void closeall()
{
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber) continue;
if(OrderType()>1) ras=OrderDelete(OrderTicket());
else
{
if(OrderType()==0) ras=OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE);
else ras=OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);
}
}
}
//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+
double money()
{
double dp=0;
int i;
for(i=0; i<OrdersTotal(); i++)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber) continue;
dp+=OrderProfit();
}
return(dp);
}
//+------------------------------------------------------------------+
bool CheckMoneyForTrade(string symb,double lots,int type)
{
double free_margin=AccountFreeMarginCheck(symb,type, lots);
//-- if there is not enough money
if(free_margin<0)
{
string oper=(type==OP_BUY)? "Buy":"Sell";
//fPrint("Not enough money for ", oper," ",lots, " ", symb, " Error code=",GetLastError());
return(false);
}
//--- checking successful
return(true);
}
//---------------------------------------------------------------------------
int CheckForClose()
{
if(getProfit()>=Amount){CloseAll();}
if(LockDown>0)
{
for(int TradeNumber = OrdersTotal(); TradeNumber >= 0; TradeNumber--)
{
if (OrderSelect(TradeNumber, SELECT_BY_POS, MODE_TRADES)&&(LockDown>0))
{ int Pos=OrderType();
if((Pos==OP_BUY)&&(Bid-OrderOpenPrice()>Point*LockDown)&&(OrderStopLoss() == 0))
{bool modif1=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point,OrderTakeProfit(),0,CLR_NONE);}
if((Pos==OP_SELL)&&(OrderOpenPrice()-Ask>Point*LockDown)&&(OrderStopLoss() == 0))
{bool modif2=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Point,OrderTakeProfit(),0,CLR_NONE);}
}
}
}
return(0);
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
double getProfit()
{
double Profit = 0;
for (int TradeNumber = OrdersTotal(); TradeNumber >= 0; TradeNumber--)
{
if (OrderSelect(TradeNumber, SELECT_BY_POS, MODE_TRADES))
Profit = Profit + OrderProfit() + OrderSwap();
}
return (Profit);
}
//---------------------------------------------------------------------------
void CloseAll()
{
bool Result;
int i,Pos,Error;
int Total=OrdersTotal();
if(Total>0)
{
for(i=Total-1; i>=0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
Pos=OrderType();
if(Pos==OP_BUY)
{Result=OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, CLR_NONE);}
if(Pos==OP_SELL)
{Result=OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, CLR_NONE);}
if((Pos==OP_BUYSTOP)||(Pos==OP_SELLSTOP)||(Pos==OP_BUYLIMIT)||(Pos==OP_SELLLIMIT))
{Result=OrderDelete(OrderTicket(), CLR_NONE);}
//-----------------------
if(Result!=true)
{
Error=GetLastError();
Print("LastError = ",Error);
}
else Error=0;
//-----------------------
}
}
}
} /]