Self-learning the MQL5 language from scratch - page 55

 
MrBrooklin:

Vasily, there is one more thing I need to clarify. In point 2 of the Expert Advisor algorithm I wrote: "In the Expert Advisor, create a block of input parameters with two parameters: set "trailing level" and set "trailing step". What do you mean by set the "trailing level" parameter? This is a "positive" level of the current price relative to the opening price of a position at which trailing stop loss would be moved to the level of the opening price, i.e. to Breakeven.

Sincerely, Vladimir.

For buy, if price moved up from the current trailing level, trailing step plus trailing level, we would move it to the new level. Kovalev's algorithm has no trailing step. There, on each tick the price is compared with trailing level, and if it is higher, then SL level is modified.

The level is by how many points SL lags behind the price. When the price exceeds this step, it moves SL to a new level.

 
Valeriy Yastremskiy:

For buy, if price has risen above, from the current trailing level, the trailing step plus the trailing level, we move it to the new level. Kovalev's algorithm has no trailing step. There, on each tick the price is compared with trailing level, and if it is higher, then SL level is modified.

The level is by how many points SL lags behind the price. The step parameter is introduced at every tick and when the price exceeds this step, it moves SL to a new level.

Valery, I understand how you see trailing, and later I will try to draw my idea. Maybe then all the questions will disappear. Most probably at the moment I'm still confused by the commonly used terminology.

Regards, Vladimir.

 
MrBrooklin:

Vasily, there is one more thing I need to clarify. In point 2 of the Expert Advisor algorithm he wrote: "In the Expert Advisor, create a block of input parameters with two parameters: set "trailing level" and set "trailing step". What do you mean by set the "tra iling level" parameter? It is a "positive" level of the current price relative to the opening price of a position at which trailing stop loss would be moved to the level of the opening price, i.e. to Breakeven.

Sincerely, Vladimir.

This is how I understood it. You have two functions for shifting the trailing stop. The first one moves trailing stop-loss to Breakeven, guided by parameter "Trailing Stop Level". The second function pulls Stop Loss further behind the price, guided by parameter "Trailing Stop Step". Imho, I would call the first parameter "Trailing Stop Loss Level" because it is not trailing stop loss but it is a stop loss transfer.

 
MrBrooklin:

Hello Alexey, I would be very grateful for any help you can give me.

Sincerely, Vladimir.


There are local problems with power supply ... :-)

I will post the trawl library with link from phone maybe today, if I will write more info from PC, tomorrow night Moscow time.
It's all elementary, loop on open, if symbol is needed and so is magik, then check the trawl function condition, if pose modification condition is fulfilled, then modify. That's it.
By the way, here is simple trawl function by Igor Vladimirovich Kim - you can take it apart too.
https://www.mql5.com/ru/code/11693

Here you can find a lot of trawl types in form of function library. I used specific functions for myself and I still use them in my live account, no questions asked, this is from Yuri Dzyuban
https://www.mql5.com/ru/code/7108

There's a lot of interesting stuff and different options for both trawl types and trawl itself, e.g. trawl from profit only, etc.

 
Aleksey Masterov:

No one here is interested in your scribblings. It is customary to post it as an attachment, if you do so, it doesn't mean that more people who want to read it...

It interferes with reading the topic and answering the question.

You've hurt my feelings this morning - but you may not understand that a man studies MT5 and you offer him a trawl of MT4.

- I don't know how to do it and I'm not sure what to do with it. I just wanted to share what I've learned. And to listen to my own mess - I've spent lots of nights trying to understand every function

Files:
8ix5cw.PNG  140 kb
 
SanAlex:

You've offended me since the morning - but you can't understand that a man studies MT5 and you offer him a trawl for MT4.

- I don't understand what you're suggesting to him to buy mt5, but you offer him a trawl for mt4. I just wanted to share what I've learned. I want to listen to my own feedback, I've spent many nights trying to understand every function.


