Errors, bugs, questions - page 1930

 
Almost a childish question: why is it so?
void OnStart()
{
  const double Norm = NormalizeDouble(8905 / 1000.0, 3);
  Print(Norm); // 8.904999999999999
  Print(DoubleToString(Norm, 3)); // 8.905
  
  const double Norm2 = (double)DoubleToString(Norm, 3);
  Print(Norm2); // 8.904999999999999
  Print(Norm == Norm2); // true
}

For some reason, I was sure that DoubleToString was meaningless after normalisation. But no, as the script shows. Why is it so?

It seems that the double -> string conversion does not work correctly.

 
The PositionGet functions are very slow in the tester. For demonstration purposes, the following Expert Advisor was written
// #include <TesterBench.mqh> // https://www.mql5.com/ru/code/18804/

input int Interval = 3600;
input double Lots = 1;

void OnTick()
{
  if (!PositionSelect(_Symbol))
  {
    if (HistorySelect(0, TimeCurrent()))
    {
      const int Total = HistoryDealsTotal() - 1;

      MqlTradeRequest Request = {0};
      MqlTradeCheckResult CheckResult;
  
      Request.action = TRADE_ACTION_DEAL;
  
      Request.symbol = _Symbol;
      Request.type = ((Total >= 0) && ((ENUM_DEAL_TYPE)HistoryDealGetInteger(HistoryDealGetTicket(Total), DEAL_TYPE) == DEAL_TYPE_SELL)) ?
                     ORDER_TYPE_SELL : ORDER_TYPE_BUY;;
  
      Request.volume = Lots;
      Request.price = SymbolInfoDouble(Request.symbol, (Request.type == ORDER_TYPE_BUY) ? SYMBOL_ASK : SYMBOL_BID);

      if (OrderCheck(Request, CheckResult))
      {
        MqlTradeResult Result;

        const bool AntiWarning = OrderSend(Request, Result);            
      }
    }
  }
  else
  {
    // Если раскоментировать эти строки, одиночный прогон станет на 20% медленнее.
//    string Symbol = ::PositionGetString(POSITION_SYMBOL);
//    string Comment = ::PositionGetString(POSITION_COMMENT);

    if (TimeCurrent() - PositionGetInteger(POSITION_TIME) >= Interval)      
    {
      MqlTradeRequest Request = {0};
      MqlTradeResult Result;
      
      Request.action = TRADE_ACTION_DEAL;
      Request.position = PositionGetInteger(POSITION_TICKET);
  
      Request.symbol = PositionGetString(POSITION_SYMBOL);
      Request.type = (ENUM_ORDER_TYPE)(1 - PositionGetInteger(POSITION_TYPE));
  
      Request.volume = PositionGetDouble(POSITION_VOLUME);
      Request.price = PositionGetDouble(POSITION_PRICE_CURRENT);
          
      const bool AntiWarning = OrderSend(Request, Result);
    }
  }
}


Result of single run with yellow lines commented out

Core 1  2017.07.17 23:59:58   Interval = 7.09 s.
Core 1  EURUSD,M1: 13369675 ticks, 47426 bars generated. Environment synchronized in 0:00:00.857. Test passed in 0:00:09.720 (including ticks preprocessing 0:00:01.950).
Core 1  EURUSD,M1: total time from login to stop testing 0:00:10.577 (including 0:00:00.857 for history data synchronization)


Result of a single run with yellow lines NOT commented out

Core 1  2017.07.17 23:59:58   Interval = 9.336 s.
Core 1  EURUSD,M1: 13369675 ticks, 47426 bars generated. Environment synchronized in 0:00:00.062. Test passed in 0:00:11.997 (including ticks preprocessing 0:00:01.934).
Core 1  EURUSD,M1: total time from login to stop testing 0:00:12.059 (including 0:00:00.062 for history data synchronization)


TesterBench library shows the same drop in execution time.


HH Not only PositionGet, but also OrderGet, HistoryDealGet, HistoryOrderGet are slow.

 

In the tester (1629) trades are opened at zero prices

Running the Expert Advisor in the tester using real ticks of the FIBOGroup-MT5 Server


 

Question for developers and interested colleagues.

In Tester in visualisation mode there is an object of CiMA class - muwings.

Mode = "Every tick based on real ticks". The speed in the Visualizer is close to maximum.

The problem is this. When a new bar appears, you have to wait for a shitload of new ticks to refresh values of the CiMA muwings, or rather values in the muwings buffer.

And on every tick the update is accelerated by method CiMA::Refresh(-1).

Why does the Tester work so badly?

No such problems in real trade.

 

Pusha is a strange one these days:

uest/302788

request/302788

As I can guess, it was me who was put down as a candidate and commented on the same order.

But the messages are just like for coders)

 

From the documentation

ENUM_BASE_CORNER

Identifier

Description

CORNER_LEFT_UPPER

Centre of coordinates in the upper left corner of the chart

CORNER_LEFT_LOWER

Centre of coordinates in the lower left corner of the chart

CORNER_RIGHT_LOWER

Centre of coordinates in the lower right corner of the chart

CORNER_RIGHT_UPPER

centre of coordinates in the upper right corner of the chart

Question: Why couldn't the table be drawn in numerical order? You put 1 - and instead of the expected"Coordinate centre in the upper left corner of the chart" you get"Coordinate centre in the lower right corner of the chart".

Now it looks like this

1 - Coordinate centre in the lower left corner of the chart.
2 - Coordinate centre in the graph bottom right corner
3 - Coordinate centre in the upper right corner of the chart
4 - Coordinate centre in the left top corner of the chart

 
Aleksey Vyazmikin:

From the documentation

ENUM_BASE_CORNER

Identifier

Description

CORNER_LEFT_UPPER

Centre of coordinates in the upper left corner of the chart

CORNER_LEFT_LOWER

Centre of coordinates in the lower left corner of the chart

CORNER_RIGHT_LOWER

Centre of coordinates in the lower right corner of the chart

CORNER_RIGHT_UPPER

centre of coordinates in the upper right corner of the chart

Question: Why couldn't the table be in numerical order? You put 1 - and instead of the expected"Coordinate centre in the upper left corner of the graph" you get"Coordinate centre in the lower right corner of the graph".

It looks like this

1 - Coordinate centre in the lower left corner of the chart.
2 - Coordinate centre in the graph bottom right corner
3 - Coordinate centre in the upper right corner of the chart
4 - Coordinate centre in the left top corner of the chart

The counting starts from zero.

What prevents you from entering CORNER_LEFT_UPPER instead of a number? That's what enumeration is for, so you don't have to think about numbers.

 

In the helpdesk

MT4:

For objects with fixed size: OBJ_BUTTON, OBJ_RECTANGLE_LABEL and OBJ_EDIT properties OBJPROP_XDISTANCE and OBJPROP_YDISTANCE set position of the upper left object point relative to the chart corner (OBJPROP_CORNER), from which X and Y coordinates in pixels will be counted.


MT5:

For objects with fixed size: OBJ_BUTTON, OBJ_RECTANGLE_LABEL, OBJ_EDIT and OBJ_CHART, properties OBJPROP_XDISTANCE and OBJPROP_YDISTANCE set the position of the upper left point of the object relative to the chart corner (OBJPROP_CORNER), from which X and Y coordinates in pixels will be measured.

The matter is that the old version of MT4 using ObjectSet allows placing objects relative to their edges (corners) - for objects in the left part the calculation of pixels is performed from the first symbol, for objects in the right part - from the last symbol, while the new version always performs the calculation from the first symbol, which makes positioning of labels with text difficult, because you don't always know how many text symbols will be. I ask the developers to add a choice of text alignment method!

//+------------------------------------------------------------------+
//|Функция вывода информации на экран -- Старый вариант              |
//+------------------------------------------------------------------+

void Label_MQL4(string _name,int _window,int _x,int _y,string _text,int _font,color _color,int corner)
  {
   ObjectDelete(_name);
   ObjectCreate(_name,OBJ_LABEL,_window,0,0);
   ObjectSet(_name,OBJPROP_CORNER,corner);
   ObjectSet(_name,OBJPROP_XDISTANCE,_x);
   ObjectSet(_name,OBJPROP_YDISTANCE,_y);
   ObjectSetText(_name,_text,_font,"Arial",_color);
  }
  
//+------------------------------------------------------------------+
//|Функция вывода информации на экран -- Новый вариант               |
//+------------------------------------------------------------------+
void Label_MQL5(string _name,int _window,int _x,int _y,string _text,int _font,color _color,int corner)
  {
   //corner=4;
   ObjectDelete(0,_name);
   ObjectCreate(0,_name,OBJ_LABEL,_window,0,0);
   ObjectSetInteger(0,_name,OBJPROP_CORNER,corner);
   ObjectSetInteger(0,_name,OBJPROP_XDISTANCE,_x);
   ObjectSetInteger(0,_name,OBJPROP_YDISTANCE,_y);
   ObjectSetText(_name,_text,_font,"Arial",_color);
  }  


If anyone knows how to get left and right alignment in MT5, please share the appropriate feature!

 
Artyom Trishkin:

The counting starts from zero.

What prevents you from entering CORNER_LEFT_UPPER instead of a number? That's what enumeration is for, so you don't have to think about numbers.

From zero? Well, OK - let it be zero - I didn't take it into account - but it still doesn't work!

Because it makes more sense to me and I've used it before.

 
Aleksey Vyazmikin:

From scratch? Well, OK - even if it's from scratch - I didn't consider it - but it still doesn't work!

Because it makes more sense to me and I've used it before...

Shall I move up the list item you're trying to identify with number 4, which isn't there? It becomes zero - and everything is in place.

Reason: