You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello Peter! Glad to have you back on the phone. On the one hand you are right about the difficulty of the task, on the other hand it has made me look at self-study from a different angle. So, there is nothing wrong with it. The more so, if I manage to handle trailing stops and provide the ready result to everyone, it will be my small victory in learning MQL5.
Now I'm deliberately not publishing any written code lines and comments, because I need to achieve at least some results myself, without anyone's help. The trailing stop task is clear, the initial assistance from the participants of this topic is provided, and now everything depends on me. All I need now is patience.
Sincerely yours, Vladimir.
I understand the important role of over-tasking in self-study and I hope you will be able to write a simple version yourself, but here's the thing:
Thank you, Peter, for your wish! Believe me, it's not always possible to understand a person, especially when you don't know him at all. And there is nothing wrong with that.
In the process of writing the code of an EA with the working name Trailing Stop, I periodically visit this topic, because I am the initiator of its creation and, therefore, I have to answer the questions that are addressed to me. When I have something to show, communications will become much more interesting.
Regards, Vladimir.
Good day and good mood everyone!
My quarantine is over and I am back to normal again. It is a pity that there is less time for self-study now. During this absence I have significantly progressed in learning the MQL5 programming language and writing EA code. I am not going to ask for help from the members of this topic yet, as I do not want to interrupt my Expert Advisor from doing important things. Firstly, I do not want to distract them from their important work. Second, the independent search for errors will enable me to study the language much deeper. I don't set myself a deadline to write the whole code, so I'm not running a horse race. This way, the material learned can be better assimilated.
Regards, Vladimir.
You are starting from the wrong place again, and the code contains an error. Start with the functions. Write the algorithm framework using only your own functions. Then we will think how to implement them. Start with the standard template that is opened when creating a new EA in metaeditor.
The trailing stop is better to be made for the net account to begin with. This way it will be easier to work with the position, because there will only be one position for a symbol. It can be transformed into a hybrid in the second version.
Hello Vasily! I hope I have fixed the error in the loop code. It should have been written in this way:
I'm doing everything else as you advised. Thank you once again!
Regards, Vladimir.
Hello everyone and good mood!
I continue studying MQL5. I've been stuck in place for a long time now, as I am having trouble understanding one simple thing. I wrote a code, which should open a Buy position with 0.1 lot at 9 am and close it forcedly at 11:50 pm, if neither Stop Loss nor Trailing Stop triggered during the trading day. I placed the code in the OnTick() function. Currently, when the strategy tester is started, two Buy positions of 0.1 lot each are opened within 1-2 seconds. If I decrease the lot, for example, to 0.01, then 22 positions are opened within 8-10 seconds. Initial balance is 50000 Rubles. Currency pair EURUSD. I suppose it has something to do with ticks and margin. I looked through a lot of information on my website, but it hasn't had any effect yet.
Please advise what I should do or what condition I should specify to open only one position with the specified lot and no more.
Sincerely, Vladimir.
Could you please advise me what I should do or what condition I should set to open only one position with the specified lot and no more?
Sincerely, Vladimir.
Hi! Set a limit on open positions;
Hello! Set a limit on open positions;
Hello!
Thanks for the tip. To be honest, my thoughts were already focused on somehow prohibiting updates of quotes after opening the first position. I will try to limit the number of open positions.
Regards, Vladimir.
Hello everyone and good mood!
I continue studying MQL5. I've been stuck in place for a long time now, as I am having trouble understanding one simple thing. I wrote a code, which should open a Buy position with 0.1 lot at 9 am and close it forcedly at 11:50 pm, if during the trading day neither Stop Loss, nor Trailing Stop, nor Take Profit triggered. I have placed the code in the OnTick() function. Currently, when the strategy tester is started, two Buy positions of 0.1 lot each are opened within 1-2 seconds. If I decrease the lot, for example, to 0.01, then 22 positions are opened within 8-10 seconds. Initial balance is 50000 Rubles. Currency pair EURUSD. I suppose it has something to do with ticks and margin. I looked through a lot of information on my website, but it hasn't had any effect yet.
Please advise what I should do or what condition I should specify to open only one position with the specified lot and no more.
Regards, Vladimir.
If the position with our magik and on our symbol is zero then check the time and open a position. If it is 1 then don't open a position, check the closing time and trawl. We can use scrolls or if we want to check iff.
If positions with our Magik and on our symbol are zero, we check the time and open a position, if it is 1, we don't open a position, we check the closing time and trawl, if it is more than 1, we alert and don't work. We may use scrolls or check iff.
Hello Valery! Thank you for your tip. I have already mastered the if-else operator, and now I need to master the switch operator as well. Do I need to use Alert() or is it just there for more information?
Regards, Vladimir.