I'm so sorry.
I did not do it on purpose.
As for mt4 and mt5 the forum is the same. I've got the same approach to trawling... I don't know, maybe someone will want to convert types of trawls from MT4 to MT5 to the code as a training ... :-)
Actually, everything is very simple. You just select the function you are interested in and translate it. And in the MT5 code there are a lot of functions and expositions of trawl types.
 
MrBrooklin:

Valery, I understand how you imagine trailing, so later I will try to draw what I had in mind. Perhaps then all the questions will disappear. Most probably at the moment I'm still confused by the commonly used terminology.

Regards, Vladimir.

Valery, as promised, I am posting the picture.

Sincerely, Vladimir.


 
MrBrooklin:

Valery, as promised, I am posting the drawing.

Sincerely, Vladimir.


Philosophical question: if the trawl step is multiple of less than the Breakeven level minus the open position price, does it make sense to move the SL several times?

 
Valeriy Yastremskiy:

If the trawl step is multiple of the Breakeven level minus the open price, then maybe it makes sense to move the SL several times?

Valery, to be honest, I don't understand what you wanted to explain to me, so let's try to understand it once again. What I have drawn in the picture above only refers to what was called in the Expert Advisor's algorithm to set the "trailing level ". When Vasiliy made changes in the algorithm he changed the word trailing to the word break-even. In fact, he did it correctly, because the input parameters should set the level of RIGHT NOW price at which Stop Loss would be set to Breakeven. Breakeven is the price level at which the position was opened.

Example: Let's say there is a Buy position opened at 1.10 000. If the Stop Loss level has been set at 200 pips (five digits), the Stop Loss will be moved to 1.10200 when the current price reaches 1.10000.

All this has nothing to do with the trailing step so far. Then if the current price has moved above (marked with a short red line on the chart), at which Stop Loss has been moved to Breakeven, by the value equal to the input parameter "Trailing Stop", then at that moment Stop Loss should move up by the value equal to the input parameter "Trailing Stop" .

Example: Let's assume that the current price has continued moving in the direction we want. If the "Trailing Stop Loss" has been set at 10 points (five digits) in the input parameters, when the current price reaches 1.10210, the Stop Loss will be moved to 1.10010.

And this will happen until either Take Profit or Stop Loss triggers.

I hope that my vision of the trailing stop algorithm is now clear? If it is fundamentally wrong, I also ask you to explain my error.

Respectfully, Vladimir.

 
MrBrooklin:

Valery, to be honest, I don't understand what you wanted to explain to me, so let's try to understand it again. What I drew in the picture refers only to what was called in the Expert Advisor's algorithm to set the "trailing level ". When Vasiliy made changes in the algorithm he changed the word trailing to the word break-even. Actually he did it correctly, because the input parameters should set the level of CURRENT PRICE at which Stop Loss is moved to Breakeven, at the price level at which the position is opened.

Example: Let's say we have a Buy position opened at 1.10 000. If the Breakeven level in the Trading Platform is set to 200 pips (five digits), then when the current price reaches 1.10200, the Stop Loss is moved to 1.10000.

All this has nothing to do with the trailing step so far. Then if the current price has moved above (marked with a short red line on the chart), at which Stop Loss has been moved to Breakeven, by the value equal to the input parameter "Trailing Stop", then at that moment Stop Loss should move up by the value equal to the input parameter "Trailing Stop".And this will happen until either Take Profit or Stop Loss is triggered.

I hope that my vision of the trailing stop algorithm is now clear? If it is fundamentally wrong, I also ask you to explain my error.

Sincerely, Vladimir.

Now let's analyze if the trailing step is 50 points and we pull the SL after 50 points after breakeven.

The question is why price should pass 200 points to Breakeven and then trawl in 50 points? Maybe, it would be better to pull it up to 50 points at once. After all, if we pull it up twice, the SL will be 100 pips and if the price reverses, the loss will be 100 pips. In your case the loss will be 200 pips, because price will not reach breakeven.

Generally speaking, there are two motivations with opposite effect. Close to the SL reduces the loss and makes the probability of closing at the SL higher. If the SL is close in relation to volatility, then of course your variant is better, if at a normal level and pulling up the SL will not affect the frequency of triggering, then mine.