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

 

How to connect to Meta Quotes servers so that the dll library can send orders and exchange data so that c++ language, not mql4, is involved in EA implementation as much as possible?


Is it possible to draw objects in MT4 using the dll library, what can be learnt about it?

 
Mihail Matkovskij:

But why with iBars(symbol, timeframe) the story turns out to be incomplete, while with iBars(Symbol(), Period()) it is quite normal? And it happens only when the terminal is restarted, not always. And variables symbol, timeframe are initialized correctly, in initialization section (I checked it myself).

Try to squeeze my example:https://c.mql5.com/3/324/Test.mq5

Sequence of actions:

1. Throw the compiled file to the chart. The messages you get when you do this:

2. Terminate the terminal and start it again. The messages in the log will be as follows:

Resolved.

Instead of this code

public:  
  Loader(): symbol(Symbol()), timeframe(Period()) 
  {
    Print(__FUNCTION__ + " symbol: " + symbol + " timeframe: " + EnumToString(timeframe));
    ResetLastError();
    Print(__FUNCTION__ + " bars: " + (string)iBars(symbol, timeframe)); // Данный вызов iBars() даёт 0 при перезапуске терминала
    Print(__FUNCTION__ + " Error: " + (string)GetLastError());
    Print(__FUNCTION__ + " bars (2): " + (string)iBars(Symbol(), Period())); // Этот же вызов iBars() работает нормально
  }

I wrote the following

public:  
  Loader(): symbol(NULL), timeframe(PERIOD_CURRENT) 
  {
    Print(__FUNCTION__ + " symbol: " + symbol + " timeframe: " + EnumToString(timeframe));
    ResetLastError();
    Print(__FUNCTION__ + " bars: " + (string)iBars(symbol, timeframe));
    Print(__FUNCTION__ + " Error: " + (string)GetLastError());
    Print(__FUNCTION__ + " bars (2): " + (string)iBars(Symbol(), Period())); 
  }

Now there are no errors when restarting the terminal. But symbol and timeframe need to be initialized only with empty values.

Here are two versions of the source code, with a bug and a working one. Let me remind you, the sequence of testing is as follows:https://www.mql5.com/ru/forum/160683/page1189#comment_17047032

Files:
Bug.mq5  7 kb
Correct.mq5  6 kb
 
Seric29:

How to connect to Meta Quotes servers so that the dll library can send orders and exchange data so that the implementation of the Expert Advisor involves as much as possible the C++ language and not mql4?

There is no way. The protocol is closed.

Can the dll library draw objects in MT4? What can I study about it?

No, you cannot.

 
Seric29:

Wow, I'll check it out. I know you can initialize variables with array elements with functions, but I didn't know it automatically changes, I don't think there's any such thing in C++ either, I'll check later.

I made a mistake (

If you need to recalculate the lot before trade operations, you'd better place the lot definition at the beginning of OnTick

or (as I changed it) OnTimer

 

Hello! Please help me to output all the values, I can only output the last ones. And the second question, how to output these values with a shift to the right(set any shift). Thank you!

   for(int p = 0; p < 4; p++)
      for(int c = 0; c < 4; c++)
         for(int ps = 0; ps < 4; ps++)
            Comment(StringFormat("Выводим значения\nP = %G\nC = %G\nPS = %d", p, c, ps));
 

Where can I read about delimiters in printing? It's either plus or comma delimiters, I can't understand it, it's tricky

Print(a, b + "abc") ;

 
Koldun Zloy:

Negative. The protocol is closed.

You can't.

What do you mean the protocol is closed. There are order opening functions in mql4, it's essentially just code. The same is true for graphical objects. I heard that mql4 is a commercial product and that's why there is no source code or embedded functions (e.g. Arrayresize/Range etc.). For example, I'm not comfortable using mql4 to write a program, it's too dead language, very limited. What about the language Win API 32, it can not do anything about my questions? I guess everything is closed for Win API 32 as well.

 
Seric29:

What do you mean the protocol is closed. There are order opening functions in mql4, it's essentially just plain code. The same is true for graphical objects. I heard that mql4 is a commercial product and that's why there is no source code or embedded functions (e.g. Arrayresize/Range etc.). For example, I'm not comfortable using mql4 to write a program, it's too dead language, very limited. What about the language Win API 32, it can not do anything about my questions? Probably, everything is locked for Win API 32 as well.

It would be better to make a separate topic, it will be livelier)

 
MakarFX:

I made a mistake(

If you need to recalculate the lot before making a trade operation, it's better to place the lot definition at the beginning of OnTick

or (as I changed it) OnTimer

What I mean is that you initialize "lot" variable with expression, there's no way this expression can be filled in automatically. You can even check it, take a simple counter, assign the counter value during initialization and then change the counter and the value of Lot won't change unless you change it yourself. It works in C++.

int Pomidor=9;
int Pomidor1(int q=Pomidor){return q;}//при инициализации
Вызов
Print(Pomidor());// результат будет автоматически равен Pomidor и это будет регулярная смена значений 

But it doesn't work in mql4, it only works like this

int Pomidor1(int q=67){return q;}

Result 67.

 
Valeriy Yastremskiy:

Better to make a separate topic, it will be livelier)

I was also thinking, the topic is relevant but of course not the fact that it is worth to clog up the forum, maybe it's not interesting for many people. I am interested, I like to write code in C++.

Reason: