Forex
Google

Go Back   Forex Trading > Discussion Areas > Metatrader 4
Forex Forum Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-17-2006, 02:12 AM
igotswansons igotswansons is offline
Junior Member
 
Join Date: Sep 2005
Posts: 13
igotswansons is on a distinguished road
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-17-2006, 07:54 AM
newdigital newdigital is offline
Administrator
 
Join Date: Sep 2005
Posts: 15,388
newdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud of
Quote:
Originally Posted by 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:
Trailing Stop EA

E-ASEClose Expert from KIMIV

Trailing file

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

Templates to create EAs and Indicators

Kalenzo posted stop and trailing stop code somewhere here:
Wma 5/20 - Ema
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-17-2006, 08:47 PM
igotswansons igotswansons is offline
Junior Member
 
Join Date: Sep 2005
Posts: 13
igotswansons is on a distinguished road
thank you very much.. I will look through these links.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-13-2007, 08:08 PM
iscuba11's Avatar
iscuba11 iscuba11 is offline
Senior Member
 
Join Date: May 2006
Location: Houston
Posts: 400
iscuba11 is on a distinguished road
Smile

Quote:
Originally Posted by 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 06-14-2007, 03:38 PM
iscuba11's Avatar
iscuba11 iscuba11 is offline
Senior Member
 
Join Date: May 2006
Location: Houston
Posts: 400
iscuba11 is on a distinguished road
Unhappy

Quote:
Originally Posted by newdigital
We have many thread about trailing stop. You may check some EAs and scripts which are doing this job:
Trailing Stop EA

E-ASEClose Expert from KIMIV

Trailing file

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

Templates to create EAs and Indicators

Kalenzo posted stop and trailing stop code somewhere here:
Wma 5/20 - Ema


These links do not seem to help in creating a trailing stop script!!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 06-14-2007, 03:57 PM
european's Avatar
european european is offline
Senior Member
 
Join Date: Apr 2006
Posts: 281
european is on a distinguished road
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,OrderTake Profit(),0,Red); }
//----
}

Last edited by european : 06-14-2007 at 04:09 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 06-14-2007, 05:24 PM
iscuba11's Avatar
iscuba11 iscuba11 is offline
Senior Member
 
Join Date: May 2006
Location: Houston
Posts: 400
iscuba11 is on a distinguished road
Question

Quote:
Originally Posted by european
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,OrderTake Profit(),0,Red); }
//----
}

When I use this script as a script to just drag over a graph it does not reflect activation has taken place. If I use a modify script, and then right click the mouse and select modify or delete order, the modify script settings are reflected in the modify window. But if I use your trailing stop script it does not reflect in the right click mouse - trailing stop window. This is the problem - How do I know if the trailing stop is even activated??

PHP Code:
//+------------------------------------------------------------------+
//|                                         Script Trailing Stop.mq4 |
//|                                                                  |
//|                                                                  |
//|                                                        |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
#include <stdlib.mqh>
#include <WinUser32.mqh>

//+------------------------------------------------------------------+
//| script "Create Trailing Stop On Open Position"     |
//+------------------------------------------------------------------+

extern int TS 30//Trailing Stop

int start()
{
//----
OrderSelect(0SELECT_BY_POS);

if (
OrderType() == OP_BUY) {
if (
OrderStopLoss() < Bid-Point*TSOrderModify(OrderTicket(),0,Bid-Point*TS,OrderTakeProfit(),0,Red); }

if (
OrderType() == OP_SELL) {
if (
OrderStopLoss() > Bid+Point*TSOrderModify(OrderTicket(),0,Bid+Point*TS,OrderTakeProfit(),0,Red); }
//----
}

//+------------------------------------------------------------------+
 

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 06-14-2007, 05:45 PM
newdigital newdigital is offline
Administrator
 
Join Date: Sep 2005
Posts: 15,388
newdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud of
Script to modify the order by mouse.
I tried it long time ago and it worked.
It is translation from Russian:

Code:
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.
Explanation of the settings inside the script:

Code:
Order_Find_Radius = 10;
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

Code:
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.
Attached Images
File Type: gif screen2.gif (43.1 KB, 271 views)
Attached Files
File Type: mq4 ModifyOrder.mq4 (21.1 KB, 36 views)

Last edited by newdigital : 06-14-2007 at 05:47 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 06-14-2007, 05:46 PM
european's Avatar
european european is offline
Senior Member
 
Join Date: Apr 2006
Posts: 281
european is on a distinguished road
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.

Last edited by european : 06-14-2007 at 06:43 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 05-20-2008, 10:13 AM
ssg10 ssg10 is offline
Junior Member
 
Join Date: Apr 2008
Posts: 4
ssg10 is on a distinguished road
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


Similar Threads
Thread Thread Starter Forum Replies Last Post
ATR Trailing Stop - Help Boiseboy Indicators - Metatrader 4 51 07-08-2008 04:39 AM
Help Needed Making Perfect Trailing Stop EA sbwent Expert Advisors - Metatrader 4 27 03-13-2008 04:30 AM
Trailing Stop Script - Not EA iscuba11 Tools and utilities 3 07-02-2007 02:22 PM


All times are GMT. The time now is 09:06 AM.