Nous reste a voir ce que cela va donner ,le temps passant .
Code
//+------------------------------------------------------------------+
//| ETOILE SOIR MATIN GG.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"
//#property strict
//+------------------------------------------------------------------+
extern double LotFactor =85; //lotsize factor
double lot;
extern int MagicNumber=23571113;
extern string mn="ETOILE SOIR MATIN";
extern double StopLoss=0;
extern double TakeProfit=22;
extern int TrailingStop=10;
extern int Slippage=3;
extern int A4=4;
extern int A1=1;
extern int A2=2;
extern int A3=3;
int ras;
double TP=0,SL=0,TR;
extern int Start_Time = 7; // Time to allow trading to start ( hours of 24 hr clock ) 0 for both disables
extern int Finish_Time = 22; // Time to stop trading ( hours of 24 hr clock ) 0 for both disables
//+------------------------------------------------------------------+
//| 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 start function
//+------------------------------------------------------------------+
int start()
{
if(TimeHour(TimeCurrent())>=Start_Time && TimeHour(TimeCurrent())<=Finish_Time )return(0);
double MyPoint=Point;
if(Digits==3 || Digits==5) MyPoint=Point*10;
double TheStopLoss=0;
double TheTakeProfit=0;
if( TotalOrdersCount()==0 )
{
int result=0;
if (Open[A4]>Close[A4]&&Close[A4]>Open[A1]&&Open[A4]>Close[A1]&&Open[A2]<Open[A3]&&Open[A2]<Close[A3]&&Close[A2]<Open[A3]&&Close[A2]<Close[A3]&&Open[A3]<Close[A3]) // Here is your open Buy rule
{
if (!IsTradeContextBusy() && IsTradeAllowed())
result=OrderSend(Symbol(),OP_BUY, NR(Lot_Volume()),Ask,Slippage,0,0,"ETOILE SOIR MATIN",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);
}
if (Open[A4]<Close[A4]&&Close[A4]<Open[A1]&&Open[A4]<Close[A1]&&Open[A2]>Open[A3]&&Open[A2]>Close[A3]&&Close[A2]>Open[A3]&&Close[A2]>Close[A3]&&Open[A3]>Close[A3]) // Here is your open Sell rule
{
if (!IsTradeContextBusy() && IsTradeAllowed())
result=OrderSend(Symbol(),OP_SELL, NR(Lot_Volume()),Bid,Slippage,0,0,"ETOILE SOIR MATIN",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)
{
bool modif3= 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))
{
bool modif4=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);
}
//+------------------------------------------------------------------+
//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 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);
}
}
}
*/