Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1076

 

How do I read a large file in one line?

FileReadString()

When reading from a bin-file. the length of a string to read must be specified. When reading from a txt-file the string length is not required, and the string will be read from the current position to the line feed character "\r\n". When reading from a csv-file, the string length isn't required also, the string will be read from the current position till the nearest delimiter or till the text string end character.

The only flag for the whole file is FILE_BIN, but in MQL5, unlike in MQL4, it is limited to 4095 bytes. How else can I get a large text from a file on one line?
 
Сергей Таболин:

That's not what I mean.

"And with a logical NOT to solve - invert the bits, but I don't have a terminal - I can't remember how to do a bitwise NOT in MQL, and I don't want to read the online help".

I mean either give me a proof or don't muddy the waters ))))

"Anybody can make a mistake. Only the strong can admit to a mistake!". If no one has voiced it yet, that's my wisdom ))). If someone has already said it - I have repeated the wisdom of a wise man ))))

I still do not understand your claims? You suggesting that I should prove something to you? - Why? ))))

Here I reproduced via NOT and checked all discussed variants:

void OnStart()
  {
//---
   uint TForiginal=OBJ_PERIOD_M1|OBJ_PERIOD_M2|OBJ_PERIOD_M3|OBJ_PERIOD_M4|OBJ_PERIOD_M5|OBJ_PERIOD_M6|OBJ_PERIOD_M10|
                   OBJ_PERIOD_M12|OBJ_PERIOD_M15|OBJ_PERIOD_M20|OBJ_PERIOD_M30|OBJ_PERIOD_H1;

   uint TFwithNOT=(~OBJ_PERIOD_H1&OBJ_PERIOD_H2)-1;
   uint TFwithShift=OBJ_ALL_PERIODS>>9;
   Print("TForiginal = ",TForiginal);
   Print("TFwithNOT = ",TFwithNOT);
   Print("TFwithShift = ",TFwithShift);
  }
//+------------------------------------------------------------------+

NOT variant works with any TF, but fill according to (~TF_ below which we display & TF_one older than required TF)-1;

 

Good day everyone! One more question...

There is an MQL5 program, it has a setting (a lot) of "Input parameters". The program performs calculations and creates / deletes and manages graphical objects as needed.

After the change of input parameters from setup window the eventInit is generated, which leads to program initialization and "recalculate" and "redraw" objects, which is, in principle, what is needed, butthe eventInitis also generated when the chart period is changed (and other), as a result the process repeats every time, even when it is not needed.

Question:How can I exclude program initialization atInit eventifinput parameters are not changed but leave initialization at program (terminal) start?

Possible variant: to remember the set values and compare them when the event Init occursand if they are different allow initialization, but there are a lot of input parameters...

 
Anzhela Sityaeva:

Good day everyone! One more question...

There is an MQL5 program, it has a setting (a lot) of "Input parameters". The program performs calculations and creates / deletes and manages graphical objects as needed.

After the change of input parameters from setup window the eventInit is generated, which leads to program initialization and "recalculate" and "redraw" objects, which is, in principle, what is needed, but the eventInit is also generated when the chart period is changed (and others), as a result the process repeats every time, even when it is not needed.

Question:How can I exclude program initialization atInit eventif input parameters are not changed but leave initialization at program (terminal) start?

Possible variant: to remember the set values and compare them when event Init occursand if they are different to allow initialization, but there are a lot of input parameters...

Here are some tips for another, similar problem

Forum on trading, automated trading systems & strategy testing

Works in EA, but not right in indicator, music when indicator starts

Ihor Herasko, 2019.06.17 14:12

Yes.

  1. When the indicator starts, it creates a global terminal variable. Like - I'm booted up.
  2. A greeting is played.
  3. On unloading (checked in OnDeinit) the global terminal variable is deleted.
  4. If during operation the TF is changed or parameters are changed, then on exit in OnInit the global variable of the terminal is checked. If it is, then the greeting is not played. If not, the greeting is played.

 
Alexey Viktorov:

Here are some tips for another, similar problem



Thanks for the reply, it looks like in our case we will have to keep track of the status of a couple of dozen match changesby describing this through a "blank" on the graph to keep track of their change, or put up with unnecessary initialisation as long as there aren't too many objects...
 
Anzhela Sityaeva:
Thanks for the reply, it looks like in our case we will have to keep track of the state of a couple of dozen changes of correspondences by describing this through a "blank" on the graph to keep track of their changes, or put up with unnecessary initialisation as long as there are not so many objects...

But the question you asked was.

Anzhela Sityaeva:

Good day, everyone! One more question...

There is an MQL5 program, it has settings (a lot) "Input parameters". The program performs calculations and creates / deletes and manages graphical objects as needed.

After the change of input parameters from setup window the eventInit is generated, which leads to program initialization and "recalculate" and "redraw" objects, which is, in principle, what is needed, but the eventInit is also generated when the chart period (and other)is changed , as a result the process repeats every time, even when it is not needed.

Question:How can I exclude program initialization atInit eventif input parameters are not changed but leave initialization at program (terminal) start?

Possible variant: to remember the set values and compare them when event Init occursand if they are different to allow initialization, but there are a lot of input parameters...

And in your situation, one of those tips will prevent these unnecessary redraws of objects. And if these objects are deleted in OnDeinit(), you should prohibit deletion there too when switching the chart.

This is a forum for trading, automated trading systems and strategy testing.

How to delete global variable of the terminal at chart close?

Alexey Viktorov, 2019.06.29 08:40

Pay attention to this table

REASON_PROGRAM

0

Expert stopped working by calling ExpertRemove()

REASON_REMOVE

1

Program removed from the chart

REASON_RECOMPILE

2

Program recompiled

REASON_CHARTCHANGE

3

The chart symbol or period has been changed

REASON_CHARTCLOSE

4

The chart is closed

REASON_PARAMETERS

5

Input parameters were changed by the user

REASON_ACCOUNT

6

Another account was activated or reconnected to the trade server because the account settings were changed

REASON_TEMPLATE

7

Another chart template was applied

REASON_INITFAILED

8

OnInit() handler returned a non-zero value

REASON_CLOSE

9

Terminal was closed


and on this line of your code

   if(reason==1) GlobalVariableDel("val");

But if I remember correctly the beginning of your problem, it is better to put the condition like this

   if(reason != REASON_CHARTCHANGE) GlobalVariableDel("val");

 
Alexey Viktorov:

But in your question it was

In your situation, one of those tips will prevent these unnecessary object redraws. And if these objects are deleted in OnDeinit(), then you should prohibit deletion there as well when switching the chart.


The direction is clear, let's give it a try... Thank you for your reply.
 
I haven't found an EA example in Codebase where a closing condition can be set, not only standard SL/TP. Can someone give me a hint?
 
Sprut112:
I haven't found an EA example in Codebase where a closing condition can be set, not only standard SL/TP. Can someone give me a hint?

What is the difference between opening and closing condition?

 
Sprut112:
I have not found in Codebase an example of an EA where one can write the closing condition of a position, and not only the standard SL/TP. Can someone tell me?

Vladimir Karputov had such conditions in his codes, but you have to learn how to read his code yourself)

Reason: