Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 103

 
trader781:
e.g., copy the whole file.
Alexey Viktorov:
1. When an order is opened, write the ticket in the variable global level or static, and then monitor this order until it is blue in color, oops, until it is closed by comparison OrderCloseTime() > 0. If the close time is greater than zero, the order is closed.

2. The substitution for the GOTO operator is much more efficient. Read the documentation about the functions.

Is there any way of showing me an example? How do I wait for the previous trade to close?

double Lot = 0.1;      

double loss = 100;  



int start()

  {

  int order;

    if(OrdersTotal()==0)                            

    {                  

      order = OrderSend(Symbol(),OP_BUY,Lot,Ask,1*Point,Ask-loss*Point,Ask+loss*Point);   // Вверх

      order = OrderSend(Symbol(),OP_SELL,Lot,Bid,1*Point,Bid+loss*Point,Bid-loss*Point);    // Вниз

    }



   return(0);

  }

//+------------------------------------------------------------------+

 
DenZell:

Is there any way of showing me an example? How do I wait for the previous trade to close?

double Lot = 0.1;      

double loss = 100;  



int start()

  {

  int order;

    if(OrdersTotal()==0)                            

    {                  

      order = OrderSend(Symbol(),OP_BUY,Lot,Ask,1*Point,Ask-loss*Point,Ask+loss*Point);   // Вверх

      order = OrderSend(Symbol(),OP_SELL,Lot,Bid,1*Point,Bid+loss*Point,Bid-loss*Point);    // Вниз

    }



   return(0);

  }

//+------------------------------------------------------------------+

There are several options.

The simplest one is the sequence of actions. First, we try to do something with an already open order, and then, if there is no open order, we try to set it.

We divide position handling and opening of a new order into two separate user-defined functions. Then in the OnTick() function check for the presence of open orders and call one or the other function according to the result obtained.

It looks like this in words:

void OnTick()
{
if(OrdersTotal() > 0)
  открытие();
else
  сопровождение();
}

bool открытие()
{
// здесь код открытия
}

bool сопровождение()
{
// здесь код сопровождения
}
And it is even more difficult to check for a specific order if OrderCloseTime() > 0.

This is the case if the account provides, but more often it is the case of working of other Expert Advisors or opening orders manually.
 
is it possible to programmatically select the start date of the account history in the terminal?
 
Money_Maker:
Can I programmatically select the start date of the account history in the terminal?
You can. This will be the very first order in the history with type 6 - balance operation. The opening time of this order will be the beginning of the account history.
 
Artyom Trishkin:
You can. This will be the first order in the history with type 6 - balance operation.
I don't need the first order in the history ... the history opens at maximum ... I need the history from a certain date ... which I will set programmatically (apparently, the question was streamlined due to the details)
 
Money_Maker:
I don't need the first order in the history ... the history is opened to the maximum I need the history from a certain date ... which I will set programmatically (apparently the question was streamlined at the expense of details)
The answer is also possible.

But the question is still "streamlined", so I will say that we should skip the orders the open time of which is earlier than that "specific date".
 
Artyom Trishkin:
The answer is also that you can.

But the question still remains "streamlined", so I would say that we should skip orders whose opening time is earlier than this "certain date" ... of course it did not occur to me ... but 7 years is a very large number of orders ...
I have not really thought of filtering by date ... but 7 years is a great many of orders .
the question is underlined in red in the screenshot ... so the question is not streamlined?
 
Money_Maker:
Of course it didn't occur to me to filter by date ... but in 7 years there are a lot of orders .
In the screenshot, the question is underlined in red and you have to put a certain date there... so the question is not streamlined?
I do not understand your question :(

What exactly do you want to do programmatically?
 
Artyom Trishkin:
I don't understand your question :(

What exactly do you want to do programmatically?
Where it is underlined in red, enter the date and essentially click ok... it determines the depth of history in the report
 
Money_Maker:
where it is underlined in red, enter the date and essentially click ok... it determines the depth of history in the report
You can't do it programmatically in a pure mql. You need to look for this window and the date through WinAPI, I think.