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

 

Hello!

Can you please show me how an EA based on Triple Exponential Average indicator can be prohibitedto open a position if the last trade is taken out by SL?

Совершение сделок - Торговые операции - MetaTrader 5
Совершение сделок - Торговые операции - MetaTrader 5
  • www.metatrader5.com
Торговая деятельность в платформе связана с формированием и отсылкой рыночных и отложенных ордеров для исполнения брокером, а также с управлением текущими позициями путем их модификации или закрытия. Платформа позволяет удобно просматривать торговую историю на счете, настраивать оповещения о событиях на рынке и многое другое. Открытие позиций...
 

MQL5
I have no problems with it in normal mode, but as soon as I start optimisation the error prints at each run and there is no output.

But the thing is, it doesn't even execute the code. I've put Prints around the program, no output, just an error on every run that exits.

Why is the Print not working?

 
Roman Sharanov:

MQL5
The Expert Advisor works without problems in normal mode, but as soon as I start optimizing it, it complains on every pass that it has entered the array limits.

But the thing is, it doesn't even execute the code. I've put Prints around the program, no output, just an error on every run that exits.

Why doesn't Print work?

You have to check the array size. You are shown a line where there is an output outside the array. Here, you must insert Print before this line, in which you write the output of the array size and index, by which you are trying to access array data - the array size and index will be printed in the log, and then the program will exit with an error.

BUT! Do all this in the tester in visual mode, not in optimizer - in optimizer (and tester in non-visual mode) all printers are disabled for acceleration.

 
Artyom Trishkin:

Exit outside the array before reaching Print().

Check the size of the array. You are shown a line where the output is outside the array. Before this line, you must insert Print, in which you write the output of the array size and index, by which you are trying to access array data - the array size and index will be printed into the journal, and then the program will crash.

BUT! Do it all in the tester in visual mode, not the optimizer - in the optimizer (and the tester in non-visual mode) printers are all off for acceleration.

That is the problem, everything works with any parameters in the visual, but with any optimization it goes out of bounds

 
Roman Sharanov:

That's the problem that with any parameters in the visual all works, but with any optimization it is out of bounds

What is there in the array? I can only guess that either there is no data in the array yet, or it is smaller than you think. Are there any checks in the program for the array size?

 
Artyom Trishkin:

What is in the array? I can only guess that either there's no data in the array yet, or it's smaller than you think. Are there any checks in the program for the size of the array?

Last N, I have 500, macd values, and cycle limits are strictly limited and can never be less than 0 and greater than N, I've both debugged it and counted on paper

 
Roman Sharanov:

The last N, I have 500, macd values, and the loop limits are strictly limited and can never be less than 0 and greater than N, I've both debugged it and counted it on paper

Are you sure the array is full of data when you access it? Is there a check for data availability and that the array has the right value?

Just because it's written and calculated on a piece of paper doesn't mean it matches what the EA received (didn't receive).

 
Artyom Trishkin:

Are you sure that the array is full of data when you access it? Is there a check that the data is available and that the array has the right size?

Just because it's written and calculated on a piece of paper doesn't mean it matches what the Expert Advisor received (didn't receive).

Yes, at the beginning, before all operations, it is copied from the buffer.

 
What is the universal formula for calculating the breakeven price if there are commissions and swaps in the transaction?

There is a simple formula that works for quotes with 5 digits and deposit in usd

Lot x profit in pips = profit in $.

If it is buy, and there are swaps and commissions in deal, then breakeven price will be a bit higher than open price
(If there are no swaps and commissions, the breakeven is the opening price)

But if the instrument is exotic or the quote is 4 or 2 figures or the deposit currency is pounds. The above formula is not helpful.
Is there a universal formula?
 
Roman Sharanov:

Yes, at the beginning, before all operations, copied from the buffer

Copied. And how much is copied is checked?

If you are using an indicator with smoothing, it requires a few more bars than you expect. Therefore, just because you have copied does not mean that the data has been copied and is available in its full size.

It is easier for you to check the size of the array and, if it does not have the required size, exit OnTick()