Self-learning the MQL5 language from scratch - page 73

 
Vasiliy Sokolov:

I added a few functions. I ended up with a code like this:

I still don't understand how to work with a MA. It makes no sense on netting. In any case you can easily remove this check as it is only done in one function.

Thank you, Vasiliy, for the interesting information. They say that repetition is the mother of learning! This time it seems to be about me... :-)

I have attached the robot - trawl variants - by name, it is intuitive, when you enter the EXPA code it is all described, but on MT4. I myself now trade on MT4 and I need them for trading. These robots in the code base are from Yuriy Dzyuban, my thanks to him very much. (By the way - the topic - similar robots for MT5)

trawl robot options



You write a ticket and parameters of external variables of the appropriate trawl, put it on a chart and follow profit!!!

Here is an example of a MA trawl:

extern   int      iTicket;             // уникальный номер (тикет) открытой позиции
extern   int      iTmfrm;              // период графика, на котором строится МА (1, 5, 15, 30, 60, 240, 1440, 10080, 43200)
extern   int      iMAPeriod = 21;      // период МА (не меньше 2)
extern   int      iMAShift = 0;        // сдвиг индикатора относительно ценового графика
extern   int      iMAMethod = 0;       // метод усреднения (0 - MODE_SMA, 1 - MODE_EMA, 2 - MODE_SMMA, 3 - MODE_LWMA);
extern   int      iApplPrice = 0;      // используемая цена (0 - PRICE_CLOSE, 1 - PRICE_OPEN, 2 - PRICE_HIGH, 3 - PRICE_LOW, 4 - PRICE_MEDIAN, 5 - PRICE_TYPICAL, 6 - PRICE_WEIGHTED)
extern   int      iShift = 1;          // индекс получаемого значения из индикаторного буфера (сдвиг относительно текущего бара на указанное количество периодов назад)
extern   int      iIndent = 3;         // отступ от МА, на котором размещается стоплосс
Files:
 

Good day and good mood everyone!

I continue studying the MQL5 programming language. I have written the code of my Expert Advisor with a trailing stop. At first I was pleased with the testing of the EA but it turned out to be too early. The matter is that the EA does not work stably and I do not understand what this is about.

The essence of the problem: I am running the Expert Advisor on historical data since January 6, 2020. The first days, the Expert Advisor works exactly according to the algorithm, but as soon as testing reaches January 13, 2020, the algorithm is not executed. I found out that the entire problem is in the trailing stop loss function. The only thing I cannot understand is how it can occur - at times the trawl works and at times it does not? I am trying to find out where I screwed up.

I will not lay out the code of the trawl function yet, because I want to sort out the issue myself.

Regards, Vladimir.

 
MrBrooklin:

Good day and good mood everyone!

I continue studying the MQL5 programming language. I have written the code of my Expert Advisor with a trailing stop. At first I was very glad to test it, but it turned out to be too early. The matter is that the EA does not work stably and I do not understand what this is about.

The essence of the problem: I am running the Expert Advisor on historical data since January 6, 2020. The first days, the Expert Advisor works exactly according to the algorithm, but as soon as testing reaches January 13, 2020, the algorithm is not executed. I found out that the entire problem is in the trailing stop loss function. The only thing I cannot understand is how it can occur - at times the trawl works and at times it does not? I am trying to find out where I screwed up.

I will not lay out the code of the trawl function yet, because I want to sort out the issue myself.

Sincerely, Vladimir.

You may use logs and alert. And at the very least, record each sneeze in the file))))

 
Valeriy Yastremskiy:

A logbook and an alert to help. And at the very least a record in the file of every sneeze))))

Hello Valery! Thanks for the tip. Had a look at the log on the day the trawl is not working correctly:

10016

TRADE_RETCODE_INVALID_STOPS

Incorrect stops in request


However, even on the day when the trawl stop loss works fine, the exact same trade server return code appears. An ambiguity.

Regards, Vladimir.

 
MrBrooklin:

Hello Valery! Thanks for the tip. Had a look at the logbook on the day the trawl is not working correctly:

10016

TRADE_RETCODE_INVALID_STOPS

Incorrect stops in the request.


Now I need to understand how it can be that on one trading day the stops in the request are correct, while they are wrong on another trading day. This is an error.

Sincerely, Vladimir.

The journal does not write everything. So, you have calculated the stop and placed it. and just before the order, the freeze level has changed along the way. It happens.

Alert is faster and immediately visible, print is also visible, but there are a lot of system messages.

 
Valeriy Yastremskiy:

The logbook doesn't write everything. So they calculated the stop, took it out. and before, just before the order it and the freeze level were taken out. suddenly on the way out changed. It happens.

Alert is faster and immediately visible, print is also visible, but there are a lot of system messages.

Valeri, what is the freeze level? Maybe it should be prescribed in the code in some way?

Regards, Vladimir.

 
MrBrooklin:

Hello Valery! Thanks for the tip. Had a look at the logbook on the day the trawl is not working correctly:

10016

TRADE_RETCODE_INVALID_STOPS

Incorrect stops in the request


However, even on the day when the trawl stop loss works fine, the exact same trade server return code appears. An ambiguity.

Regards, Vladimir.

Hello! Most likely the broker has changed the level of stops, andwrong stops in case of trailing is when the trailing distance is less thanthe level of stops allowed by the broker, simply increase the trailing distance slightly, the trailing distanceshould not be less than the level of stops, you could find this information in the specification of each instrument
 
VVT:
Hello! Most likely the broker has changed the stop level.Wrong stops in case of trailing is when trail distance is less than allowed by the brokerstop level, you just need to increase the trail distance a little, trail distanceshould not be less than stop level, this information you might find in specification of each instrument

Hello! Thanks for the tip. I honestly didn't know about that. I will try to change it.

Sincerely, Vladimir.

 
VVT:
Hello! Most likely broker has changed stop level.Wrong stops in case of trailingstop is when distance of trail is less than allowed by broker, you just need to increase distance of trail a little, distance of trailshould not be less than level of stops, this information you might find in specification of each instrument

Tried changing the distance. Didn't work. It's the same. I will continue reading about trailing stop loss and dealing with the code.

Sincerely, Vladimir.

 
MrBrooklin:

Tried changing the distance. Didn't work. It's the same. I will continue reading about trailing stop loss and dealing with the code.

Sincerely, Vladimir.

Incorrect stop, it's strange. What else happens during trawling?

Reason: