Questions from Beginners MQL5 MT5 MetaTrader 5 - page 982

 

There is the following code, which draws an input box on the chart with the text "Take Profit" aligned to the centre:

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   Edit();
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   EditDel();
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+ 
//| Создает объект "Поле ввода"                                      | 
//+------------------------------------------------------------------+ 
void EditCreate(ENUM_BASE_CORNER corner,string name,int x,int y,int width,int height,string text,
                int font_size,ENUM_ALIGN_MODE align,bool read_only,color back_clr)
  {
   long cid=ChartID();
   int subWind=0;
   string font="Consolas";
   color text_color=clrBlack;
   color border_clr=clrDimGray;
   bool back=false;
   bool selectable=false;
   bool selected=false;
   bool hidden=true;
   long zorder=0;
   if(ObjectFind(cid,name)==-1)
     {
      ObjectCreate(cid,name,OBJ_EDIT,subWind,0,0);
      ObjectSetInteger(cid,name,OBJPROP_XDISTANCE,x);
      ObjectSetInteger(cid,name,OBJPROP_YDISTANCE,y);
      ObjectSetInteger(cid,name,OBJPROP_XSIZE,width);
      ObjectSetInteger(cid,name,OBJPROP_YSIZE,height);
      ObjectSetString(cid,name,OBJPROP_TEXT,text);
      ObjectSetString(cid,name,OBJPROP_FONT,font);
      ObjectSetInteger(cid,name,OBJPROP_FONTSIZE,font_size);
      ObjectSetInteger(cid,name,OBJPROP_ALIGN,align);
      ObjectSetInteger(cid,name,OBJPROP_READONLY,read_only);
      ObjectSetInteger(cid,name,OBJPROP_CORNER,corner);
      ObjectSetInteger(cid,name,OBJPROP_COLOR,text_color);
      ObjectSetInteger(cid,name,OBJPROP_BGCOLOR,back_clr);
      ObjectSetInteger(cid,name,OBJPROP_BORDER_COLOR,border_clr);
      ObjectSetInteger(cid,name,OBJPROP_BACK,back);
      ObjectSetInteger(cid,name,OBJPROP_SELECTABLE,selectable);
      ObjectSetInteger(cid,name,OBJPROP_SELECTED,selected);
      ObjectSetInteger(cid,name,OBJPROP_HIDDEN,hidden);
      ObjectSetInteger(cid,name,OBJPROP_ZORDER,zorder);
      ChartRedraw(cid);
     }
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void Edit()
  {
   long cid=ChartID();
   if(ObjectFind(cid,"edit tp")<0)
     {
      EditCreate(CORNER_LEFT_UPPER,"edit tp",50,50,150,20,"Take Profit",12,ALIGN_CENTER,true,clrBeige);
     }
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void EditDel()
  {
   long cid=ChartID();
   ObjectDelete(cid,"edit tp");
  }
//+------------------------------------------------------------------+

When running in real time, it works correctly:

In the strategy tester, the alignment is on the left side for some reason.


In MT4, the code works correctly both in real time and in the Strategy Tester. I see such tricks only in MT5...

What may be the problem?

 
Oleg Remizov:

There is the following code, which draws an input box on the chart with the text "Take Profit" aligned to the centre:

When running in real time, it works correctly:

In the strategy tester, the alignment is on the left side for some reason.


In MT4, the code works correctly both in real time and in the Strategy Tester. I see such tricks only in MT5...

What may be the problem?

In the tester of MT5, it was already mentioned many times on the forum.

 

Good afternoon to all. Gentlemen, please advise how to handle simultaneous pressing of keyboard button and mouse button.For example, pressing the button draws an object, and pressing the same + left mouse button would draw another object.But it turns out that when you press the keyboard button and mouse button, 2 objects are drawn.

if(lparam==49)
 {
 ObjectCreate(0,"line",OBJ_TREND,0,time1,price1,time1+86400,price1);
 ChartRedraw(0);
 }
if(lparam==49 &&В MouseK==1)
 {
 ObjectCreate(0,"Marg",OBJ_LABEL,0,0,0);
 ObjectSetInteger(0,"Marg",OBJPROP_XDISTANCE,280); 
 ObjectSetInteger(0,"Marg",OBJPROP_YDISTANCE,20); 
 ChartRedraw(0);
 }  
 

I am working from the following article:

https://www.mql5.com/ru/articles/4149

and there are a couple of things in the code that I don't understand, please explain the meaning

1. Why is the ::(scope resolution) operator used?

void OnStart()
  {
//---
   Test();
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Test                                                             |
//+------------------------------------------------------------------+
bool Test()
  {

   string pStream;
   string sources_filename="Websorce.txt";

   int hFile,iStringSize;

// read file contents 
   hFile=::FileOpen(sources_filename,FILE_TXT|FILE_READ|FILE_UNICODE);
   if(hFile==INVALID_HANDLE)
     {
      ::Print("error opening file "+sources_filename);
      return(false);
     }

   while(!::FileIsEnding(hFile))
     {


2. what does this code line "_errCode |= code" do? (I know this operator is bitwise "or" the same as "_errCode =_errCode |code")


class JSONParser {
    private:
        int _pos;
        ushort _in[];
        int _len;
        string _instr;
        int _errCode;
        string _errMsg;
      

        void setError(int code=1,string msg="unknown error") {
          string _str = NULL;
            _errCode |= code;
Создание пользовательской новостной ленты в MetaTrader 5
Создание пользовательской новостной ленты в MetaTrader 5
  • www.mql5.com
В терминале MetaTrader 5 есть множество полезных функций, которые могут пригодиться пользователю, независимо от его стиля торговли, включая и возможность доступа к ленте оперативных новостей. Это дает трейдеру торговый контекст, значимость которого сложно переоценить, ведь он может оказать влияние на рынки. Единственное ограничение — объем...
 
Hello, there is an advisor in the base for mt4 which can be used as a manual trading simulator in the tester. It's not a bad simulator. I want to ask a question. Is it possible to make such a trainer EA multitime. Can I use it on MT4 or on MT5?
 
bahtiyar:
Hello there is an advisor in the base for mt4 which can be used as a manual trading simulator in the tester. It's not a bad simulator. I want to ask a question. Is it possible to make such a trainer EA multitime. On MT4 or on MT5?

You may. For MT5 it is also multicurrency, but with some limitations. Unfortunately, the tester does not work with graphics. More exactly, it does not allow editing graphical objects manually.

 
Alexey Viktorov:

You can. And for mt5 it is also multi-currency, but with some limitations. Unfortunately, the tester does not work with graphics. To be more precise, it does not allow to edit graphical objects manually.

Thank you for your reply Alexey! You have answered what you can do. I want to clarify my question. Is it possible to make the visualization so that I could analyse several timeframes, because the tester will be used as a manual trading simulator? If so, how can I do this in general7
 
bahtiyar:
Thank you for your reply Alexey! You have answered what can be done. I would like to clarify my question. Is it possible to make the visualisation so that I can analyse several timeframes, because the tester will be used as a manual trading simulator. if possible how can this be done in general terms7

No way

 
bahtiyar:
Thank you for your reply Alexey! You have answered what can be done. I want to fix my question. Can I analyze several timeframes in visualization, because the tester will be used as a manual trading simulator?
Vitaly Muzichenko:

No way

You cannot do it on MT4. You can adjust charts so that you can look through the history up to the necessary depth.

On MT5 the tester loads all symbols and all TFs that are accessed from the program along with indicators if they are used in the code.

But in any case, you'll need a special indicator to "jump" over charts so that you don't want to trade. Or the speed will have to be such that it will not differ much from the real one.

 

How much does the Optimize flag in the meta-editor config help speed up program execution? I've got something of a slow test... How much effect does this Optimize have?

Unfortunately, I can't use it because of the crash when adding instances to the CDictionary object.

Reason: