Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 612
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I wrote code that when any order closes all other pending orders, but the problem is that I wrote 4 orders 2, 3, 4, 5. So when next pending orders 6, 7, 8, etc. are opened, they should not be closed. The numbers of orders highlighted in red should be changed into the orders that all pending orders will be closed.
void start(){
//----
double Take1 = Ask+20 *Point;
double Take2 = Ask+0 *Point;
double Take3 = Ask-20 *Point;
double Take4 = Ask-40 *Point;
double Take5 = Ask-60 *Point;
double Stop = Bid-StopLoss *Point;
if(OrdersTotal()==0){
OrderSend(Symbol(),0,0.01,Ask,30,Stop,Take1,",0,0,CLR_NONE);
OrderSend(Symbol(),2,0.02,Ask-20*Point,30,Stop,Take2,"",0,0,CLR_NONE);
OrderSend(Symbol(),2,0.04,Ask-40*Point,30,Stop,Take3,",0,0,CLR_NONE);
OrderSend(Symbol(),2,0.08,Ask-60*Point,30,Stop,Take4,",0,0,CLR_NONE);
OrderSend(Symbol(),2,0.16,Ask-80*Point,30,Stop,Take5,"",0,0,CLR_NONE);
}
if(OrdersTotal()==4)
{
OrderDelete(2);
}
if(OrdersTotal()==3)
{
OrderDelete(3);
}
if(OrdersTotal()==2)
{
OrderDelete(4);
}
if(OrdersTotal()==1)
{
OrderDelete(5);
return(0);
}
I wrote code that when any order closes all other pending orders, but the problem is that I wrote 4 orders 2, 3, 4, 5. So when next pending orders 6, 7, 8, etc. are opened, they should not be closed. The numbers of orders marked in red should be changed into the orders which all pending orders will be closed.
First, we check in the loop whether the position has recently been closed or not, for which we will need OrdersHistoryTotal. Where we check the time of closing the position OrderCloseTime, if it is higher than the last one in the variable, then we loop through all of the open OrdersTotal. And close them.
P.S. Insert the code using Alt+S or the
For example this
here is the condition if(OrdersTotal()==0). but what should we write the condition if there are zero bays?
If (OP_BUY==0)
If (OP_BUY==0)