Trailing StopLoss

 

I hav been using trailing stoploss coded into the EA. Works fine. The only catch is that if  contact is lost it does not work. The trailing stoploss can also be set manually on the terminal. As I understand it

it is then handled by the server, which means it will work even if contact is lost witht the EA.

I looked around on the MQL4 help but ould not find anything that indicated that this "server"-stoploss could be set from within the EA.

Is it possible to set this "server trailing stoploss" programmatically from the EA?

 

I had a look on MQL5 and it has a function CheckTrailingFixedPips.


Could not figure out if this was implemented as a onetime call to the function. If so it is what I was asking for.

There where no examples so I cannot figure out if it works like I want, "automatic" change of trailing stoploss

 
Ingvar Engelbrecht:

I hav been using trailing stoploss coded into the EA. Works fine. The only catch is that if  contact is lost it does not work. The trailing stoploss can also be set manually on the terminal. As I understand it

it is then handled by the server, which means it will work even if contact is lost witht the EA.

I looked around on the MQL4 help but ould not find anything that indicated that this "server"-stoploss could be set from within the EA.

Is it possible to set this "server trailing stoploss" programmatically from the EA?

No, the trailing stops are NOT handled by the server. It is handled by your EA or by the Terminal (if they were set manually). If the EA or terminal goes down, then they are no longer updated.

If your Trailing Stop is non-virtual (i.e. updates the true Stop-Loss price), then the server will only handle the last Stop-Loss set for the order or position.

 
Fernando Carreiro:

No, the trailing stops are NOT handled by the server. It is handled by your EA or by the Terminal (if they were set manually). If the EA or terminal goes down, then they are no longer updated.

If your Trailing Stop is non-virtual (i.e. updates the true Stop-Loss price), then the server will only handle the last Stop-Loss set for the order or position.

Fernando

>If your Trailing Stop is non-virtual (i.e. updates the true Stop-Loss price), then the server will only handle the last Stop-Loss set for the order or position.

>Of course, you cannot have multiple stoplosses!!?? And what do you mean by non-virtual?? What is a virtual Stoploss?


So, what is the point in using this "CheckTrailingFixedPips" Class in MQL5 instead of just check my trades in the EA and do a OrderModify if needed 

I have a routine that loops throgh all positions and uses "ticket" to modify stoploss if needed. It is incorporated in the EA and controlled by a timer. Still cant figure out what the

Class "CheckTrailingFixedPips" does. The attibute "Fixed" in the name of it indicates that it does something different than just doing an OrderModify to change the the SL

 

Ingvar Engelbrecht:

>If your Trailing Stop is non-virtual (i.e. updates the true Stop-Loss price), then the server will only handle the last Stop-Loss set for the order or position.

>Of course, you cannot have multiple stoplosses!!?? And what do you mean by non-virtual?? What is a virtual Stoploss?

So, what is the point in using this "CheckTrailingFixedPips" Class in MQL5 instead of just check my trades in the EA and do a OrderModify if needed 

I have a routine that loops throgh all positions and uses "ticket" to modify stoploss if needed. It is incorporated in the EA and controlled by a timer. Still cant figure out what the

Class "CheckTrailingFixedPips" does. The attibute "Fixed" in the name of it indicates that it does something different than just doing an OrderModify to change the the SL

I think you are mixing up concepts and MT/MQL versions!

The "OrderModify" function is only available in MQL4, not in MQL5 which uses the "OrderSend" function with the "TRADE_ACTION_MODIFY" operation type.

The "CheckTrailingFixedPips" however, is part of the MQL5 OOP Library, specifically for use via "Expert" Class, which is an Object Oriented Programming layer working on top of the normal procedural functions like "OrderSend".

A virtual stop loss, is where the stop price is only maintained in the EA variables and does not physically update the server's Stop-Loss price, and it is up to the EA to manually close the order when that value is reached.

Also, you cannot have multiple stop-loss prices (that makes no sense). There is always just one stop-loss (if set) and when it is hit, the order closes! If you are considering partial close at different levels, then that is not a stop-loss, and it has to be handled virtually in the EA (or have multiple orders with different S/L, which is only possible on a "Hedging" account and not on a "Netting" account).

 
Fernando Carreiro:

I think you are mixing up concepts and MT/MQL versions!

The "OrderModify" function is only available in MQL4, not in MQL5 which uses the "OrderSend" function with the "TRADE_ACTION_MODIFY" operation type.

The "CheckTrailingFixedPips" however, is part of the MQL5 OOP Library, specifically for use via "Expert" Class, which is an Object Oriented Programming layer working on top of the normal procedural functions like "OrderSend".

A virtual stop loss, is where the stop price is only maintained in the EA variables and does not physically update the server's Stop-Loss price, and it is up to the EA to manually close the order when that value is reached.

Also, you cannot have multiple stop-loss prices (that makes no sense). There is always just one stop-loss (if set) and when it is hit, the order closes! If you are considering partial close at different levels, then that is not a stop-loss, and it has to be handled virtually in the EA (or have multiple orders with different S/L, which is only possible on a "Hedging" account and not on a "Netting" account).

   OK on "Virtual". I suspected that. I have no idea why "multiple stoplosses" came into the discussion.

   OK on "CheckTrailingFixedPips"

   So I am stuck with maintaining a trailing SL function in the EA or in a separate EA constructed solely  for the purpose of maintaining the trailing. (I have used both methods).

   Why do it in a separate EA? The main reason is that it is a simple EA that needs a minimum of maintenace.   The "real" EA I am developing (On MT4) is a rather complex EA trading all the "majors"

   based on their "strength"

   I am working on transforming it to a MT5 (hedging) account. I like MQL5

   Thanks!

 
Ingvar Engelbrecht:

   OK on "Virtual". I suspected that. I have no idea why "multiple stoplosses" came into the discussion.

   OK on "CheckTrailingFixedPips"

   So I am stuck with maintaining a trailing SL function in the EA or in a separate EA constructed solely  for the purpose of maintaining the trailing. (I have used both methods).

   Why do it in a separate EA? The main reason is that it is a simple EA that needs a minimum of maintenace.   The "real" EA I am developing (On MT4) is a rather complex EA trading all the "majors"

   based on their "strength"

   I am working on transforming it to a MT5 (hedging) account. I like MQL5

   Thanks!

>> I have no idea why "multiple stoplosses" came into the discussion.

Because that is what you wrote in your post #3 and I quote: ">Of course, you cannot have multiple stoplosses!!?? And what do you mean by non-virtual?? What is a virtual Stoploss?"

>> Why do it in a separate EA?

Putting the trailing stop in a separate EA is not really a good practice. In fact, it should be an integral part of a strategy's rules and be implemented as such for better overall risk and order management.

>> I am working on transforming it to a MT5 (hedging) account. I like MQL5

Be aware, that unless you have planned it from the beginning with MQL5 in mind, then implementing it in MQL5 will require a completely different approach, causing you to re-write it from scratch.

 

Well my friend.

You wrote the obvious fact

>If your Trailing Stop is non-virtual (i.e. updates the true Stop-Loss price), then the server will only handle the last Stop-Loss set for the order or position

Maybe i misunderstod you on this one but you are mentioning "The last stop" implying more than one. I guess that is not what it ment but it caused my comment

As to MQL4 versus MQL5.

I have used mostly  MQL5 since it became available. Wrote this EA in MQL4 since it will run multiple orders on a pair. I then became aware of the "Hedging" concept offered by some brokers.

Most of the code is the same and I also use several libraries. one of the libraries are for trading functions. Since they are quite different they are separated into 2 different versions. I also use the compiler directive  #ifdef __MQL4__   and  #ifdef __MQL5__ 

Programming in itself is second nature to me, I have worked as a professional prgrammer since 1970. Started at IBM (Sweden) The last 10 years I have been working as a freelance programmer in my own company.

By the years I have acquired something like 12 different programming languages. The last being PHP.

I think we can drop this thread now. Ther is no way to maintain a trailing stoploss other than from the "Terminal".

 
Ingvar Engelbrecht:

Well my friend.

You wrote the obvious fact

>If your Trailing Stop is non-virtual (i.e. updates the true Stop-Loss price), then the server will only handle the last Stop-Loss set for the order or position

Maybe i misunderstod you on this one but you are mentioning "The last stop" implying more than one. I guess that is not what it ment but it caused my comment

As to MQL4 versus MQL5.

I have used mostly  MQL5 since it became available. Wrote this EA in MQL4 since it will run multiple orders on a pair. I then became aware of the "Hedging" concept offered by some brokers.

Most of the code is the same and I also use several libraries. one of the libraries are for trading functions. Since they are quite different they are separated into 2 different versions. I also use the compiler directive  #ifdef __MQL4__   and  #ifdef __MQL5__ 

Programming in itself is second nature to me, I have worked as a professional prgrammer since 1970. Started at IBM (Sweden) The last 10 years I have been working as a freelance programmer in my own company.

By the years I have acquired something like 12 different programming languages. The last being PHP.

I think we can drop this thread now. Ther is no way to maintain a trailing stoploss other than from the "Terminal".

Last Stop-Loss = The price to which that Stop-Loss was last updated!
 
Fernando Carreiro:

No, the trailing stops are NOT handled by the server. It is handled by your EA or by the Terminal (if they were set manually). If the EA or terminal goes down, then they are no longer updated.

If your Trailing Stop is non-virtual (i.e. updates the true Stop-Loss price), then the server will only handle the last Stop-Loss set for the order or position.

Fernando,

Have you tested it yourself?

@Carl Schreiber has a different opinion...

https://www.mql5.com/en/forum/160854#comment_3834774

Why Metatrader don't have Server Trailing Stop Loss?
Why Metatrader don't have Server Trailing Stop Loss?
  • 2016.11.12
  • www.mql5.com
Why Metatrader don't have Server Trailing Stop Loss? There's a lot of trading platform that have Server Trailing Stop Loss...
 
Arthur Albano:

Fernando,

Have you tested it yourself?

@Carl Schreiber has a different opinion...

https://www.mql5.com/en/forum/160854#comment_3834774

I think Carl means terminal, not server. There is no server side TSL.

Reason: