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

 
Maxim Kuznetsov #:

I've stepped on such a rake. Start actively collecting, counting statistics and you will.

ALWAYS check other people's/external data.

About the fact that even the Bid, Ask can be incorrect even in this thread said. I will not dig out the link, it's long, but it was cured.

Ok. Here's a function to check:

bool arrayCheck(const double &_values[]) {
  for (int i = 0; i < (int)_values.Size(); i++)
    if (_values[i] == 0 || _values[i] == EMPTY_VALUE || _values[i] == DBL_MAX) {
      Alert("Values incorrect! File: ", __FILE__, " Line: ", __LINE__, " ", __FUNCTION__);
      return false;
    }
  return true;
}

If you manage to catch at least one such case, post in the threadhttps://www.mql5.com/ru/forum/1111

Because one user also wrote that it was giving out wrong prices in the tester. But he never gave an example where this could be seen(https://www.mql5.com/ru/forum/1111/page3131#comment_26786448).

Ошибки, баги, вопросы
Ошибки, баги, вопросы
  • 2010.06.02
  • www.mql5.com
Общее обсуждение: Ошибки, баги, вопросы
 
Mihail Matkovskij #:

Made it this way.

if(CopyLow(mSymbol,0,2,6,low)>0 && low[ArrayMinimum(low)]>CopySymb[1].low) {

Thank you all!

 
Vitaly Muzichenko #:

I did it like this.

Thank you all!

Minor clarification. ArrayMaximum can return -1 if it fails. We still need to figure out what those cases might be. Let's reject an empty low array at once. And to avoid guessing what other cases there might be, we just do this:

int iMinLow;

if(CopyLow(mSymbol,0,2,6,low)>0 && (iMinLow = ArrayMinimum(low)) >= 0 && low[iMinLow]>CopySymb[1].low) {
 
Mihail Matkovskij #:

A small clarification. ArrayMaximum can return -1 if it fails. What remains to be understood is what kind of failure it might be. Let's reject an empty low array right away. And to avoid guessing what else might happen, we just do it this way:

And to be even more reliable:

int iMinLow;

if(CopyLow(mSymbol,0,2,6,low)>0 && (iMinLow = ArrayMinimum(low)) >= 0 && iMinLow < (int)low.Size() && low[iMinLow]>CopySymb[1].low) {
 
Vitaly Muzichenko #:

Made it this way.

Thank you all!

Why not use iLowest?

 
Tretyakov Rostyslav #:

Why not use iLowest?

It depends on what the task is...

 
Good day, I would like to try my forces and write a "simple" Expert Advisor for a set position. The idea is quite simple: essentially ETFs do not go up much, but do not fall down much either, and price fluctuations pass through narrow ranges two or three times a year. Initially we have a position in ETFs and we want to obtain a target profit of 12.5% on the purchased position. The expert operation is reduced to setting an insignificant portion of the position immediately in the sell order, for example one fiftieth of it by half a percentage point more, the next part by another half a percentage point more, etc. By dividing the whole position by 25% of the price increase (thus achieving the 12.5% target for the position as a whole). After each sale, immediately place a buy order for a smaller percentage. Over time, once the entire position has gone through several rounds, its average purchase price (actual) will be lower, and the target will be reached sooner. Naturally, if the price of the entire asset drops below the buy price, the position is filled using the same principle, but in reverse order, first buying, then selling. As fluctuations do not occur during the day, the order should be moved to the next trading day in a month or two.
Question for knowledgeable people on how best to implement? Maybe there is somewhere where you can write off part of the code?
 
Кирилл Якимов sell order, for example one fiftieth of it by half a percentage point more, the next part by another half a percentage point more, etc. By dividing the whole position by 25% of the price increase (thus achieving the 12.5% target for the position as a whole). After each sale, immediately place a buy order for a smaller percentage. Over time, once the entire position has gone through several rounds, its average purchase price (actual) will be lower, and the target will be reached sooner. Naturally, if the price of the entire asset drops below the buy price, the position is filled using the same principle, but in reverse order, first buying, then selling. As fluctuations do not occur during the day, the order should be moved to the next trading day in a month or two.
Question for knowledgeable people on how best to implement? Maybe there is somewhere where you can write off some of the code?

A lot of unnecessary "water"...

First write a "simple EA" that just places an order, then ask for help to refine it.

As it is, your text looks like "write me"!

 
Tretyakov Rostyslav #:

Why not use iLowest?

In this case, you can do that too.

 

Кирилл Якимов #:
Доброго дня, хочу попробовать свои силы и написать "простого" эксперта ...

...

Question for knowledgeable people on how best to implement? Maybe there is where you can write off some of the code?

Simple Expert:https://www.mql5.com/ru/code/103

More results

Simple MA Expert Advisor
Simple MA Expert Advisor
  • www.mql5.com
Простой эксперт для тех, кто хочет попробовать новый тестер стратегий.