Discussion of article "How to Create Your Own Trailing Stop" - page 5

 
natyog:


oh how! question to question - that's wise!

the position is opened by your expert my_first_ea_sartrailing.mq5



I just don't remember everything, that's why I'm asking.

You should clear the structure of the trade request before filling it: ZeroMemory( mrequest);

This is how it should be (add it in two places):

ZeroMemory( mrequest);      // добавить

mrequest.action = TRADE_ACTION_DEAL;  // есть

Or better yet, remove structure filling altogether and use the standard CTrade class
 
Dmitry Fedoseev:

I just don't remember everything, that's why I'm asking.

You need to clean up the structure of the trade request before filling it: ZeroMemory( mrequest);

This is how it should be (add it in two places):

ZeroMemory( mrequest);      // добавить

mrequest.action = TRADE_ACTION_DEAL;  // есть

Or better yet, remove structure filling altogether and use the standard CTrade class

clearing the ZeroMemory( mrequest) structure does not change the situation:

The tester still outputs

2017.08.25 12:47:50.311 2016.01.13 16:00:00 failed instant sell 0.10 EURUSD at 1.08275 sl: 1.08575 tp: 1.07275 [Invalid request]
2017.08.25 12:47:50.311 2016.01.13 16:00:00 Alert: Request to set Sell order failed - error code:4756

In the Expert Advisor you took for an example (my_first_ea.mq5) the standard CTrade class is not used, but the structure of the trade zap is filled in.

It is clear, both articles (yours and https://www.mql5.com/en/articles/100 ) were written for beginners.

At the same time my_first_ea.mq5 is still tested without errors, but your my_first_ea_sartrailing.mq5 is not.

Why?

Пошаговое руководство по написанию MQL5-советников для начинающих
Пошаговое руководство по написанию MQL5-советников для начинающих
  • 2010.06.09
  • Samuel Olowoyo
  • www.mql5.com
Написание советников на MQL5 проще чем кажется, вы легко можете этому научиться. В этом руководстве вы познакомитесь с основными моментами, необходимыми для написания простого советника на основе конкретной торговой стратегии. Рассмотрена структура советника, использование встроенных технических индикаторов и торговых функций, вопросы отладки и тестирования советника на исторических данных.
 

For some reason after ZeroMemory() positions started to open.

 
lucky, it's the first time it's happened?
 

Hello, I need the code to stop the Trailing Stop, say, I have a position in buy the price I advance 10 pips and I want the TS to stop at 5 pips and not advance more if the price continued and is at 20 pips the TS is still in 5 pips, thanks
 

Hello everyone. And who can write such a robot that will trawl, even probably not trawl, but close all positions (both open and pending-this can be optional) when the profit on all open positions decreases to a given value! Example: the profit on all open positions is 200 USD and I do not want to lose more than 20 per cent of this amount, i.e. when the profit drops to 160 USD, the Expert Advisor will close all positions.

I believe that this is a simple matter for programmers.

 
Igor Petrov:

***

I believe it's a simple matter for programmers.

These are the phrases programmers hate the most. That's for future reference.

 
Vladimir Karputov:

These are the phrases programmers hate the most. That's for future reference.

Okay. Got it.)

 
Igor Petrov:

Okay. Got it.)

Search the words "Trailing" "Balance" "Equity."

 
Hello. The code makes orders but does not modify the stop loss. What changes to the code can i make to fix this error?
Files:
error.JPG  87 kb