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

 

How do you deal with a terminal freeze?

The code is simple, but it's very slow

   for(int i=limit;i>=0;i--)
     {
      RSI_01Buffer[i]=iRSI(NULL,0,RSI_Period,RSI_Price,i);
      RSI_02Buffer[i]=iMAOnArray(RSI_01Buffer,0,MA_Period,0,MODE_SMA,i);
     }
 
 
Alexey Viktorov:

It is easier and safer to put first start flag in OnTick()

It should do calculations and rendering at once, even, for example, on a weekend.

 
Igor Makanu:

I will not guess what will happen, the first thing I see is that you have paused to get the indicator values in OnInit() - what will happen if the user switches the TF at that time?

SZY: And how would your code behave if you run an EA, then close the terminal and reopen the terminal with a running EA?

these variants are considered

 

Please remind me of a trivial thing. My EA opens and closes orders in the tester normally. Now I have been working with the demo for a week already and everything is OK. But in two cases, when opening the second order (Marting), my EA has not closed both of them when the balance is positive, but only one has been struggling with the second one until I have closed the take order. I looked at the log - the pricewas "requoting". Shouldn't seem to be a problem and should close anyway, but it didn't.

So, I haven't written the function SENDING (REQUIRED) OF ORDER CLOSING in the event of a condition. Please tell me how to write this triviality. Thank you.

 
Порт-моне тв:

Please remind me of a trivial thing. My EA opens and closes orders in the tester normally. Now I have been working with the demo for a week already and everything is OK. But in two cases, when opening the second order (for a Mart position) it hasn't closed both of them when the balance is positive, but only one has been struggling with the second one until I have closed the take order. I looked at the log - the pricewas "requoting". Shouldn't seem to be a problem and should close anyway, but it didn't.

So, I haven't written the function SEND (REQUIRED) OF ORDER CLOSING in the event of a condition. Please tell me how to write this triviality. Thank you.

if(GetLastError()==138)OrderClose(...);
or increase the slippage
 
MakarFX:
Or increase the slip.

Thank you for your reply. Why 138???? Is this an error number? And how much to increase the slippage (please explain the meaning of the increase). Thank you

 
Порт-моне тв:

Why 138???? Is it an error number?

Yes

Port mone tv:

And how much to increase the slippage (please explain the meaning of the increase).

It's up to you, the more slippage the less requotes.

 
MakarFX:

How do you deal with a terminal freeze?

The code is simple, but it's very busy.

Strange...

I did it with int start() instead of OnCalculate and it doesn't hang at all

Why?

 
Andrey Sokolov:

It is necessary to make calculations and rendering at once, even, for example, on weekends.

Indicators work in one thread, if one waits, all others wait, until the terminal hangs.
When starting MT, initialization of indicator (-s) can happen before initialization of terminal variables, i.e. it's a piece of cake to catch a hang.

Reason: