Spread de 20 pour mettre le robot en condition difficile
Capital de départ 1500 $...en dessous de ce montant ,on observe une baisse de la courbe en final de backtest.
Je suis désolé pour la qualité du modelage mais ma plateforme ne me permet pas de faire mieux
Capital de départ 1500 $...en dessous de ce montant ,on observe une baisse de la courbe en final de backtest.
Je suis désolé pour la qualité du modelage mais ma plateforme ne me permet pas de faire mieux
Code
//+------------------------------------------------------------------+
//| MODULOSTOP GG SELL V2.mq4 |
//| Copyright 2019, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| MODULO LG SH TP SL BREAKEVEN.mq4 |
//| Copyright 2019, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
int MagicNumber=13102019; //magic
extern string Name_EA = "MODULOSTOP GG SELL V2";
double point = MarketInfo(Symbol(), MODE_POINT);
int spread = MarketInfo(Symbol(), MODE_SPREAD);
extern int size = 0;
int shiftOpenBuy =0;
int shiftCloseBuy =1;
int shiftOpenSell =0;
int shiftCloseSell =1;
double LotFactorLONG=54 ; //
extern double LotFactorSHORT = 130; //lotsize factor
double MultiplierLONG = 0.1; //
extern double MultiplierSHORT = 0.7; //from 0.04...to 0.09
extern int long_courtLONG=1; // 0 = Long & 1 = Court
extern int long_courtSHORT=1; // 0 = Long & 1 = Court
int gainLONG=32; // no comment ;)
extern int gainSHORT=0; // no comment ;)
int ecartLONG=0;// Ecart : 150, 1000, ou 1500 selon les paires..
extern int ecartSHORT=18;// Ecart : 150, 1000, ou 1500 selon les paires
extern bool trail=false;
extern double TrailingStop=13;
double pips = 0.00001; //leave as default for 5 digit brokers
int stopOK = 0; // ne pas modifier
int sendOK = 0; // ne pas modifier
extern int hour=23;
extern int c=0;
double LotSizeLONG; //lotsize
double SizeLotLONG;
double LotSizeSHORT; //lotsize
double SizeLotSHORT;
extern int profit=20;
extern int stop =32;
extern int Slippage =0;
//----
double TP=0,SL=0,TR;
//+------------------------------------------------------------------+
//| Hidden StopLoss Calculations |
//+------------------------------------------------------------------+
void StopLoss()
{
double MyPoint=Point;
if(Digits==3 || Digits==5) MyPoint=Point*10;
TP=profit*MyPoint;
SL=stop*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,clrGold);
if(OrderType()==OP_SELL)
bool OrdClL=OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,clrGold);
}
}
}
}
//+------------------------------------------------------------------+
//| Trailing Stoploss après Breakeven |
//+------------------------------------------------------------------+
void trail()
{
for (int i = OrdersTotal()-1; i >= 0; i --)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY)
{
if(Bid - OrderOpenPrice() > TrailingStop *10* MarketInfo(OrderSymbol(),MODE_POINT))
{
if(((OrderStopLoss() < Bid - TrailingStop *10* MarketInfo(OrderSymbol(), MODE_POINT))&& ((Bid-OrderOpenPrice())>(Point*TrailingStop)))||
(OrderStopLoss()==0))
{
bool modify1=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*10*MarketInfo(OrderSymbol(),MODE_POINT),OrderTakeProfit(),clrGold);
}
}
} else if(OrderType()==OP_SELL) {
if(OrderOpenPrice()-Ask>TrailingStop*10*MarketInfo(OrderSymbol(),MODE_POINT))
{
if(((OrderStopLoss()>Ask+TrailingStop*10*MarketInfo(OrderSymbol(),MODE_POINT))&& ((OrderOpenPrice()-Ask)>(Point*TrailingStop)))||
(OrderStopLoss()==0))
{
bool modify2=OrderModify(OrderTicket(),OrderOpenPrice(),
Ask+TrailingStop*10*MarketInfo(OrderSymbol(),MODE_POINT),OrderTakeProfit(),clrGold);
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| 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())
{
Lot_Volume(); //calc lotsize
return(0);
}
//MODIF***********
if (!IsTradeContextBusy() && IsTradeAllowed())
if(c==0){
if(PERIOD_M5==true)
if(PERIOD_H1==true)
if (((iOpen(Symbol(),0, shiftOpenBuy)> iClose(Symbol(),0, shiftCloseBuy)+ (size + spread)*point))
&&(Bid >iOpen(NULL,PERIOD_M5,0)
&&(Bid >iOpen(NULL,PERIOD_H1,0))))
if(OrderSend(Symbol(), OP_BUY, SizeLotLONG, Ask, 0, Ask - (stop * Point), Ask + (profit * Point), "MODULOSTOP GG SELL V2",MagicNumber,0,clrGold))c=1;}
//+------------------------------------------------------------------+
// Here is your open buy rule
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
// Here is the beginning of your open buy rule strategy
//+------------------------------------------------------------------+
// double Price=(Ask+Bid)/2;
if(PERIOD_M5==true)
if(PERIOD_H1==true)
if (((iOpen(Symbol(),0, shiftOpenBuy)> iClose(Symbol(),0, shiftCloseBuy)+ (size + spread)*point))
&&(Bid >iOpen(NULL,PERIOD_M5,0)
&&(Bid >iOpen(NULL,PERIOD_H1,0))))
//+------------------------------------------------------------------+
// Here is the end of your buy rule strategy
//+------------------------------------------------------------------+
if (!IsTradeContextBusy() && IsTradeAllowed())
if(c==0){if(OrderSend(Symbol(), OP_BUY, SizeLotSHORT, Ask, 0, Ask - (stop * Point), Ask + (profit * Point), "MODULOSTOP GG SELL V2",MagicNumber,0,clrGold))c=1;}
//
//MODIF***********
Comment(AccountEquity() - AccountBalance());
int type = OrderType();
int type2 = OrderType();
if (Hour()==1 && Minute()==1 && Seconds()==1 && sendOK==0)
{
sendOK=1;stopOK=0;
//+------------------------------------------------------------------+
if(long_courtLONG==1)
if (!IsTradeContextBusy() && IsTradeAllowed())
{
int ticket5= OrderSend(Symbol(), OP_SELLSTOP, LotSizeLONG, Bid-ecartLONG*pips, 0, 0, 0, "MODULOSTOP GG SELL V2",MagicNumber,0,clrGold);
if (!IsTradeContextBusy() && IsTradeAllowed())
if(long_courtSHORT==1)
{
int ticket6= OrderSend(Symbol(), OP_SELLSTOP, LotSizeSHORT, Bid-ecartSHORT*pips, 0, 0, 0, "MODULOSTOP GG SELL V2",MagicNumber,0,clrGold);
if(ticket5<0)
{
Print("OrderSend failed with error #",GetLastError());
}
else
Print("OrderSend placed successfully");
}
if(ticket6<0)
{
Print("OrderSend failed with error #",GetLastError());
}
else
Print("OrderSend placed successfully");
}
//+------------------------------------------------------------------+
if(long_courtLONG==0)
if (!IsTradeContextBusy() && IsTradeAllowed())
{
int ticket1= OrderSend(Symbol(), OP_BUYSTOP, LotSizeLONG, Ask+ecartLONG*pips, 0, 0, 0, "MODULO LONG SHORT TP SL TS",MagicNumber,0,clrGold);
if(long_courtSHORT==0)
if (!IsTradeContextBusy() && IsTradeAllowed())
{
int ticket2= OrderSend(Symbol(), OP_BUYSTOP, LotSizeSHORT, Ask+ecartSHORT*pips, 0, 0, 0, "MODULO LONG SHORT TP SL TS",MagicNumber,0,clrGold);
if(ticket1<0)
{
Print("OrderSend failed with error #",GetLastError());
}
else
Print("OrderSend placed successfully");
}
if(ticket2<0)
{
Print("OrderSend failed with error #",GetLastError());
}
else
Print("OrderSend placed successfully");
}
//+------------------------------------------------------------------+
}
if (Hour()>=hour && stopOK==0)
{
stopOK=1;sendOK=0;
int u = OrdersTotal() - 1;
while (u >= 0)
{
if(OrderSelect(u, SELECT_BY_POS))
if (type == OP_SELLSTOP || type == OP_BUYSTOP)
{
bool modif3= OrderDelete(OrderTicket());
}
u -= 1;
}
}
if (AccountEquity()>= AccountBalance()+ gainLONG)
if (AccountEquity()>= AccountBalance()+ gainSHORT)
{
int w = OrdersTotal() - 1;
while (w >= 0)
{
if(OrderSelect(w, SELECT_BY_POS))
{
bool modif1= OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID),2);
bool modif2= OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK),2);
}
w -= 1;
}
//MODIF***********
if (!IsTradeContextBusy() && IsTradeAllowed())
int ticket3=OrderSend(Symbol(), OP_BUY, SizeLotLONG, Ask, 0, Ask - (stop * Point), Ask + (profit * Point), "MODULO LONG SHORT TP SL TS",MagicNumber,0,clrGold);
//(OrderSend(Symbol(), OP_BUY, SizeLotLONG, Ask, 0, Ask - (stop1 * Point), Ask + (profit1 * Point), 0, "MODULO VERSION 4 LONG SHORT")
int ticket4=OrderSend(Symbol(), OP_BUY, SizeLotSHORT, Ask, 0, Ask - (stop * Point), Ask + (profit * Point), "MODULO LONG SHORT TP SL TS",MagicNumber,0,clrGold);
//--- place market order to buy 1 lot
if(ticket3<0)
{
Print("OrderSend failed with error #",GetLastError());
}
else
Print("OrderSend placed successfully");
if(ticket4<0)
{
Print("OrderSend failed with error #",GetLastError());
}
else
Print("OrderSend placed successfully");
//MODIF***********
}
return(0);
}
//+------------------------------------------------------------------+
//insuring its a new candle function
//+------------------------------------------------------------------+
bool IsNewCandle()
{
static int BarsOnChart=0;
if (Bars == BarsOnChart)
return (false);
BarsOnChart = Bars;
return(true);
}
//+------------------------------------------------------------------+
//Calculates Lot Size based on balance and factor
//+------------------------------------------------------------------+
double Lot_Volume()
{
LotSizeLONG=AccountBalance() * 0.01 /LotFactorLONG ;
SizeLotLONG=LotSizeLONG*MultiplierLONG;
return(LotSizeLONG);
return(SizeLotLONG);
LotSizeSHORT=AccountBalance() * 0.01 /LotFactorSHORT ;
SizeLotSHORT=LotSizeSHORT*MultiplierSHORT;
return(LotSizeSHORT);
return(SizeLotSHORT);
}
//+------------------------------------------------------------------+