Script for trailing stop needed please?

 

I am developing my first ea right now and I am having trouble with a trailing stop. I can initiate an instant buy or sell order but I do not know how to give it a trailing stop. Can anyone help me with this. I am currently using an

OrderSend function for the instant orders. If someone could please tell me how to add a trailing stop to this, I would really appreciate it. thank you

 
igotswansons:
I am developing my first ea right now and I am having trouble with a trailing stop. I can initiate an instant buy or sell order but I do not know how to give it a trailing stop. Can anyone help me with this. I am currently using an OrderSend function for the instant orders. If someone could please tell me how to add a trailing stop to this, I would really appreciate it. thank you

We have many thread about trailing stop. You may check some EAs and scripts which are doing this job:

https://www.mql5.com/en/forum/172924

https://www.mql5.com/en/forum/173193

https://www.mql5.com/en/forum/173225

Also you may visit EA template page with the codes for trailing stop:

https://www.mql5.com/en/forum/173059

Kalenzo posted stop and trailing stop code somewhere here:

https://www.mql5.com/en/forum/173101

 

thank you very much.. I will look through these links.

 
igotswansons:
I am developing my first ea right now and I am having trouble with a trailing stop. I can initiate an instant buy or sell order but I do not know how to give it a trailing stop. Can anyone help me with this. I am currently using an OrderSend function for the instant orders. If someone could please tell me how to add a trailing stop to this, I would really appreciate it. thank you

Did you find one that worked or create one yourself. I am looking for the same and with the same frustration. If you now have a TS Script that drags over to a graph, would you post it or send it to me at: fdiebold@sbcglobal.net

Thanks in advance

Dave

 
newdigital:
We have many thread about trailing stop. You may check some EAs and scripts which are doing this job:

https://www.mql5.com/en/forum/172924

https://www.mql5.com/en/forum/173193

https://www.mql5.com/en/forum/173225

Also you may visit EA template page with the codes for trailing stop:

https://www.mql5.com/en/forum/173059

Kalenzo posted stop and trailing stop code somewhere here:

https://www.mql5.com/en/forum/173101

These links do not seem to help in creating a trailing stop script!!!!

 

Plenty of examples of Trailing Stop code on this site - use 'Search' function

My example of TS:

*************************************

extern int TS = 30; //Trailing Stop

int start()

{

//----

OrderSelect(0, SELECT_BY_POS);

if (OrderType() == OP_BUY) {

if (OrderStopLoss() < Bid-Point*TS) OrderModify(OrderTicket(),0,Bid-Point*TS,OrderTakeProfit(),0,Red); }

if (OrderType() == OP_SELL) {

if (OrderStopLoss() > Bid+Point*TS) OrderModify(OrderTicket(),0,Bid+Point*TS,OrderTakeProfit(),0,Red); }

//----

}

 
 

Script to modify the order by mouse.

I tried it long time ago and it worked.

It is translation from Russian:

Instruction for installation:

1. Open script in MetaEditor and set your desirable default settings.

Default settings in the script are started and finished

by this line //+--------------------------+

2. In Metarader: go to Tools, Options, Expert Advosirs

and select "Allow external experts import".

3. Move script to the chart by mouse just near the order

which you want to modify.

4. Move all the lines to the necessary levels:

- Open_Price_Line (white color by default) -

price to open the order (for pending orders only);

- Stop_Loss_Line (red color) - stop loss level;

- Take_Profit_Line (green color) - take profit level;

- Expiration_Line (yellow) - for pending orders only.

To remove stop loss, take profit, expiration date

so just delete the lines on the chart (by mouse).

Move the lines by mouse on the chart to modify the order.[/CODE]

Explanation of the settings inside the script:

Order_Find_Radius = 10;[/CODE]

It is distance between the price to open the order and where you drop this sctipt. Default is 10. If you are sniper so you may set to zero. It does not affecting on anything a lot because you should open the order manually before. So it is affecting on the following: will this script recognize the order to modify or not. I prefer 10 or more. 20 for example. Because I am not a sniper by mouse

Take_Profit = 50; int Stop_Loss = 50;

It is understandable: stop loss and take profit value. You may set it to 100 (both) to move easy after.

[CODE]Slippage = 5;

Understabdable.

[CODE]Expiration_Shift = 0;

It is for pending orders only. Value is in bas. For example, if you are attaching (moving) ther script to H4 chart and Expiration_Shift = 3 so it means that the order will be expired in 12 hours (3 bars x 4 H timeframe).

How to use this script:

1. Open the order.

2. Move this script by mouse to the place with order price on the chart. If you get the error so it means that you are not sniper and you moved the script far away from the order on the chart. Just increase Order_Find_Radius value in this case. I prefer 20 for example (20 pips target aroud the order open price on the chart).

3. Wait. Pop up window will be opened (see image attached). Ignore this pop-up window (do not click on "OK" or "Cancel", just ignore). If this pop-up window prevent you to see or move the lines on the chart so just move this window to somewhere by mouse.

4. You should see the lines. Just wait 2 or 3 seconds. To speed up this process, or if you do not see red/green stop loss and take profit lines so simple click on the chart by mouse in any place.

5. Move take profit line and stop loss line what ven distance you want (by mouse on the chart). How to move? Double mouse click on the line and move.

6. So, now only you may press "OK" in pop-up window. Afer that order will be modified.

7. If you want to modify once again so move this script to the "open order place" and repeat it.

It looks complicated but it is very simple. Just set your desirable Order_Find_Radius and use your mouse.

Files:
screen2.gif  44 kb
modifyorder.mq4  22 kb
 

Script ?

The code I provided (and most TS code that exists) works in EAs.

There are 2 ways to see the TS works - Red SL line on a chart, corresponding to TS level will be moving once your trade made profit of TS value and the Terminal 'S/L' value will be changing as well. EA will show a 'smiling face' icon in the right top corner of the chart.

There are many variations and options of TS code.

In general, scripts are meant to be used for a one-off execution, while TS needs to be reviewed on every tick.

I find the method explained by newdigital above awkward to use, but that is MQ4 limitation.

 

Percent trailing stops and other types

Hi folks,

Do you know if there is anything out there available for percent trailing stop, ATR based trailing stops or similar things?

Thanks!

 

Need trailing bar stoploss

Can someone point to where I can find a stoploss that will adjust to a set amount of bars.

For example on a short trade, stop moves to the low of the 4th last bar.

On a long trade, stop moves to the high of the 7th last bar e.t.c

thanks

Reason: