Errors, bugs, questions - page 2737

 

In MT4, while debugging indicators, the debugger hangs permanently if you switch to a chart.

Reproduced, for example, during start of debugging of standard CCI indicator.

1. Set a breakpoint;

2. Press F5;

3. Switch to the graph.

Result - the debugger graph hangs.

You can also simply press F5 several times during debugging - the chart hangs.

Build 1260.

Debugger settings:


 
Comments not related to this topic have been moved to "Questions from MQL4 MT4 MetaTrader 4 beginners".
 

The search result deletes some of the text.


Here is the original.

Forum on trading, automated trading systems and strategy tester

MetaTrader 5 Strategy Tester: bugs, bugs, suggestions for improvement

fxsaber, 2020.05.11 20:31

It probably doesn't make sense for Tester to create opt-files that have Header.passes_passed== 0.
 
Very rarely work with graphical objects, the need to color the background for OBJ_LABLE (set OBJPROP_BGCOLOR) arose.
As it turned out, setting the background colour is not possible for an object of OBJ_LABLE type, it is necessary to use OBJ_EDIT.
When using OBJ_EDIT, a new problem has arisen - the need to set the size of OBJPROP_XSIZE and OBJPROP_YSIZE so that all text fits into the corresponding object dimensions.

Question: how to determine the OBJPROP_XSIZE and OBJPROP_YSIZE sizes to fit the whole text?
I considered two options:
1. Creating OBJ_LABLE object, reading its dimensions, deleting OBJ_LABLE object.
Not suitable because dimensioning is only possible after the object has actually been created and is not possible when the object is in the ChartRedraw queue.

2. using TextSetFont followed by TextGetSize.
Not suitable, because the result is radically different from the results of method #1, the difference of 2.5 - 2.9 times, depending on the size of the font.
Probably the reason is 4K monitor and 175% DPI.

#define  PRINT(x) ; Print(#x, ":", string(x))
          
void SetLabel(long achart, string name, int wnd, string text, color clr, int x, int y, int corn=0, int fontsize=8, string font="Tahoma")
{
   ObjectCreate(achart, name, OBJ_LABEL, wnd, 0, 0); 
   ObjectSetInteger(achart, name, OBJPROP_CORNER, corn); 
   ObjectSetString(achart, name, OBJPROP_TEXT, text); ObjectSetInteger(achart, name, OBJPROP_COLOR, clr); 
   ObjectSetInteger(achart, name, OBJPROP_FONTSIZE, fontsize); ObjectSetString(achart, name, OBJPROP_FONT, font);
   ObjectSetInteger(achart, name, OBJPROP_SELECTABLE, false); 
   ObjectSetInteger(achart, name, OBJPROP_BORDER_TYPE, 0);
   ObjectSetInteger(achart, name, OBJPROP_XDISTANCE, x); ObjectSetInteger(achart, name, OBJPROP_YDISTANCE, y);
}

void OnStart(){     
   string obj_name = "test_obj";   
   string text = "AAAA::BBBB";
   int font_size = 7;
   string font_name = "Tahoma";
   
   SetLabel(0, obj_name, 0, text, clrWhite, 100, 100, 0, font_size, font_name);
   ChartRedraw(0);
   Sleep(1000);
   
   uint dx_fixed_0 = int(ObjectGetInteger(0, obj_name, OBJPROP_XSIZE));
   uint dy_fixed_0 = int(ObjectGetInteger(0, obj_name, OBJPROP_YSIZE));
   ObjectDelete(0, obj_name);
   
   PRINT(dx_fixed_0);
   PRINT(dy_fixed_0);
   
   
   uint dx_fixed_1;
   uint dy_fixed_1;
   TextSetFont(font_name, -10 *  font_size);
   TextGetSize(text, dx_fixed_1, dy_fixed_1);
   
   PRINT(1.0 * dx_fixed_0 / dx_fixed_1);  	// Result: 1.0
   PRINT(1.0 * dy_fixed_0 / dy_fixed_1);  	// Result: 1.0
}  


Thanks toGeess for thesolution.
It is necessary to multiply by -10 the size of the shuffle when passing it to TextSetFont.

 
Sergey Dzyublik:
I rarely work with graphical objects, I need to paint the background color for OBJ_LABLE (set OBJPROP_BGCOLOR).
As it turned out, setting the background colour is not possible for an object of OBJ_LABLE type, it is necessary to use OBJ_EDIT.
When using OBJ_EDIT, a new problem has arisen - the need to set the size of OBJPROP_XSIZE and OBJPROP_YSIZE so that all text fits into the corresponding object dimensions.

Question: how to determine the OBJPROP_XSIZE and OBJPROP_YSIZE sizes to fit the whole text?
I have considered two options:
1. Create OBJ_LABLE object, read the dimensions, delete OBJ_LABLE object.
Not suitable because dimensioning is only possible after the object has actually been created and is not possible when the object is in the ChartRedraw queue.

2. using TextSetFont followed by TextGetSize.
Not suitable, because the result is radically different from the results of method #1, the difference of 2.5 - 2.9 times, depending on the size of the font.
Probably the reason is 4K monitor and 175% DPI.

Firstly, text size and object size are not the same thing. At the very least there has to be a border. And therefore these values can't coincide.
Secondly, it is better to use OBJ_BITMAP_LABEL which has no limitations.
And if you do use it, it is better to use CCanvas class.

#include <Canvas\Canvas.mqh>
          
void SetLabel(CCanvas &c, long achart, string name, int wnd, string text, color clr_text, color clr_bckgrnd, int x, int y, int corn=0, int fontsize=8, int border=2, string font="Tahoma", uchar transparency=0xFF)
{
   uint w,h;
   c.FontSet(font, fontsize);
   c.TextSize(text, w, h);
   if(!c.CreateBitmapLabel(achart,wnd,name,x,y,w+border*2,h+border*2,COLOR_FORMAT_ARGB_NORMALIZE))
      Print("Error creating canvas object: ", GetLastError());
   c.Erase(ColorToARGB(clr_bckgrnd,transparency));
   c.TextOut(border,border,text,ColorToARGB(clr_text,transparency));
   c.Update();
}

void OnStart(){     
   string obj_name = "test_obj";   
   string text = "AAAA::BBBB";
   int font_size = 17;
   string font_name = "Tahoma";
   CCanvas Can;
   SetLabel(Can,0, obj_name, 0, text, clrYellow, clrBlue, 100, 100, 0, font_size,3, font_name, 0x80);
   Sleep(10000);
   Can.Destroy();
}  

The result is the same object, only with more possibilities. For example, by adding transparency to the text label.


 
Geess:

Firstly, text size and object size are not the same thing. At a minimum, there must be a border. And so these values cannot coincide.

Thank you very much for your help.
You are adapting a ready-made solution to your own needs, so I don't see the need to implement libraries.
The solution you originally proposed can be represented as:

void SetBitmapLabel(long achart, string name, int wnd, string text, color clr, color bgclr, int x, int y, int corn=0, int fontsize=8, string font="Tahoma", int border=2)
{
   uint w,h;
   TextSetFont(font,-10* fontsize,0,0);
   TextGetSize(text,w,h);
   w = w+border*2;
   h = h+border*2;
   
   uint pixels[];
   ArrayResize(pixels,w*h);
   ArrayInitialize(pixels,0);
   ENUM_COLOR_FORMAT color_format = COLOR_FORMAT_XRGB_NOALPHA;
   string resource_name="::"+name+(string)ChartID()+(string)(GetTickCount()+MathRand());
   
   ResourceCreate(resource_name,pixels,w,h,0,0,0,color_format);
   ObjectCreate(achart,name,OBJ_BITMAP_LABEL,wnd,0,0);
   ObjectSetInteger(achart,name,OBJPROP_XDISTANCE,x);
   ObjectSetInteger(achart,name,OBJPROP_YDISTANCE,y);
   ObjectSetString(achart,name,OBJPROP_BMPFILE,resource_name);
   ArrayInitialize(pixels,ColorToARGB(bgclr));
   TextOut(text,border,border,0,pixels,w,h,ColorToARGB(clr),color_format);
   ResourceCreate(resource_name,pixels,w,h,0,0,0,color_format);
}

void SetLabel(long achart, string name, int wnd, string text, color clr, int x, int y, int corn=0, int fontsize=8, string font="Tahoma")
{
        ObjectCreate(achart, name, OBJ_LABEL, wnd, 0, 0); 
        ObjectSetInteger(achart, name, OBJPROP_CORNER, corn); 
        ObjectSetString(achart, name, OBJPROP_TEXT, text); ObjectSetInteger(achart, name, OBJPROP_COLOR, clr); 
        ObjectSetInteger(achart, name, OBJPROP_FONTSIZE, fontsize); ObjectSetString(achart, name, OBJPROP_FONT, font);
        ObjectSetInteger(achart, name, OBJPROP_SELECTABLE, false); 
        ObjectSetInteger(achart, name, OBJPROP_BORDER_TYPE, 0);
        ObjectSetInteger(achart, name, OBJPROP_XDISTANCE, x); ObjectSetInteger(achart, name, OBJPROP_YDISTANCE, y);
}

void OnStart(){     
   string obj_name = "test_obj";   
   string text = "AAAA::BBBB";
   int font_size = 50;
   string font_name = "Tahoma";
   
   SetBitmapLabel(0, "BL" + obj_name, 0, text, clrRed, clrWhite, 100, 100, 0, font_size, font_name);
   SetLabel      (0, "L"  + obj_name, 0, text, clrRed,           100, 200, 0, font_size, font_name);
   ChartRedraw(0);
   Sleep(10000);
}  


Unfortunately, because of a defect in MT5 - the proposed solution cannot be used normally.
The text size turns out to be 3 times smaller than needed on a 4K monitor with 175% Windows DPI.
I have to multiply font size by DPI / 100% * [1.6 ... 1.8]

ThanksGeessfor thesolution.
You have to multiply the font size by -10 when passing it toTextSetFont.




 
Sergey Dzyublik:

Thank you very much for your help.
You are adapting a ready-made solution to your own needs, so I don't see the need to implement libraries.
The solution you originally proposed can be represented as:


Unfortunately, because of a defect in MT5 - the proposed solution cannot be used normally.
The text size turns out to be 3 times smaller than needed on a 4K monitor with 175% Windows DPI.
I have to multiply font size by DPI / 100% * [1.6 ... 1.8].

https://www.mql5.com/ru/docs/objects/textsetfont


you have to do it like this:

void SetBitmapLabel(long achart, string name, int wnd, string text, color clr, color bgclr, int x, int y, int corn=0, int fontsize=8, string font="Tahoma", int border=2, uchar transparency=0xFF)
{
   uint w,h;
   TextSetFont(font,-10*fontsize,0,0);
   TextGetSize(text,w,h);
   w = w+border*2;
   h = h+border*2;
   
   uint pixels[];
   ArrayResize(pixels,w*h);
   ArrayInitialize(pixels,0);
   ENUM_COLOR_FORMAT color_format = COLOR_FORMAT_ARGB_NORMALIZE;
   string resource_name="::"+name+(string)ChartID()+(string)(GetTickCount()+MathRand());
   
   ResourceCreate(resource_name,pixels,w,h,0,0,0,color_format);
   ObjectCreate(achart,name,OBJ_BITMAP_LABEL,wnd,0,0);
   ObjectSetInteger(achart,name,OBJPROP_XDISTANCE,x);
   ObjectSetInteger(achart,name,OBJPROP_YDISTANCE,y);
   ObjectSetString(achart,name,OBJPROP_BMPFILE,resource_name);
   ObjectSetInteger(achart,name,OBJPROP_BACK,false);
   ArrayInitialize(pixels,ColorToARGB(bgclr, transparency));
   TextOut(text,border,border,0,pixels,w,h,ColorToARGB(clr, transparency),color_format);
   ResourceCreate(resource_name,pixels,w,h,0,0,0,color_format);
}

