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

 
hamsteruser:

*returntick is not being destroyed either. I'm just confused by the trading terminal exhaust. It's writing about uncleared memory.


Give me all the code where you use the pointer returned by the function and the moment when you destroy the pointer. It's so hard to help you.

 
Anatolij Povoroznyj:

Hello. Please help me to correct the code. I need the EA not to open a series of orders, but only one order on the first event.

Now it works this way: when CCI crosses the line 200 downwards, this opens a BAY, then if CCI crosses 200 downwards again, this opens another BAY, etc., etc., until CCI crosses the line -200 upwards, then all the BAY are closed and a Sell is opened.

What I want to ask: when SSI crosses the line 200 from top to bottom - the first and only BAI opens, other BAIs should not open until SSI crosses the line -200 from bottom to top, in this case the BAI is closed and a sell is opened. (Mirror the sell line and the -200 line).


Add a function to check if there are any open orders of the relevant type. That is, if there are orders, the function will return true and the next order will not open.

 

Probably off topic...

A wish on MT4

I use many alerts, and they are all set for certain parameters.

I set the lifetime of my alerts as long as necessary and resurrect them to a new target price.

Since my terminal's alert log isn't sorted by symbol or event, searching for the right alert every time is a hassle.

It would be nice to have sorting options like in the "trade" tab

 
hamsteruser:

There is a function with a pointer:


I still call it in another function:


How do I clear the memory behind it?

On delete(TickReturn); I get an error operand excepted.

TickReturn* rt = returntick( period, 1 );

int timeis = rt.curtime;

delete rt;
 
MMM1972:

Probably not the point...

A wish on MT4

I use many alerts, and they are all set for certain parameters.

I set the lifetime of my alerts as long as necessary and resurrect them to a new target price.

Since my terminal's alert log isn't sorted by symbol or event, searching for the right alert every time is a hassle.

It would be nice to have sorting options like in the "trade" tab

The MT4 terminal is no longer being developed. Only bugs found are being fixed.

 
Алексей Барбашин:

Give all the code where you use the pointer returned by the function and the moment when you destroy the pointer. It's so hard to help you.

The memory is really flowing.

  class TickReturn

   {

   public:

      int curtime;

      double open;

      double close;

      double high;

      double low;

      double priceask;

      double pricebid;

      

   };



  TickReturn *returntick(int period, int timeposition)

   {

      TickReturn *returntick = new TickReturn();

      MqlRates rates[];

      MqlTick last_tick;

      

      if(SymbolInfoTick(symbol,last_tick)){}

      else Print("SymbolInfoTick() failed, error = ",GetLastError());

      

      //int timeposition=0;

      ArraySetAsSeries(rates,true);

      ArrayResize(rates,1);

      int copied=CopyRates(symbol,period,timeposition,1,rates);

      

      returntick.curtime = rates[0].time;

      returntick.open = rates[0].open;

      returntick.close = rates[0].close;

      returntick.high = rates[0].high;

      returntick.low = rates[0].low;

      returntick.priceask = last_tick.ask;

      returntick.pricebid = last_tick.bid;

      

      return(returntick);

}

void OnTick() { int period = 15; int timeis = returntick(period, 1).curtime; Print("timeis= ", TimeToStr(timeis,TIME_SECONDS)); Вот здесь пытаюсь уничтожить указатель. }

 
hamsteruser:

The memory is really flowing.


void OnTick() { int period = 15; int timeis = returntick(period, 1).curtime; Print("timeis= ", TimeToStr(timeis,TIME_SECONDS)); This is where I try to destroy the pointer }


It's not quite clear what exactly can be destroyed here. No wonder that memory leaks. What is a pointer? A pointer is a reference to the memory address where the created dynamic variable is stored. In fact, you call the procedure of getting a pointer to the class variable, in this procedure the class object is created, placed in memory, then the pointer is returned to the function of getting the ticks and.... is destroyed when you exit the function. Note that the pointer is destroyed, but the memory is not cleared! And with each new tick more and more memory is eaten up! To avoid this point in your code, you should first of all remove the abbreviation and place the pointer into another variable:TickReturn* temptick =returntick(period, 1);// get the pointer and place it into a variable int timeis = temptick.curtime; // Get the required value from the object by the pointer ...... delete temptick; // Destroy the pointer and clear the memory

And before destroying the pointer, it's better to check if it's correct to avoid the delete error.

On the whole, I wouldn't bother with the pointers and the class in particular, as the task is much easier in fact and there's no need to use the class. Create structure with needed fields, declare global variable with type of this structure, make function to update information in this structure on every tick and collect from it what you need, because variable will be global, you won't need to run it through functions and you won't need pointers.

 

1.Is it possible to use mql4 to disable other EAs?

2. To check if there is an Expert Advisor running on a given ChartId?

 
Sergey Likho:

1.Is it possible to use mql4 to disable other EAs?

2. Check if there is an Expert Advisor running on a given ChartId?


It is possible to disable trading inside the EA code, and make a switch in an external file, then another EA will be able to inform any EA that trading is no longer needed.

 
Aleksey Vyazmikin:

You can prohibit trading inside the EA code, and make the switch in the external file, then another EA will be able to tell any EA that trading is no longer needed.


The idea is exactly that EA A will disable EA B by condition.

Reason: