//+------------------------------------------------------------------+
This EA place One BUT and One SELL same time. Before use on real account please test on demo account first. Profit-Loss your own responsitivy .
//| double-order.mq4 |
//| Copyright 2022, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
extern int MagicNumber=10001;
extern double Lots =0.01;
extern double TakeProfit=50;
extern int Slippage=3;
void OnTick()
{
//---
double lotmax = AccountEquity()/1000;
double speared =DoubleToStr(Ask-Bid,Digits);
double open = 0;
if (Lots > lotmax){
Alert(" Lotsize more then fund Please set lot size less then " , lotmax); }
else{ open = Ask; }
double buyticket = 0;
double lastbuy = 0;
double buytarget = 0;
double buyprofit = 0;
datetime buydate = 0;
double sellticket = 0;
double lastsell = 0;
double selltarget = 0;
double sellprofit = 0;
datetime selldate = 0;
double accountplus1 = AccountBalance()+0.10,Digits;
double askplus1 = Ask+TakeProfit*Point;
int result=0;
for (int cntl = 0; cntl < OrdersTotal(); cntl++)
{
if(OrderSelect(cntl,SELECT_BY_POS,MODE_TRADES) && OrderMagicNumber()== MagicNumber){
if(OrderMagicNumber()== MagicNumber && OrderType() == OP_BUY){
buyticket = OrderTicket();
lastbuy = OrderOpenPrice();
buydate = OrderOpenTime();
buyprofit = OrderProfit();
buytarget = lastbuy+(TakeProfit*Point);}
if(OrderMagicNumber()== MagicNumber && OrderType() == OP_SELL){
sellticket = OrderTicket();
lastsell = OrderOpenPrice();
selldate = OrderOpenTime();
sellprofit = OrderProfit();
selltarget = lastsell-(TakeProfit*Point);}
}
}
//+------------------------------------------------------------------+
double exit = 0;
if(sellprofit > 0 && High[1] < Close[0] && selltarget >= Close[0]){Alert("Close sell and open send new order");
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{ exit = 1;
result=OrderClose(sellticket,OrderLots(),Ask,Slippage,Red);
if(result > 0){
OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"SELL_Double_Order_EA",MagicNumber,0,Green);
OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"SELL_Double_Order_EA",MagicNumber,0,Green);
}
}
}
if(buyprofit > 0 && Low[1] > Close[0] && buytarget <= Close[0]){Alert("Close buy and open send new order");
exit = 2;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{ result=OrderClose(buyticket,OrderLots(),Bid,Slippage,Green);
if(result>0){
OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"BUY_Double_Order_EA",MagicNumber,0,Yellow);
OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"BUY_Double_Order_EA",MagicNumber,0,Yellow);
}
}
}
if(lastbuy == 0 && lastsell == 0 && OrdersTotal() == 0){Alert("open send new order");
exit=3;
OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"open_send_new_order",MagicNumber,0,Blue);
OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"open_send_new_order",MagicNumber,0,Blue);
}
// All close
if((AccountEquity() > AccountBalance() && AccountEquity() > accountplus1 && High[1] < Close[0]) || (AccountEquity() > AccountBalance() && AccountEquity() > accountplus1 && Low[1] > Close[0])){Alert("All Close ");
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);
}
}
//----------------------------
Comment(" Account Balance ", AccountBalance() ," accountplus1 ",accountplus1, " Equity " , AccountEquity(), " lotmax ",lotmax, " open ",open , " speard ", speared," ask ",Ask," askplus1 ",askplus1," exit ", exit,
"\n boy order ", buyticket, " last buy price " ,lastbuy , " buy target ", buytarget," buy profit ",buyprofit," buy date ",buydate,
"\n sell order ",sellticket, " last sell price ",lastsell,"sell target", selltarget," sell profit ",sellprofit," sell date ",selldate);
}