void SetLabel(long achart, string name, int wnd, string text, color clr, int x, int y, int corn=0, int fontsize=8, string font="Tahoma")
{
        ObjectCreate(achart, name, OBJ_LABEL, wnd, 0, 0); 
        ObjectSetInteger(achart, name, OBJPROP_CORNER, corn); 
        ObjectSetString(achart, name, OBJPROP_TEXT, text); ObjectSetInteger(achart, name, OBJPROP_COLOR, clr); 
        ObjectSetInteger(achart, name, OBJPROP_FONTSIZE, fontsize); ObjectSetString(achart, name, OBJPROP_FONT, font);
        ObjectSetInteger(achart, name, OBJPROP_SELECTABLE, false); 
        ObjectSetInteger(achart, name, OBJPROP_BORDER_TYPE, 0);
        ObjectSetInteger(achart, name, OBJPROP_XDISTANCE, x); ObjectSetInteger(achart, name, OBJPROP_YDISTANCE, y);
}

void OnStart(){     
   string obj_name = "test_obj";   
   string text = "AAAA::BBBB";
   int font_size = 50;
   string font_name = "Tahoma";
   
   SetBitmapLabel(0, "BL" + obj_name, 0, text, clrRed, clrBlue, 100, 100, 0, font_size, font_name,2,0xA0);
   SetLabel      (0, "L"  + obj_name, 0, text, clrBlue,         100, 200, 0, font_size, font_name);
   ChartRedraw(0);
   Sleep(10000);
}



I don't understand why you need OBJ_LABEL so much? You have implemented a variant without libraries with OBJ_BITMAP_LABEL. What is its advantage? I see only a limitation.

 
Target
Geess:

https://www.mql5.com/ru/docs/objects/textsetfont
I don't understand why you need OBJ_LABEL so much? You have implemented a variant without libraries with OBJ_BITMAP_LABEL. What is its advantage? I see only a limitation.

Thank you very much again.
Didn't know, didn't see, didn't read, about multiplication by -10. Problem solved.
OBJ_LABEL was used to illustrate the problem and be able to reproduce it.

 
Hello!

Please tell me what the problem is.

Different indicators, which are working correctly and updating, start to show something different in sync, not based on the price chart displayed in the main window. It happens occasionally, not every day.

At first I blamed on indicators, but after trying different ones, including MT5 native ones, I am suspicious about the terminal. I observe the problem for a long time, since last year, on different versions of the terminal. First it was on Alpari custom version, now it is the same on the original version. Both on demo account and on real ecn.

Alpari broker. MT5 build 2363 from 13.03.2020. I don't remember on other periods, but it definitely happens on M1.

Screenshots:

"Slipped" variant. Except for the zigzag, all indicators are built in. The zigzag with correct work with history. Readings of indicators are convergent among themselves. They do not correspond with prices.

After the update.

MT5 version

 

Afternoon.

Stumbled across an incomprehensible thing and don't understand what it is.

There are two functions which are used in different strategies. Logically, the code in checks like

if(m_position.PositionType()==POSITION_TYPE_SELL  && m_position.Magic()==magic)

It should not be executed if one of the conditions is wrong. But for some reason it is executed if the magic number and the magic number passed into the function are NOT EQUAL.

It seems to be an integer type comparison. I cannot understand why. You can see it in the screenshot below.


void OpenNextBuyPositionBySignal(CTrade &m_trade,long magic,double ExtDP,double iuv,double imv,int itp,int isl,double etp,double esl,double ev,double &rev,string numstr,ulong &last_pt)
{
   for(int i=PositionsTotal()-1;i>=0;i--)
     if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
       if(m_position.Symbol()==m_symbol.Name())
       {
          if(m_position.PositionType()==POSITION_TYPE_SELL  && m_position.Magic()==magic)
          {
             if((m_position.Profit()+m_position.Swap()+m_position.Commission())<0)
             {
                if(IsSetBuy(magic,ExtDP)==true)
                {
                    double cdist=MathFloor(MathAbs((m_position.PriceOpen()-m_position.PriceCurrent())/ExtDP));
                    Print("#1122 cdist ",numstr,": ",cdist);
                    Print("#2211! m_position.PriceOpen(): ",m_position.PriceOpen());
                    Print("#2212! m_position.PriceCurrent(): ",m_position.PriceCurrent());
                    Print("#2213! ExtDP: ",ExtDP);
                    Print("#2214! magic: ",magic);
                    Print("#2215! ev: ",ev);
                    Print("#2216! iuv: ",iuv);
                    Print("#2217! m_position.Volume(): ",m_position.Volume());
                    Print("#2218! m_position.Magic(): ",m_position.Magic());
                    
                   
                    if(NormalizeDouble(m_position.Volume()+iuv*cdist,2)<=imv)
                       ev=NormalizeDouble(m_position.Volume()+iuv*cdist,2);
                     if(NormalizeDouble(m_position.Volume()+iuv*cdist,2)>imv)
                        ev=NormalizeDouble(imv,2);
                     rev=ev;
                     double sl=0.0;
                     double tp=0.0;
                     if(itp>0) tp=m_symbol.Ask()+etp;
                     if(isl>0) sl=m_symbol.Bid()-esl;
                     //m_trade.SetExpertMagicNumber(magic);
                     if(OpenBuy(m_trade,ev,sl,tp,numstr))
                     {
                        last_pt=POSITION_TYPE_BUY;
                        FileWrite(filehandle,numstr+", ",TimeCurrent(),", ",GetLastPositionsType(magic),", ",GetPositionTicket(magic,POSITION_TYPE_BUY)); 
                        Print("#516! Position BUY after down SELL "+numstr);                                 
                        //Sleep(3000);
                        continue;
                     }
                  }
               }
            }
            if(m_position.PositionType()==POSITION_TYPE_BUY  && m_position.Magic()==magic)
            {
               if((m_position.Profit()+m_position.Swap()+m_position.Commission())<0)
               {
                  if(IsSetBuy(magic,ExtDP)==true)
                  {
                     double cdist=MathFloor(MathAbs((m_position.PriceOpen()-m_position.PriceCurrent())/ExtDP));
                     Print("#1123 cdist ", numstr," : ",cdist);
                     Print("#3211! m_position.PriceOpen(): ",m_position.PriceOpen());
                     Print("#3212! m_position.PriceCurrent(): ",m_position.PriceCurrent());
                     Print("#3213! ExtDP: ",ExtDP);
                     Print("#3214! magic: ",magic);
                     Print("#3215! ev: ",ev);
                     Print("#3216! iuv: ",iuv);
                     Print("#3217! m_position.Volume(): ",m_position.Volume());
                     Print("#3218! m_position.Magic(): ",m_position.Magic());
                    
                     if(NormalizeDouble(m_position.Volume()+iuv*cdist,2)<=imv)
                        ev=NormalizeDouble(m_position.Volume()+iuv*cdist,2);
                     if(NormalizeDouble(m_position.Volume()+iuv*cdist,2)>imv)
                        ev=NormalizeDouble(imv,2); 
                     rev=ev;                          
                     double sl=0.0;
                     double tp=0.0;
                     if(itp>0) tp=m_symbol.Ask()+etp;
                     if(isl>0) sl=m_symbol.Bid()-esl;
                     //m_trade.SetExpertMagicNumber(magic);
                     if(OpenBuy(m_trade,ev,sl,tp,numstr))
                     {
                        last_pt=POSITION_TYPE_BUY;
                        FileWrite(filehandle,numstr+", ",TimeCurrent(),", ",GetLastPositionsType(magic),", ",GetPositionTicket(magic,POSITION_TYPE_BUY)); 
                        Print("#517! Position BUY After down BUY "+numstr);                                 
                        //Sleep(3000);
                        continue;
                     }
                  }
               } 
            }
         }
}


void OpenNextSellPositionBySignal(CTrade &m_trade,long magic,double ExtDP,double iuv,double imv,int itp,int isl,double etp,double esl,double ev,double &rev,string numstr,ulong &last_pt)
{
   for(int i=PositionsTotal()-1;i>=0;i--)
      if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
         if(m_position.Symbol()==m_symbol.Name())
         {
            if(m_position.PositionType()==POSITION_TYPE_BUY  && m_position.Magic()==magic)
            {
               if((m_position.Profit()+m_position.Swap()+m_position.Commission())<0)
               {
                  if(IsSetSell(magic,ExtDP)==true)
                  {
                     double cdist=MathFloor(MathAbs((m_position.PriceCurrent()-m_position.PriceOpen())/ExtDP));
                     Print("#1124 cdist ", numstr," : ",cdist);
                     Print("#4211! m_position.PriceOpen(): ",m_position.PriceOpen());
                     Print("#4212! m_position.PriceCurrent(): ",m_position.PriceCurrent());
                     Print("#4213! ExtDP: ",ExtDP);
                     Print("#4214! magic: ",magic);
                     Print("#4215! ev: ",ev);
                     Print("#4216! iuv: ",iuv);
                     Print("#4217! m_position.Volume(): ",m_position.Volume());
                     Print("#4218! m_position.Magic(): ",m_position.Magic());
                   
                     if(NormalizeDouble(m_position.Volume()+iuv*cdist,2)<=imv)
                        ev=NormalizeDouble(m_position.Volume()+iuv*cdist,2);
                     if(NormalizeDouble(m_position.Volume()+iuv*cdist,2)>imv)
                        ev=NormalizeDouble(imv,2);
                     rev=ev;
                     double sl=0.0;
                     double tp=0.0;
                     if(itp>0) tp=m_symbol.Bid()-etp;
                     if(isl>0) sl=m_symbol.Ask()+esl;
                     //m_trade.SetExpertMagicNumber(magic);
                     if(OpenSell(m_trade,ev,sl,tp,numstr))
                     {
                        last_pt=POSITION_TYPE_SELL;
                        FileWrite(filehandle,numstr+", ",TimeCurrent(),", ",GetLastPositionsType(magic),", ",GetPositionTicket(magic,POSITION_TYPE_SELL)); 
                        Print("#518! Position SELL After down BUY "+numstr);                             
                        //Sleep(3000);
                        continue;
                      }
                   }
                }
             }
             if(m_position.PositionType()==POSITION_TYPE_SELL  && m_position.Magic()==magic)
             {
                if((m_position.Profit()+m_position.Swap()+m_position.Commission())<0)
                {
                   if(IsSetSell(magic,ExtDP)==true)
                   {
                      double cdist=MathFloor(MathAbs((m_position.PriceCurrent()-m_position.PriceOpen())/ExtDP));
                      Print("#1125 cdist ", numstr," : ",cdist);
                      Print("#5211! m_position.PriceOpen(): ",m_position.PriceOpen());
                      Print("#5212! m_position.PriceCurrent(): ",m_position.PriceCurrent());
                      Print("#5213! ExtDP: ",ExtDP);
                      Print("#5214! magic: ",magic);
                      Print("#5215! ev: ",ev);
                      Print("#5216! iuv: ",iuv);
                      Print("#5217! m_position.Volume(): ",m_position.Volume());
                      Print("#5218! m_position.Magic(): ",m_position.Magic());
                    
                      if(NormalizeDouble(m_position.Volume()+iuv*cdist,2)<=imv)
                         ev=NormalizeDouble(m_position.Volume()+iuv*cdist,2);
                      if(NormalizeDouble(m_position.Volume()+iuv*cdist,2)>imv)
                         ev=NormalizeDouble(imv,2); 
                      rev=ev;                             
                      double sl=0.0;
                      double tp=0.0;
                      if(itp>0) tp=m_symbol.Bid()-etp;
                      if(isl>0) sl=m_symbol.Ask()+esl;
                      //m_trade.SetExpertMagicNumber(magic);
                      if(OpenSell(m_trade,ev,sl,tp,numstr))
                      {
                        last_pt=POSITION_TYPE_SELL;
                        FileWrite(filehandle,numstr+", ",TimeCurrent(),", ",GetLastPositionsType(magic),", ",GetPositionTicket(magic,POSITION_TYPE_SELL)); 
                        Print("#519! Position SELL After down SELL "+numstr);                                 
                        //Sleep(3000);
                        continue;
                      }
                   }
                }
             }
          }
}


magazine
Заранее спасибо за ответ.