Dès qu'un ordre d’achat ou de vente est passé....les ordres en attente sont supprimés.
EURUSD 1mn
EURUSD 1mn
Code
//+------------------------------------------------------------------+
//| eaxtwoependingaorders.5.volatility.mq4 |
//| Copyright 2020, 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 int MagicNumber=20100807; //magic
extern string Name_EA = "eaxtwoependingaorders .1" ;
extern double LotFactor =198; //lotsize factor
double lot;
extern int barnumber =51;
//
extern int TakeProfitBuystop = 41;
extern int TakeProfitSellstop = 42;
extern int StopLossBuystop = 60;
extern int StopLossSellstop = 20;
//
//extern int TakeProfit = 100;
//extern int StopLoss = 140;
//
extern int ecartask=6;
extern int ecartbid=8;
int last_bar = 0;
extern bool trail=true;
extern double TrailingStop=1;
input int MaxSpreadAllow = 10; // Enter Maximum allowed spread
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
double MyPoint=Point;
if(Digits==3 || Digits==5) MyPoint=Point*10;
new_del () ;
//
// if (last_bar == Bars) return(0);
//last_bar = Bars;
//
static datetime tmeBar0;
bool newBar = false;
if ( tmeBar0 != Time[0] )
{
tmeBar0 = Time[0];
newBar = true;
}
double Spread = MarketInfo(Symbol(), MODE_SPREAD); // This will Obtain broker Spread for current pair
if(Spread > 0 && Spread <= MaxSpreadAllow) // This part compares broker spread with maximum allowed spread, and refuse trade if maxSpread is exceeded
if ( OrdersTotal () == 0 )
if(AccountFreeMargin()>(1000*(AccountEquity() * 0.01 /LotFactor)))
{
double HighOfLastBars = iHigh ( Symbol (), PERIOD_M1 , iHighest ( Symbol (), PERIOD_M1 , MODE_HIGH, barnumber , 0 ));
double LowOfLastBars = iLow ( Symbol (), PERIOD_M1 , iLowest ( Symbol (), PERIOD_M1 , MODE_LOW, barnumber , 0 ));
int buystop = OrderSend(Symbol(),OP_BUYSTOP, NR(Lot_Volume()),Ask +ecartask*Point,5,LowOfLastBars-StopLossBuystop*Point,HighOfLastBars +TakeProfitBuystop*Point,"eaxtwoependingaorders .1",MagicNumber,0,clrBlue);
int sellstop = OrderSend(Symbol(),OP_SELLSTOP, NR(Lot_Volume()),Bid-ecartbid*Point,5,HighOfLastBars +StopLossSellstop*Point,LowOfLastBars-TakeProfitSellstop*Point,"eaxtwoependingaorders .1",MagicNumber,0,clrBlue);
}
return ( 0 );
}
//-------------------- ( to close pending order) ---------------
int new_del()
{
if(trail) trail();
int i,a;
int total = OrdersTotal();
string comentario,par;
for (i=total-1; i >=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if (OrderType()==OP_BUY || OrderType()==OP_SELL)
{
for (a=total-1; a >=0; a--)
{
if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES))
if(OrderType()==OP_SELLSTOP)
{
bool modify1= OrderDelete(OrderTicket());
Print("Deleting SELL_STOP"," Ordertype:",OrderType());
return(1);
}
if(OrderType()==OP_BUYSTOP)
{
bool modify2= OrderDelete(OrderTicket());
Print("Deleting BUY_STOP"," Ordertype:",OrderType());
return(1);
}
}
}
}
return ( 0 );
}
//+------------------------------------------------------------------+
//| 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(),clrGreenYellow);
}
}
} 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(),clrGreenYellow);
}
}
}
}
}
}
//+------------------------------------------------------------------+
//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=AccountEquity() * 0.01 /LotFactor ;
return(lot);
}
//+------------------------------------------------------------------+