Self-learning the MQL5 language from scratch - page 36

 
MrBrooklin:

Peter, if you remember, the New7.mq5 script can already place pending orders, take profit and stop loss. I was going to add trailing stop loss to it according to the self-study plan. Hence the question. Thank you for the tip!

Regards Vladimir.

Trailing stop is a function of price follow-up by an order at a far distance to fix the current profit/loss. In trailing logic there may be different techniques described by many parameters and their calculations. The trailing function is not just placing/moving an order, it is part of the strategy, and the strategy is the level you have not yet reached. You cannot call trailing the function of changing the level of an order. Trailing is more than that and it's too early for you to do it yet. imho.
 
Valeriy Yastremskiy:

1. Script no, EA yes. The script starts immediately and unloads when it finishes. You cannot use OnTick function in the script. Theoretically, you can. In the script, you can use SLEEP, the function to stop working for a while, and in the infinite loop vail at intervals to request the Ask price, compare it with the price of the position and change the SL and TP. Trading functions are not prohibited. But it is .... You will never be understood.

Valery, even now many people don't understand me, why do I need all this? I don't worry much about it. But to understand and create a more complex script is a small, but confident step in self-study. Thanks for the tip, I will study the necessary information tomorrow. Now it's time to relax and tune in to the Russia-Sweden football match.

Regards, Vladimir.

 
VVT:

Hello! It is possible and necessary to write. Let's start with understanding what a trailing stop is, it's a change, a so-called dragging of a stop loss for example, which occurs with every new tick and depending on a given distance from the current price. There are many types and methods, and you can find examples of incremental or one-off dragging of stops, which are used depending on the purpose. You may decide for yourself whether to apply them or not.)

Hello, I need to use, because the self-study plan, which I try to stick to, I have an item on modernizing the script. I move from simple to complex! Thank you for the tip!

Regards, Vladimir.

 
To write a trailing stop you need to switch from a script to an EA, because the script is unloaded from the chart and does not have the OnTick event, without which it will not work. That is, you will not be able (although it is theoretically possible) to write such a script.
 
Реter Konow:
Trailing is the function of following the price with an order at a distant location to lock in the current profit/loss.

Are you sure you understand trailing stop correctly?

 
VVT:

Are you sure you understand trailing stop correctly?

Yes.
 
Реter Konow:
Yes.

No more questions

 
Реter Konow:
To write a trailing stop, you need to pass from the script to the Expert Advisor, because the script is unloaded from the chart when it is executed and it does not have OnTick event, without which it will not work. So, you will not be able (though it is theoretically possible) to write such a script.

Peter, I have found several trailing scripts in MQL4. I have not found any in MQL5.

Regards, Vladimir.

 
MrBrooklin:

Peter, I have found several trailing scripts in MQL4. I have not found any in MQL5.

Sincerely, Vladimir.

OK, I'm NOT saying you can't write it). I said it would be out of your reach for now. For now... The EA is simpler and more correct.

Try to switch to Expert Advisor if you want to implement a simple trailing stop. I will help you.
 
Реter Konow:
Well, I'm NOT saying that it's impossible to write). I said it would be impossible for you to do so far. For now... It's easier and truer to implement in an EA.

Try switching to an EA if you want to implement a simple trailing stop. I will help you.

Great, let's do that! But you have already intrigued me with the script. Anyway, I will try to make this script complete.

I`ll have a couple of hours off, because I need to relax and watch football.

Regards, Vladimir.

Reason: