Features of the mql5 language, subtleties and tricks - page 109

 
Taras Slobodyanik:

logical - it's a coup.

Wrote the information without assessing the logicality. If it is affected, the PositionID should have changed in the same way.

It's not changing now. If this is a bug, that would be great!


Therefore a question. Should the DEAL_ENTRY_INOUT transaction change the PositionID to DEAL_ORDER?

I think it should. This behaviour would be very convenient/right.
 
fxsaber:

Wrote the information without assessing the logic. If it is affected, however, the PositionID should have changed in the same way.

It's not changing now. If this is a bug, that would be great!


Therefore a question. Should the DEAL_ENTRY_INOUT transaction change the PositionID to DEAL_ORDER?

It says no. https://www.mql5.com/ru/docs/constants/tradingconstants/positionproperties#enum_position_property_integer

Although it was written earlier that yes, and the Position ID was changed.

Документация по MQL5: Константы, перечисления и структуры / Торговые константы / Свойства позиций
Документация по MQL5: Константы, перечисления и структуры / Торговые константы / Свойства позиций
  • www.mql5.com
Тикет позиции. Уникальное число, которое присваивается каждой вновь открытой позиции. Как правило, соответствует тикету ордера, в результате которого она была открыта, за исключением случаев изменения тикета в результате служебных операций на сервере. Например, начисления свопов переоткрытием позиции. Для нахождения ордера, которым была открыта...
 
Andrey Barinov:

It says no. https://www.mql5.com/ru/docs/constants/tradingconstants/positionproperties#enum_position_property_integer

Perhaps there is some good reason for that. From my vantage point, it doesn't seem right at all.

Although before it was written that yes, and the Position ID was changed.

I ask the developers to clarify the situation. When the PositionID changes, then after five flips, the Trading History tab in the Positions view will show five positions.

Now (the PositionID does not change during a flip) only one position is always shown. This is, to put it mildly, a strange solution.

 

Forum on trading, automated trading systems and trading strategy testing

New version of MetaTrader 5 build 1930: Floating chart windows and .Net libraries in MQL5

fxsaber, 2018.11.09 16:19

In the "by real ticks" mode, the Tester generates the bars independently - on the arrival of the ticks. For this reason, the bar history of a custom symbol in the Terminal and in the Tester may be quite different.

 
It often happens that after compiling the EA, the settings of the Tester are reset, if this EA was previously selected in it. This is annoying, to say the least. After each compilation, we have to go to the tree of Expert Advisors and search for our EA. If anyone doesn't know, there is a recipe for the Tester not to reset. You should run the Expert Advisor once in debug mode on the history - CTRL+F5. After that any recompiling will not affect Tester settings.
 
fxsaber:
We've noticed that the settings of the tester are often reset after compilation, if this Expert Advisor has been previously selected in it. This is annoying, to say the least. After each compilation, we have to go to the tree of Expert Advisors and search for our EA. If anyone doesn't know, there is a recipe for the Tester not to reset. You should run the Expert Advisor once in debug mode on the history - CTRL+F5. After that any recompiling will not affect Tester settings.


Same thing, noticed it yesterday!

Fixed it this way: After compiling new version (New file name) you have to restart the terminal. - Maybe it does not update mqlcache

After that, tester doesn't reset to previous file during compilation.


This problem appeared several times before, then disappeared. Then it reappeared again....

Z.I. Didn't read the meaning of your words, and you were advising rather than asking...

 
Comments not related to this topic have been moved to "Any questions from newbies on MQL4, help and discussion on algorithms and codes".
 

Anybody here? Check the history download script...

Am I the only one who gets frozen to death? The script is taken from the help...

//+------------------------------------------------------------------+ 
//|                                              TestLoadHistory.mq5 | 
//|                        Copyright 2009, MetaQuotes Software Corp. | 
//|                                              https://www.mql5.com | 
//+------------------------------------------------------------------+ 
#property copyright "2009, MetaQuotes Software Corp." 
#property link      "https://www.mql5.com" 
#property version   "1.02" 
#property script_show_inputs 

//--- input parameters 

//+------------------------------------------------------------------+ 
//| Script program start function                                    | 
//+------------------------------------------------------------------+ 
void OnStart()
  {



   int      all_symbols=SymbolsTotal(false);   string  sym_name="";
   Print("Load symbols ",all_symbols);

   for(int k=0;k<all_symbols;k++)
      if((sym_name=SymbolName(k,false))!="")
        {
         SymbolSelect(sym_name,true);

         Print(k," Symbol name ",sym_name);

         int res=CheckLoadHistory(sym_name,PERIOD_M1,(TimeCurrent()-60*60*24*5));

         switch(res)
           {
            case -1 : Print("Unknown symbol ",sym_name);             break;
            case -2 : Print("Requested bars more than max bars in chart ",sym_name); break;
            case -3 : Print("Program was stopped ",sym_name);                        break;
            case -4 : Print("Indicator shouldn't load its own data ",sym_name);      break;
            case -5 : Print("Load failed ",sym_name);                                break;
            case  0 : Print("Loaded OK ",sym_name);                                  break;
            case  1 : Print("Loaded previously ",sym_name);                          break;
            case  2 : Print("Loaded previously and built ",sym_name);                break;
            default : Print("Unknown result ",sym_name);
           }

         datetime first_date;
         SeriesInfoInteger(sym_name,PERIOD_M1,SERIES_FIRSTDATE,first_date);
         int bars=Bars(sym_name,PERIOD_M1);
         Print("First date ",first_date," - ",bars," bars");
        }
//--- 

//--- 
  }
//+------------------------------------------------------------------+ 
//|                                                                  | 
//+------------------------------------------------------------------+ 
int CheckLoadHistory(string symbol,ENUM_TIMEFRAMES period,datetime start_date)
  {
   datetime first_date=0;
   datetime times[100];
//--- check symbol & period 
   if(symbol==NULL || symbol=="") symbol=Symbol();
   if(period==PERIOD_CURRENT)     period=Period();
//--- check if symbol is selected in the MarketWatch 
   if(!SymbolInfoInteger(symbol,SYMBOL_SELECT))
     {
      if(GetLastError()==ERR_MARKET_UNKNOWN_SYMBOL) return(-1);

      SymbolSelect(symbol,true);
     }
//--- check if data is present 
   SeriesInfoInteger(symbol,period,SERIES_FIRSTDATE,first_date);
   if(first_date>0 && first_date<=start_date) return(1);
//--- don't ask for load of its own data if it is an indicator 
   if(MQL5InfoInteger(MQL5_PROGRAM_TYPE)==PROGRAM_INDICATOR && Period()==period && Symbol()==symbol)
      return(-4);
//--- second attempt 
   if(SeriesInfoInteger(symbol,PERIOD_M1,SERIES_TERMINAL_FIRSTDATE,first_date))
     {
      //--- there is loaded data to build timeseries 
      if(first_date>0)
        {
         //--- force timeseries build 
         CopyTime(symbol,period,first_date+PeriodSeconds(period),1,times);
         //--- check date 
         if(SeriesInfoInteger(symbol,period,SERIES_FIRSTDATE,first_date))
            if(first_date>0 && first_date<=start_date) return(2);
        }
     }
//--- max bars in chart from terminal options 
   int max_bars=TerminalInfoInteger(TERMINAL_MAXBARS);
//--- load symbol history info 
   datetime first_server_date=0;
   while(!SeriesInfoInteger(symbol,PERIOD_M1,SERIES_SERVER_FIRSTDATE,first_server_date) && !IsStopped())
      Sleep(5);
//--- fix start date for loading 
   if(first_server_date>start_date) start_date=first_server_date;
   if(first_date>0 && first_date<first_server_date)
      Print("Warning: first server date ",first_server_date," for ",symbol,
            " does not match to first series date ",first_date);
//--- load data step by step 
   int fail_cnt=0;
   while(!IsStopped())
     {
      //--- wait for timeseries build 
      while(!SeriesInfoInteger(symbol,period,SERIES_SYNCHRONIZED) && !IsStopped())
         Sleep(5);
      //--- ask for built bars 
      int bars=Bars(symbol,period);
      if(bars>0)
        {
         if(bars>=max_bars) return(-2);
         //--- ask for first date 
         if(SeriesInfoInteger(symbol,period,SERIES_FIRSTDATE,first_date))
            if(first_date>0 && first_date<=start_date) return(0);
        }
      //--- copying of next part forces data loading 
      int copied=CopyTime(symbol,period,bars,100,times);
      if(copied>0)
        {
         //--- check for data 
         if(times[0]<=start_date)  return(0);
         if(bars+copied>=max_bars) return(-2);
         fail_cnt=0;
        }
      else
        {
         //--- no more than 100 failed attempts 
         fail_cnt++;
         if(fail_cnt>=100) return(-5);
         Sleep(10);
        }
     }
//--- stopped 
   return(-3);
  }
//+------------------------------------------------------------------+ 
//| Возвращает строкое значение периода                              | 
//+------------------------------------------------------------------+ 
string GetPeriodName(ENUM_TIMEFRAMES period)
  {
   if(period==PERIOD_CURRENT) period=Period();
//--- 
   switch(period)
     {
      case PERIOD_M1:  return("M1");
      case PERIOD_M2:  return("M2");
      case PERIOD_M3:  return("M3");
      case PERIOD_M4:  return("M4");
      case PERIOD_M5:  return("M5");
      case PERIOD_M6:  return("M6");
      case PERIOD_M10: return("M10");
      case PERIOD_M12: return("M12");
      case PERIOD_M15: return("M15");
      case PERIOD_M20: return("M20");
      case PERIOD_M30: return("M30");
      case PERIOD_H1:  return("H1");
      case PERIOD_H2:  return("H2");
      case PERIOD_H3:  return("H3");
      case PERIOD_H4:  return("H4");
      case PERIOD_H6:  return("H6");
      case PERIOD_H8:  return("H8");
      case PERIOD_H12: return("H12");
      case PERIOD_D1:  return("Daily");
      case PERIOD_W1:  return("Weekly");
      case PERIOD_MN1: return("Monthly");
     }
//--- 
   return("unknown period");
  }
//+------------------------------------------------------------------+
 

Forum on trading, automated trading systems and trading strategy testing

Unclear situation when pending orders trigger.

fxsaber, 2018.11.26 13:37

There is also a situation like this:

  1. A market order has been placed opening a position and OrdersTotal has increased by one.
  2. It was executed and OrdersTotal decreased by one, but PositionsTotal did not increase by one. In other words, there is a position, but the terminal doesn't know about it.

For example, there are no positions or orders - PositionsTotal = 0, OrdersTotal = 0.

You set a market order. PositionsTotal = 0, OrdersTotal = 1.

The market order is executed - OrdersTotal = 0. But PositionsTotal = 0!

 
Duration of execution
PositionSelectByTicket(OrderGetInteger(ORDER_TICKET));

such that PositionsTotal can (not difficult to reproduce) change.


For example, PositionsTotal returns zero just before PositionsSelectBytTicket, which returns true.

Reason: