Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1042

 
Vladimir Karputov:

There is no MQL5 function that would give out mouse coordinates. But you can use the following solution: based on attached file - add saving of last mouse coordinates to OnChartEvent and then, when clicked, output these coordinates.

Got it, thanks

 

There's also some confusing problem with the ebjects.

There is a class that creates a label and a rectangle based on input parameters.

There is a state - on/off by colour of rectangle.

//+------------------------------------------------------------------+
//|                                                CreateLabels.mqh |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
class CreateKeyStateLabel{
private:
   string label_text;
   int x;
   int y;
   bool _state;
public:
   CreateKeyStateLabel(string label_text, int x, int y){
      this.label_text = label_text;
      this.x = x;
      this.y = y;
      _state = false;
      ObjectCreate(0,label_text+"_icon", OBJ_RECTANGLE_LABEL, 0, 1, 1);
      ObjectSetInteger(0,label_text+"_icon", OBJPROP_XDISTANCE, x);
      ObjectSetInteger(0,label_text+"_icon", OBJPROP_YDISTANCE, y);
      ObjectSetInteger(0,label_text+"_icon", OBJPROP_XSIZE, 15);
      ObjectSetInteger(0,label_text+"_icon", OBJPROP_YSIZE, 15);
      ObjectSetInteger(0,label_text+"_icon", OBJPROP_BGCOLOR, clrDarkGray);
      
      ObjectCreate(0,label_text+"_label",OBJ_LABEL,0,1,1);
      ObjectSetInteger(0,label_text+"_label", OBJPROP_XDISTANCE, x+17);
      ObjectSetInteger(0,label_text+"_label", OBJPROP_YDISTANCE, y);
      ObjectSetInteger(0,label_text+"_label", OBJPROP_COLOR, clrBlack);
      ObjectSetString(0,label_text+"_label", OBJPROP_TEXT, label_text);
   }
   
   ~CreateKeyStateLabel(){
      ObjectDelete(0,label_text+"_icon");
      ObjectDelete(0,label_text+"_label");
   }
   
   void invert(){
      if(_state){
         _state = false;
         ObjectSetInteger(0,label_text+"_icon", OBJPROP_BGCOLOR, clrDarkGray);
      }else{
         _state = true;
         ObjectSetInteger(0,label_text+"_icon", OBJPROP_BGCOLOR, clrDarkGreen);
      }
   }
   
   bool state(){
      return _state;
   }
   
};

Then I create these objects, make an event on pressing a key, which would toggle the state.
The first couple of times it works - and then it just ignores the keystrokes, what am I doing wrong?


//+------------------------------------------------------------------+
//|                                                       Events.mq5 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#include <CreateLabels.mqh>
#define  X_DIST 10
#define  Y_DIST 20

CreateKeyStateLabel *tilda = new CreateKeyStateLabel("Tilda",X_DIST,Y_DIST);


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   delete tilda;
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+
void OnChartEvent(const int id, const long   &lparam, const double &dparam, const string &sparam){
   switch(id){
      case CHARTEVENT_KEYDOWN:{
         if(lparam == "38") tilda.invert();
         break;
      }
   }
}

Here I've seen that it works every once in a while, how do I make it work clearly for each click of the toggle?

 
Vladimir Karputov:

There is no MQL5 function that would give out mouse coordinates. But you can use the following solution: based on the attached file, add to OnChartEvent saving the last coordinates of the mouse and then, when you click the button, output these coordinates.

And so

//---------------------------------------  

   if(id==CHARTEVENT_MOUSE_MOVE)
     {
      ChartXYToTimePrice(0,int(lparam),int(dparam),window,time,price);
      Comment("price = ",DoubleToString(price,5),"   time = ",TimeToString(time,TIME_DATE|TIME_MINUTES));
     }

//---------------------------------------
 
Dano already available tick history for tester in MT-5, but high candles still count at bid price. It would be a good advantage to MT-4 to have the high count at ask price and draw the candlesticks that way. Even on 5 min. spread is about 1 APR, or even 1.5! And what a pain to add a spread to all the hikes in the Expert Advisor code! This is a suggestion to improve it, but here's a question: there is a variable high in the MqlRates structure. At what price it is filled. It seems to me that it is not at maximum price like it is written in the manual. Maybe someone knows, I'm too lazy to write an EA for research.
 

Dear Sirs, what is this and where to look for the error?

2019.05.12 11:01:09.743 Core 6  genetic pass (52, 487) tested with error "some error after pass finished" in 0:00:00.005
Can it be related toTesterStop()? Although no, the error is after the pass...
 

Hello.
Can you please advise whether it is possible to write an MQL5 indicator with notifications to Telegram (bot) without using any third-party services, but only MQL5+Telegram API?

Or I need to write an Expert Advisor for that? I ask this question, I tried to write such an EA for MT4, and it turned out somehow only with an Expert Advisor.


And the second question.
How difficult is it to write an indicator/advisor that will signal a certain pattern I need?
For example, two bearish candlesticks followed by three bullish ones?

I understand it like this (roughly):
Closing price < opening price = bearish candle
Close price>opening price = a bullish candlestick

If I can't do it myself, I'll probably order it for money))

Thank you for your attention!

 

Is it possible to compile code intoex from a third-party program?

I'm creating some sort of robot constructor in Java, and I'd like the user to get the compiled code instead of accessing the source code.

 
Roman Sharanov:

Is it possible to compile code intoex from a third-party program?

I'm creating some sort of robot constructor in Java, and I'd like the user to get the compiled code instead of accessing the source code.

Yes, see MetaEditor's help: Welcome to Algorithm / Integration with other IDEs / Compiling MQL programs in other IDEs
 

Does anyone know? I'm working on transferring data from Excel spreadsheets to MQL5 scripts. Everything seems fine, but EXcel has decimal data with a comma instead of a dot.

Question: Is there a mechanism in MQL for script to take data from Excel and change it to decimal point, or better to change it to decimal point in Excel itself?

How to get data from Excel from the cells I need, because I need to line them up in a column, write macros, etc.? Among the data are both dates and integer and decimal. This Excel is so inconvenient, or I'm just not used to it yet...

I would be glad of any advice...

 
Vladimir M.:

Does anyone know? I'm working on transferring data from Excel spreadsheets to MQL5 scripts. Everything seems fine, but EXcel has decimal data with a comma instead of a dot.

Question: Is there a mechanism in MQL for script to take data from Excel and change it to decimal point, or better to change it to decimal point in Excel itself?

How to get data from Excel from the cells I need, because I need to line them up in a column, write macros, etc.? Among the data are both dates and integer and decimal. This Excel is so inconvenient, or I'm just not used to it yet...

I would be glad of any advice...

MQL has a character replacement function in a string. Read as string

int  StringReplace(
   string&         str,              // строка, в которой будет осуществляться замена
   const string    find,             // искомая подстрока НАЙТИ ЗАПЯТУЮ ","
   const string    replacement       // подстрока, которая будет вставлена в найденные места ЗАМЕНИТЬ НА ТОЧКУ "."
   );

and convert it to double type

Документация по MQL5: Строковые функции / StringReplace
Документация по MQL5: Строковые функции / StringReplace
  • www.mql5.com
Строковые функции / StringReplace - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5