Attention cet Ea fonctionne en Daily, tel qu'il est paramétré….le paramétrage pourrait être encore optimisé pour de meilleurs résultats…..merci de l'améliorer .
Code
//+------------------------------------------------------------------+
//| QPG QUICK OPEN BUY OR SELL.mq4 |
//| QPG |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| EURUSD DAILY |
//+------------------------------------------------------------------+
#property copyright "QPG"
#property link "https://www.mql5.com"
#property version "1.00"
//#property strict
extern string ob="OPEN BUY";
extern double delta_open_buy=15;
extern int OB1a=20;
extern int OB0a=15;
extern int OB1b=4;
extern int OB0b=1;
extern string os="OPEN SELL";
extern double delta_open_sell=25;
extern int OS0a=13;
extern int OS1a=17;
extern int OS0b=13;
extern int OS1b=16;
extern string Name_EA = "Hedge Average";
extern bool Trade_buy = true;
extern bool Trade_sell = true;
extern int Start_Hour = 1;
extern int End_Hour = 23;
extern bool Tp_in_Money = true;
extern double TP_in_money = 3;
extern int TP = 20;
extern int SL = 110;
extern int Max_order = 10;
//extern double Lots = 0.12;
extern string mm="MONEY MANAGEMENT";
extern double LotFactor = 10; //lotsize factor
extern bool TrailingStop_ = true;
extern int TrailingStop = 20;
extern int Magic = 76;
extern string re="REGULATOR";
extern int adxperiod =14;
extern int adxthreshold =27;
extern int rsiperiod = 2; //rsi period
extern int rsiupper = 80; //rsi upper bound, wont buy above this value
extern int rsilower = 20; //rsi lower bound, wont sell below this value
double LotSize;
double slb,tpb,sls,tps,pt;
int ras,wt,wk,ticketb,tickets;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
if(Digits==3 || Digits==5) pt=10*Point; else pt=Point;
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
if(TrailingStop_)dtrailing();
if(Tp_in_Money && TP_in_money<=money()) closeall();
//----
double booster = Volume[1]> Volume[0]
&&(iADX(Symbol(),0,adxperiod,PRICE_CLOSE,MODE_MAIN,0)>adxthreshold )
&& iRSI(Symbol(),0,rsiperiod,PRICE_CLOSE,0)>rsilower && iRSI(Symbol(),0,rsiperiod,PRICE_CLOSE,0)<rsiupper;
int signal;
if
((Ask>Bid*Point)&&(Open[OB1a]>Open[OB0a])
&&((Open[OB1b]-Open[OB0b])>delta_open_buy*Point)
&&(booster) ) signal=1;// open buy
if
((Bid>Ask*Point)&&(Close[OS0a]>Close[OS1a])
&&((Close[OS0b]-Close[OS1b])>delta_open_sell*Point)
&&(booster) ) signal=2;// open sell
if(Hour_trade()==1)
{
if(SL==0)slb=0;else slb=Ask-SL*pt;
if(SL==0)sls=0;else sls=Bid+SL*pt;
if(TP==0)tpb=0;else tpb=Ask+TP*pt;
if(TP==0)tps=0;else tps=Bid-TP*pt;
if(totalorder(0)<Max_order && CheckMoneyForTrade(Symbol(), NR(Lot_Volume()), OP_BUY)==True && Trade_buy && signal==1 && wt!=Time[0])
{
ticketb=OrderSend(Symbol(),OP_BUY,NR(Lot_Volume()),Ask,3,slb,tpb,Name_EA,Magic,0,Blue);
if(ticketb>0) wt=Time[0];
}
if(totalorder(1)<Max_order && CheckMoneyForTrade(Symbol(), NR(Lot_Volume()), OP_SELL)==True && Trade_sell && signal==2 && wk!=Time[0])
{
tickets=OrderSend(Symbol(),OP_SELL,NR(Lot_Volume()),Bid,3,sls,tps,Name_EA,Magic,0,Red);
if(tickets>0) wk=Time[0];
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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()!=Magic || OrderType()!=tipe) continue;
total++;
}
return(total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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()
{
double lot;
if (AccountBalance()>=50) lot=0.02;
if (AccountBalance()>=75) lot=0.03;
if (AccountBalance()>=100) lot=0.04;
if (AccountBalance()>=125) lot=0.05;
if (AccountBalance()>=150) lot=0.06;
if (AccountBalance()>=175) lot=0.07;
if (AccountBalance()>=200) lot=0.08;
if (AccountBalance()>=225) lot=0.09;
if (AccountBalance()>=250) lot=0.1;
if (AccountBalance()>=275) lot=0.11;
if (AccountBalance()>=300) lot=0.12;
if (AccountBalance()>=325) lot=0.13;
if (AccountBalance()>=350) lot=0.14;
if (AccountBalance()>=375) lot=0.15;
if (AccountBalance()>=400) lot=0.16;
if (AccountBalance()>=425) lot=0.17;
if (AccountBalance()>=450) lot=0.18;
if (AccountBalance()>=475) lot=0.19;
if (AccountBalance()>=500) lot=0.2;
if (AccountBalance()>=525) lot=0.21;
if (AccountBalance()>=550) lot=0.22;
if (AccountBalance()>=575) lot=0.23;
if (AccountBalance()>=600) lot=0.24;
if (AccountBalance()>=625) lot=0.25;
if (AccountBalance()>=650) lot=0.26;
if (AccountBalance()>=675) lot=0.27;
if (AccountBalance()>=700) lot=0.28;
if (AccountBalance()>=725) lot=0.29;
if (AccountBalance()>=750) lot=0.30;
if (AccountBalance()>=800) lot=0.32;
if (AccountBalance()>=825) lot=0.33;
if (AccountBalance()>=850) lot=0.34;
if (AccountBalance()>=875) lot=0.35;
if (AccountBalance()>=900) lot=0.36;
if (AccountBalance()>=925) lot=0.37;
if (AccountBalance()>=950) lot=0.38;
if (AccountBalance()>=975) lot=0.39;
if (AccountBalance()>=1000) lot=0.4;
if (AccountBalance()>=1025) lot=0.41;
if (AccountBalance()>=1050) lot=0.42;
if (AccountBalance()>=1075) lot=0.43;
if (AccountBalance()>=1100) lot=0.44;
if (AccountBalance()>=1125) lot=0.45;
if (AccountBalance()>=1150) lot=0.46;
if (AccountBalance()>=1175) lot=0.47;
if (AccountBalance()>=1200) lot=0.48;
if (AccountBalance()>=1225) lot=0.49;
if (AccountBalance()>=1250) lot=0.5;
if (AccountBalance()>=1275) lot=0.51;
if (AccountBalance()>=1300) lot=0.52;
if (AccountBalance()>=1325) lot=0.53;
if (AccountBalance()>=1350) lot=0.54;
if (AccountBalance()>=1350) lot=0.55;
if (AccountBalance()>=1400) lot=0.56;
if (AccountBalance()>=1450) lot=0.58;
if (AccountBalance()>=1500) lot=0.6;
if (AccountBalance()>=1550) lot=0.62;
if (AccountBalance()>=1600) lot=0.64;
if (AccountBalance()>=1650) lot=0.66;
if (AccountBalance()>=1700) lot=0.68;
if (AccountBalance()>=1750) lot=0.7;
if (AccountBalance()>=1800) lot=0.72;
if (AccountBalance()>=1850) lot=0.74;
if (AccountBalance()>=1900) lot=0.76;
if (AccountBalance()>=1950) lot=0.78;
if (AccountBalance()>=2000) lot=0.8;
if (AccountBalance()>=2025) lot=0.81;
if (AccountBalance()>=2050) lot=0.82;
if (AccountBalance()>=2075) lot=0.83;
if (AccountBalance()>=2100) lot=0.84;
if (AccountBalance()>=2150) lot=0.86;
if (AccountBalance()>=2175) lot=0.87;
if (AccountBalance()>=2200) lot=0.88;
if (AccountBalance()>=2225) lot=0.89;
if (AccountBalance()>=2250) lot=0.9;
if (AccountBalance()>=2275) lot=0.91;
if (AccountBalance()>=2300) lot=0.92;
if (AccountBalance()>=2350) lot=0.94;
if (AccountBalance()>=2400) lot=0.96;
if (AccountBalance()>=2450) lot=0.98;
if (AccountBalance()>=2500) lot=1.0;
if (AccountBalance()>=2550) lot=1.02;
if (AccountBalance()>=2600) lot=1.04;
if (AccountBalance()>=2700) lot=1.08;
if (AccountBalance()>=2800) lot=1.12;
if (AccountBalance()>=2900) lot=0.16;
if (AccountBalance()>=3000) lot=1.2;
if (AccountBalance()>=3100) lot=1.24;
if (AccountBalance()>=3200) lot=1.28;
if (AccountBalance()>=3300) lot=1.32;
if (AccountBalance()>=3400) lot=1.36;
if (AccountBalance()>=3500) lot=1.4;
if (AccountBalance()>=4000) lot=1.6;
if (AccountBalance()>=4500) lot=1.8;
if (AccountBalance()>=5000) lot=2.0;
if (AccountBalance()>=5500) lot=2.2;
if (AccountBalance()>=6000) lot=2.4;
if (AccountBalance()>=6500) lot=2.6;
if (AccountBalance()>=7000) lot=2.8;
if (AccountBalance()>=7500) lot=3;
if (AccountBalance()>=8000) lot=3.2;
if (AccountBalance()>=8500) lot=3.4;
if (AccountBalance()>=9000) lot=3.6;
if (AccountBalance()>=9500) lot=3.8;
if (AccountBalance()>=10000) lot=4.0;
if (AccountBalance()>=10100) lot=4.04;
if (AccountBalance()>=10200) lot=4.08;
if (AccountBalance()>=10300) lot=4.12;
if (AccountBalance()>=10400) lot=4.16;
if (AccountBalance()>=10500) lot=4.2;
if (AccountBalance()>=10600) lot=4.26;
if (AccountBalance()>=10700) lot=4.3;
if (AccountBalance()>=10800) lot=4.34;
if (AccountBalance()>=10900) lot=4.38;
if (AccountBalance()>=11000) lot=4.4;
if (AccountBalance()>=12000) lot=4.8;
if (AccountBalance()>=13000) lot=5.2;
if (AccountBalance()>=14000) lot=5.6;
if (AccountBalance()>=15000) lot=6.0;
if (AccountBalance()>=20000) lot=8.0;
if (AccountBalance()>=30000) lot=12;
if (AccountBalance()>=40000) lot=16;
if (AccountBalance()>=50000) lot=20;
if (AccountBalance()>=60000) lot=24;
if (AccountBalance()>=70000) lot=28;
if (AccountBalance()>=80000) lot=32;
if (AccountBalance()>=90000) lot=36;
if (AccountBalance()>=100000) lot=40;
if (AccountBalance()>=200000) lot=80;
LotSize=lot/LotFactor;
return(LotSize);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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()!=Magic) 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()!=Magic) 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()!=Magic) 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);
}