Questions from Beginners MQL5 MT5 MetaTrader 5 - page 71

 
xyz999: 2) If optimisation (backtest) was carried out over a period of 10 months and the 1/4 forward test option was selected, as for example, how should I understand:
Client Terminal / Strategy Tester / Backtesting / Forward Testing
 

Thank you.

Yes, from this link.

http://www.metatrader5.com/ru/terminal/help/tester/tester_using/forward_testing.

I found the answer to my second question. However, there are NO answers to the first and third questions.

I would like to have them too.

I want to know the results and ratios of other traders. As my results are very alarming. I am a scientist in the field of automatic control and modelling of non-stationary processes, which includes also a graph of price movement in the market. I have been modelling non-stationary processes for many years and the way the tester works in no way fits into my years of experience. Something is wrong here. Either I use the tester incorrectly or it does not work properly. Let's find out together.

My backtest strictly following the optimization period shows 200% of the profit that we had during optimization with the same parameters. However, when choosing other optimization parameters and testing during the optimization period, we will get several times less profit. That should not be the case. That is why I have some questions.

 
xyz999: I found an answer to my second question. However, there is NO ANSWER TO THE FIRST AND THIRD QUESTION. I would like to have them too.

Well, it's not up to me, as they say, "Whatever I can" (c). I'm far from the topic itself. Try searching the forum, maybe where forward testing has already been discussed. Or, if you think the topic is very important, create a new thematic branch. Otherwise, questions will get lost in general branch.

xyz999 : Yes, on this link https://www.metatrader5.com/ru/terminal/help/algotrading/testing I found the answer to my second question.

There are reference materials in the terminal too. F1.

 
mario065:

Made a very dumb thing to do.

I took the body of Custom Moving Average indicator and put MFI buffer inside.

I changed the price.

I made you an expert, just an indicator and a comment to verify.

Thank you for not leaving the message unanswered. Alas the tester is still rejecting the smoothing of the other indicators. My Expert Advisor requires two indicators - MFI and DEMA at the same time. I have implemented your algorithm with MFI in my EA - in vain - I have not been able to run it for optimization of global variables.

Thanks again for your messages.
 
The article about EA https://www.mql5.com/ru/articles/100 mentions conditions to open positions, but no conditions to close them.


   bool Buy_opened=false;  // переменные, в которых будет храниться информация 
   bool Sell_opened=false; // о наличии соответствующих открытых позиций

   if(PositionSelect(_Symbol)==true) // есть открытая позиция
     {
      if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
        {
         Buy_opened=true;  //это длинная позиция
        }
      else if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
        {
         Sell_opened=true; // это короткая позиция
        }
     }    
             
   bool Buy_Condition_1=...
   bool Buy_Condition_2=...
   bool Buy_Condition_3=...

   
 if(Buy_Condition_1 || Buy_Condition_2)
     { 
       if(Buy_Condition_3)
        {
         // есть ли в данный момент открытая позиция на покупку?
         if(Buy_opened)
           {
            Alert("Уже есть позиция на покупку!!!");
            return;    // не добавлять к открытой позиции на покупку
           }        
         mrequest.action = TRADE_ACTION_DEAL;                                  // немедленное исполнение
         mrequest.price = NormalizeDouble(latest_price.ask,_Digits);           // последняя цена ask
         mrequest.sl = NormalizeDouble(latest_price.ask - STP*_Point,_Digits); // Stop Loss
         mrequest.tp = NormalizeDouble(latest_price.ask + TKP*_Point,_Digits); // Take Profit
         mrequest.symbol = _Symbol;                                            // символ
         mrequest.volume = Lot;                                                // количество лотов для торговли
         mrequest.magic = EA_Magic;                                            // Magic Number
         mrequest.type = ORDER_TYPE_BUY;                                       // ордер на покупку
         mrequest.type_filling = ORDER_FILLING_FOK;                            // тип исполнения ордера - все или ничего
         mrequest.deviation=10;                                               // проскальзывание от текущей цены
         //--- отсылаем ордер
         OrderSend(mrequest,mresult);
         // анализируем код возврата торгового сервера
         if(mresult.retcode==10009 || mresult.retcode==10008) //запрос выполнен или ордер успешно помещен
           {
            Alert("Ордер Buy успешно помещен, тикет ордера #:",mresult.order,"!!");
           }
         else
           {
            Alert("Запрос на установку ордера Buy не выполнен - код ошибки:",GetLastError());
            return;
           }
        }
      }
 
 bool Buy_Close_1=....
 bool Buy_Close_2=...
 bool Buy_Close_3=...
 
 if(Buy_Close_1 || Buy_Close_2)
     {
      if(Buy_Close_3)
        {
        // есть ли в данный момент открытая позиция на покупку?
         if(????)
         {
           Alert("Позицию на покупку закрываю!!!");
            return;    // закрыл
         }        
         mrequest.action = TRADE_ACTION_DEAL;                                  // немедленное исполнение
         mrequest.price = NormalizeDouble(latest_price.bid,_Digits);           // последняя цена bid
         mrequest.sl = 0;
         mrequest.tp = 0;
         mrequest.symbol = _Symbol;                                            // символ
         mrequest.volume = Lot;                                                // количество лотов для торговли
         mrequest.magic = EA_Magic;                                            // Magic Number
         mrequest.type = ORDER_TYPE_SELL; // ордер на продажу                                     // ордер на покупку
         mrequest.type_filling = ORDER_FILLING_FOK;                            // тип исполнения ордера - все или ничего
         mrequest.deviation=10;                                               // проскальзывание от текущей цены
         //--- отсылаем ордер
         OrderSend(mrequest,mresult);

Instead of question marks I put PositionSelect(_Symbol) with value true. It didn't help.


Question. What can I change minimally - to be able to set close conditions?
Пошаговое руководство по написанию MQL5-советников для начинающих
Пошаговое руководство по написанию MQL5-советников для начинающих
  • 2010.06.09
  • Samuel
  • www.mql5.com
Написание советников на MQL5 проще чем кажется, вы легко можете этому научиться. В этом руководстве вы познакомитесь с основными моментами, необходимыми для написания простого советника на основе конкретной торговой стратегии. Рассмотрена структура советника, использование встроенных технических индикаторов и торговых функций, вопросы отладки и тестирования советника на исторических данных.
 
Lester:
The article about the Expert Advisor https://www.mql5.com/ru/articles/100 mentions conditions for opening positions, but it doesn't discuss conditions for closing positions.


Instead of question marks I put PositionSelect(_Symbol) with value true. It didn't help.


Question. What can I change to the minimum - to be able to set closing conditions?

You have a return after Alert. Position probably isn't closing because of this return. Please take it away and try again.

// есть ли в данный момент открытая позиция на покупку?
         if(????)
         {
           Alert("Позицию на покупку закрываю!!!");
           return;    // закрыл
         }  


 
Thanks, as I felt the answer was very simple and that it was close by.
However, another question arose on the question marks part.

On the algorithm.

Under appropriate conditions + no position - the position is opened, and under other conditions and the presence of an open position - the open position is closed.

If I'm not mistaken - existence of a position, namely Buy_opened

if(Buy_Condition_1 || Buy_Condition_2)
     { 
       if(Buy_Condition_3)
        {
         // есть ли в данный момент открытая позиция на покупку?
         if(Buy_opened)
           {
            Alert("Уже есть позиция на покупку!!!");
            return;    // не добавлять к открытой позиции на покупку
           }        

equal to one - causes alert and return (returns to the beginning), and equal to zero - opens Buy order.

Question. What should I write instead of question marks - the condition of an open order, so that the EA does not open a position (in my case, it opens a sell order) ?

 bool Buy_Close_1=....
 bool Buy_Close_2=...
 bool Buy_Close_3=...
 
 if(Buy_Close_1 || Buy_Close_2)
     {
      if(Buy_Close_3)
        {
        // есть ли в данный момент открытая позиция на покупку?
         if(????)
         {
           Alert("Позицию на покупку закрываю!!!");
            return;    // закрыл
         }        
         mrequest.action = TRADE_ACTION_DEAL;                                  // немедленное исполнение
         mrequest.price = NormalizeDouble(latest_price.bid,_Digits);           // последняя цена bid
         mrequest.sl = 0;
         mrequest.tp = 0;

At the moment I have also prescribed Buy_opened, because the conditions of this definition are related to PositionSelect(_Symbol)

I understand that the questions don't mean anything, as it is possible to quickly try out all possible logical options and test, but the problem is that the tester bug doesn't allow me to do this, but there is an opportunity to actually diagnose on M1 in real trading mode.

 
Lester:
...

I understand that the questions don't mean anything as you can quickly try out all the possible logical options and test, but the problem is that the tester bug doesn't allow me to do that, but there is an opportunity to actually diagnose on M1 in real trading mode.

I don't quite understand your question.

And what bug in the tester did you find that prevents you from running the test?

 
tol64:

I don't quite understand your question.

What is the bug in the tester that prevents you from running the test?

I described it earlier or in the Indicator branch. Dema referring to the MFI indicator handle is not displayed in the MFI window and therefore the tester does not work, but the Expert Advisor works. Same with MA, AMA...!

About the question. What should we write instead of the question marks to make the Expert Advisor "understand" that there is an open position and not open an order!

bool Buy_Close_1=....
 bool Buy_Close_2=...
 bool Buy_Close_3=...
 
 if(Buy_Close_1 || Buy_Close_2)
     {
      if(Buy_Close_3)
        {
        // есть ли в данный момент открытая позиция на покупку?
         if(????)
         {
           Alert("Позицию на покупку закрываю!!!");
           // Return убрал благодаря форуму ))
         }        
 
Lester:
Described earlier, or in the indicator branch. Dema referring to the MFI indicator handle - is not displayed in the MFI window, and therefore - the Expert Advisor does not work. The same goes for MA, AMA.

About the question. What should we write instead of question marks so that the EA "sees" that there is an open position and does not open an order!

If there is a position (PositionSelect(_Symbol)) and all other conditions are met, then close the position. If return from your example is not removed, the condition should look like this

if(!PositionSelect(_Symbol))
  {
   return;
  }

which means if there is no position, then exit. If not exit, the program will execute the code that comes after this block.

But I would put check for presence/absence of position before closing condition checks.

Reason: