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

 
Artyom Trishkin:
Opened how? What is the reason for the opening?

The reason for opening a position on the euro and the reason for opening a position on the pound. Obviously, it must be somehow written in the code of the Euro Expert Advisor. But how - I do not understand.

 
novichok2018:

The reason for opening a position on the euro and the reason for opening a position on the pound. Obviously, it must be somehow written in the code of the Euro Expert Advisor. But how - I do not understand.

It is done through the usual if() with check of comments. And in the order comments, we insert the time of opening or the ticket of the order from which the second order opens.
 
Alexandr Sokolov:
The code is implemented through the usual if() with comment checking. In the comment of the order, you should insert the time of opening or the ticket of the order from which the second order opens.

How can the if() of the Euro EA code be referenced to the Pound EA code? How can I see the pound position in the euro code?

 
novichok2018:

How can the if() of the Euro EA code be referenced to the Pound EA code? How do you see the pound position in the euro code?

You are complicating things yourself. You simply loop through the euro orders and compare each euro order with all the pound orders. And if none of the comments matches, then you open a pound order with the comment where the ticket or the time of opening of the euro order

 

Can you please enlighten me on how to transfer the results of the optimisation of an EA in the MT5 tester, to the EA on the MT5 chart panel ? How to save them ?

In the manual and Google can not find it yet ...

MANY THANKS.

Тестирование стратегий - Алгоритмический трейдинг, торговые роботы - MetaTrader 5
Тестирование стратегий - Алгоритмический трейдинг, торговые роботы - MetaTrader 5
  • www.metatrader5.com
Тестер стратегий позволяет тестировать и оптимизировать торговые стратегии (советники) перед началом использования их в реальной торговле. При тестировании советника происходит его однократная прогонка с начальными параметрами на исторических данных. При оптимизации торговая стратегия прогоняется несколько раз с различным набором параметров...
 
Alexandr Sokolov:

You are complicating things yourself. You simply loop through the euro orders and compare each euro order with all the pound orders. And if none of the comments matches, then you open a pound order with the comment of the ticket or time of opening an order on the euro.

To be honest - I don't understand anything. The situation is as follows: there are no orders on either the euro or the pound. And we have conditions for opening a position in the pound and the position is opened. The position opening on the pound should become a signal for opening a position on the euro and the position should open. So what should I do in the cycle? And I do not understand anything about the comments. Can you write a sample code to help me understand it?

And in the pound code, when the conditions appear, can we open two positions - one in the pound and the other in the euro by specifying the required symbol in OrderSend? Will this work?

 
novichok2018:

To be honest - I do not understand anything. The situation is as follows: there are no orders on either the euro or the pound. And there are conditions for opening a position in the pound and the position has opened. The position opening on the pound should be a signal for the position opening on the euro and the position should open. So what should I do in the cycle? And I do not understand anything about the comments. Can you write a sample code for me to understand?

int ticket;
for(int  i = 0; i < OrdersTotal(); i++)
  {
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true)
     {
      if(OrderMagicNumber() == id_number1 && OrderSymbol() == "GBPUSD")
        {
         if(SecondExpert(OrderTicket()) == false)
           {
            ticket = OrderSend(...);
           };
        };
     };
  };

//----------------------------------------------------------------------------------------------------------------------

bool SecondExpert(int ticket)
  {
   bool se = false;
   for(int i = 0; i < OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true)
        {
         if(OrderMagicNumber() == id_number2 && OrderSymbol() == "EURUSD")
           {
            if(OrderComment() == (string)ticket)
              {
               se = true; break;
              };
           };
        };
     };
  //-----------------------------------------------------------------
   return(se);
  }


That's how I see it).

 
novichok2018:

To be honest, I have not understood anything. The situation is as follows: there are no orders either on the euro or on the pound. And we have conditions for opening a position in the pound and the position has opened. The position opening on the pound should trigger the position opening on the euro and the position should open. So what should I do in the cycle? And I do not understand anything about the comments. Can you write a sample code for me to understand?

If it is in one EA it should be something like this

if(условие для EURUSD)
 {
  OrderSend("EURUSD", ... );
  OrderSend("GBPUSD", ... );
 }

if(условие для GBPUSD)
 {
  OrderSend("GBPUSD", ... );
  OrderSend("EURUSD", ... );
 }

Or even simpler

if(условие для EURUSD || условие для GBPUSD)
 {
  OrderSend("EURUSD", ... );
  OrderSend("GBPUSD", ... );
 }
 
Alexey Viktorov:

If it's in one EA it should be something like this

Or even simpler

Yes, I imagined it somehow, but I cannot check the work on the history, because the opening of a position on EUR should take place due to the condition for GBP and it is not reflected in the code for EUR, and the history is depicted on EUR. Hence the uncertainty in the correctness of the decision.

 
novichok2018:

Yes, that is how I imagined it, but I cannot check if it works on the history, because the opening of a position on the euro should take place by the condition for the pound and is not reflected in the code for the euro, while the history is displayed on the euro. Hence the uncertainty in the correctness of the decision.

Igor Kim's functionbool ExistPositions() returns the flag of position existence, it is too difficult for me to adapt it to my specific conditions. But I don't think it will be tested in history.

If no one has a code, actually tested in the real world, to show me, I will try it scientifically. Thank you.