Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 736

 

Good afternoon!

Can you please tell me if the code compilation can be set in the code itself? Thank you.

 

I am displaying the mouse parameters and the 4 digit price tag in the comments when the wheel is clicked.

As long as the wheel is pressed, the marker runs behind the cursor, but I can't make the same happen when the wheel is released before the mouse is pressed on the LC.

Help me figure this out.


//+------------------------------------------------------------------+ 
//| Expert initialization function                                   | 
//+------------------------------------------------------------------+ 
void OnInit() 
  { 
//--- включение сообщений о перемещении мыши по окну чарта 
   ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,1); 
//--- принудительное обновление свойств графика гарантирует готовность к обработке событий 
   ChartRedraw(); 
  } 
//+------------------------------------------------------------------+ 
//| MouseState                                                       | 
//+------------------------------------------------------------------+ 

string xlabel="Bid";
input color xcolor = clrCrimson;

string MouseState(uint state) 
  { 
   string res; 
   res+="\nML: "   +(((state& 1)== 1)?"DN":"UP");   // mouse left 
   res+="\nMR: "   +(((state& 2)== 2)?"DN":"UP");   // mouse right  
   res+="\nMM: "   +(((state&16)==16)?"DN":"UP");   // mouse middle 
   res+="\nMX: "   +(((state&32)==32)?"DN":"UP");   // mouse first X key 
   res+="\nMY: "   +(((state&64)==64)?"DN":"UP");   // mouse second X key 
   res+="\nSHIFT: "+(((state& 4)== 4)?"DN":"UP");   // shift key 
   res+="\nCTRL: " +(((state& 8)== 8)?"DN":"UP");   // control key 
   res+="\nBID" + DoubleToString(SymbolInfoDouble(Symbol(), SYMBOL_BID), _Digits-1);
   return(res); 
  }
   
//+------------------------------------------------------------------+ 
//| ChartEvent function                                              | 
//+------------------------------------------------------------------+ 
void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam) 
  { 
  
int x=(int)lparam; 
int y=(int)dparam; 
datetime dt    =0; 
double   price =0;
int      window=0;

   if(id==CHARTEVENT_MOUSE_MOVE) 
      Comment("POINT: ",(int)lparam,",",(int)dparam,"\n",MouseState((uint)sparam)); 

   if(sparam =="16")
      {
         
      if(!ObjectCreate(0, xlabel, OBJ_LABEL,0, 0, 0));
      //ObjectCreate(0, xlabel, OBJ_LABEL,0, 0, 0);
      ObjectSetInteger(0, xlabel, OBJPROP_XDISTANCE, 100);
           ObjectSetInteger(0, xlabel, OBJPROP_YDISTANCE, dparam+7);
      ChartXYToTimePrice(0,x,y,window,dt,price);
      ObjectSetString(0, xlabel, OBJPROP_TEXT, DoubleToString(price, _Digits-1));
      }
      
      
  /*  while(sparam !="1")
      {
         ObjectMove(0,xlabel,0,lparam,dparam+7);      
      }
  */
  }
  
void OnDeinit(const int reason) 
   { 
      Comment("");
      ObjectDelete(0,xlabel);
   } 
 
psyman:

I am displaying the mouse parameters and the 4 digit price tag in the comments when the wheel is clicked.

As long as the wheel is pressed, the marker runs behind the cursor, but I can't make the same thing happen when the wheel is released before the mouse is pressed on the LK.

remove (commented out)
// if(sparam =="16")

 
Taras Slobodyanik:

remove (commented out)
// if(sparam =="16")


Then the marker is on the screen all the time, while you want it to appear only when you press the wheel.



PS

Your reply has given me the right idea thank you :-)

 
psyman:

I am displaying the mouse parameters and the 4 digit price tag in the comments when the wheel is clicked.

While the wheel is pressed, the marker runs behind the cursor, but I can't make the same thing happen when the wheel is released before the mouse is pressed on the LK.

Help me figure this out.


if(label)
{
   //применение изменяющихся параметров(перемещение и прочее)
}
if(sparam =="16")
{
   label = true;
   //создание метки и настройка неизменяющихся параметров метки
}
if(sparam =="1") // или какой там символ у ЛК мыши
{
   label = false;
   //удаление/скрытие метки, если нужно
}

label is of bool type

 
Ilya Prozumentov:

label is of the bool type

Can I move it before creating the label?


Now I have another question: I want to place a label to the right side of the screen, this is calculated in OnCalculate

int width = (int)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0);

ObjectSetInteger(0, objname, OBJPROP_XDISTANCE, width); 

Print(width);

It somehow turns out to be at the far left position, while the same calculation in OnChartEvent for another marker gives a correct result.

Why does it cause countdown inversion?

 
psyman:

Can the move be done before the marker is created?


Now I have another question: I want to move a marker to the right side of the screen, this is calculated in OnCalculate

It seems to be in leftmost position for some reason. But the same calculation in OnChartEvent for another marker gives correct result.

Why does the countdown inversion happen?

The label was initially set to false, so no code fragment with moving marker will be executed. But even if it is executed before the label is created nothing will happen, the program will continue to run and the label that is created later won't be affected.

Watch the anchor point, different anchor points will cause different results. You can immediately try to write 0 instead of width and if it behaves as it should, it means that it was a matter of anchor points.

OBJ_LABEL - Типы объектов - Константы объектов - Константы, перечисления и структуры - Справочник MQL4
OBJ_LABEL - Типы объектов - Константы объектов - Константы, перечисления и структуры - Справочник MQL4
  • docs.mql4.com
Следующий скрипт создает и перемещает на графике объект "Текстовая метка". Для создания и изменения свойств графического объекта написаны специальные функции, которые вы можете использовать "как есть" в своих собственных программах. //| Создает текстовую метку                                          |...
 
Ilya Prozumentov:

label is initially set to false, so the piece of code to move the label will not be executed. But even if it is executed before the label is created, nothing will happen, the program will continue to run and the label that is created afterwards will not be affected.

Watch the anchor point, different anchor points will cause different results. You can immediately try to write 0 instead of width and if it behaves as expected, it means that the problem was with the anchor points.

I have no anchor points, I only move vertically, and I set the horizon once, across the width of the screen. It's not a problem to count from the other side, but it's surprising that the same action is performed differently in different functions.


And one more question - if Bid is displayed as the label text, which function should I use to do it optimally -OnChartEvent orOnCalculate?

 
novichok2018:

Good afternoon!

Can you please tell me if the code compilation can be set in the code itself? Thank you.

This may be a silly question since no one is answering, but how else do I deal with the EA stopping and resuming after compilation?

The platform gives the message:array out of range (284,17).

line 284: NewsArr[0][NomNews]=StringSubstr(TEXT,sh,sh2-sh);position 17 opens a square bracket with NomNews, which is globally initiated by 0.

I changed 0 to 1 with no result.
I changed theline if(NomNews==300)break; 300 to 360000, to no av ail.

I compile it - it works fine for a few minutes. And what to do?

 
novichok2018:

This may be a silly question, since no one is answering, but how else do I deal with the EA stopping and resuming after compilation?

The platform gives the message:array out of range (284,17).

Line 284: NewsArr[0][NomNews]=StringSubstr(TEXT,sh,sh2-sh);position 17 opens a square bracket with NomNews, which is globally initiated by 0.

I changed 0 to 1 with no result.
I changed theline if(NomNews==300)break; 300 to 360000, to no av ail.

I compile it - it works fine for a few minutes. And what to do?

What is the dimensionality of the NewsArr array in the second dimension?
Reason: