Forex



Go Back   Forex Trading > Downloads > Expert Advisors - Metatrader 4
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 11-29-2006, 02:47 AM
Member
 
Join Date: Sep 2006
Posts: 65
sbwent is on a distinguished road
Help Needed Making Perfect Trailing Stop EA

Hi team.

I need an MQ4 programmer to help me out with this. I am trying to write a good trailing stop expert with some specific features.

1. A starting stop for when the Expert is started.
2. A trailing stop, adjustable from 5 pips upwards
3. A take profit function
4. Profit trailing. If true it will monitor and adjust all trades that are in profit, if false it wil lonly modify the chart it is attached to.
5. Play Expert sounud when adjustment is made.


Here are my inputs. If someone can program this for me I'd really appreciate it. Also, I'm sure many members of this forum would find it useful.


extern bool AllPositions = false; // (True To modify all positions ) False(modify chart positions)
extern int StopLoss=15;
extern int TrailingStop=10;
extern int TakeProfit=0;
extern bool ProfitTrailing = True; //(To Trail only postions on profit not loss )
extern bool UseSound = True;
extern string NameFileSound = "expert.wav";

Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 11-29-2006, 05:38 AM
Member
 
Join Date: Nov 2006
Posts: 46
SteveBrown is on a distinguished road
I haven't found any way to trail a stop other than by calling OrderModify() and specifying a new value for the stoploss parameter. Using that method, the EA has to monitor each incoming tick and decide whether or not to raise (or lower) the stop.

If you don't want your broker to know where your stops are, then instead of setting a stop and trailing it, your EA will have to monitor the exchange rate and call OrderClose() when its internal stop is reached. However, that entails the risk of having no stop if the connection between the EA and the broker is lost.

I know that some brokers allow you to set a server-side trailing stop manually, and if anyone knows how an Expert Advisor can do that, please post the method for doing that.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #3 (permalink)  
Old 11-29-2006, 06:24 AM
daraknor's Avatar
Senior Member
 
Join Date: Oct 2006
Location: Portland, OR USA
Posts: 996
daraknor is on a distinguished road
I was working on this, but nobody seemed interested.
EA design: Trailing Stop and Take Profit is what I posted.

To modify all trades, do the standard bit of code:
PHP Code:
   for (int count0count OrdersTotal(); count++) {
    if (
OrderSelect(countSELECT_BY_POS) == false)
           
TrailingStop();
}

The main difference is that I didn't check for magic number or currency. To restrict the functionality, check for those two things. See any EA for an example of those.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #4 (permalink)  
Old 11-29-2006, 06:27 AM
daraknor's Avatar
Senior Member
 
Join Date: Oct 2006
Location: Portland, OR USA
Posts: 996
daraknor is on a distinguished road
I am still working on that trailing stop project, but I'm calling it "ExitGuru" and am going to charge $20 for a compiled copy, $100 for source, or $30/hour for integration into another EA (which would allow for backtesting and less system overhead pulling down two copies of the same quote.)

I should have it finished in a week or two, I'm stuck in the middle of three EA. I have most of the functionality you want finished already. It seems like you are asking for something very simple though so you wouldn't need the EA I was writing.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #5 (permalink)  
Old 11-29-2006, 07:26 AM
Member
 
Join Date: Sep 2006
Posts: 65
sbwent is on a distinguished road
The Main Problem...

The main problem I'm having is making the EA work only on the chart that it is attached to. Can someone give me the code and some instructions? I guess I need an if statemement.

I can already modify/close all trades. That part is easy. Just telling it to modify the symbol that it's attached to that's go me confused.

Can someone help with this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #6 (permalink)  
Old 11-29-2006, 07:32 AM
Diam0nd's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 235
Diam0nd is on a distinguished road
Thumbs down

Quote:
Originally Posted by daraknor
am going to charge $20 for a compiled copy, $100 for source, or $30/hour for integration into another EA (which would allow for backtesting and less system overhead pulling down two copies of the same quote.)
Wow! Is this ish for real? :| I wish you a nice holiday-sale season then..



Cheers,
Diam0nd




I LOVE
__________________
- MetaTrader v4.00 Build 225 (10 Jul 2008)
- MetaTrader MultiTerminal v4.00 Build 213 (20 Mar 2008)
- Always use the latest (^ABOVE^) MetaQuotes products, saves a lot of nerves. What's new.
"METAQUOTES FOR LIFE!"

Last edited by Diam0nd; 11-29-2006 at 08:44 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #7 (permalink)  
Old 11-29-2006, 08:36 AM
daraknor's Avatar
Senior Member
 
Join Date: Oct 2006
Location: Portland, OR USA
Posts: 996
daraknor is on a distinguished road
Quote:
Originally Posted by sbwent
The main problem I'm having is making the EA work only on the chart that it is attached to. Can someone give me the code and some instructions? I guess I need an if statemement.

I can already modify/close all trades. That part is easy. Just telling it to modify the symbol that it's attached to that's go me confused.

Can someone help with this?
From Phoenix:
Code:
  for(int i=0;i<OrdersTotal();i++)
      {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break;
      if(OrderMagicNumber()!=MAGICMA_A || OrderSymbol()!=Symbol()) continue;
   
      if(OrderType() == OP_BUY)
         {
         if(((Bid - OrderOpenPrice()) > (Point * TrailingStop)) && (OrderStopLoss() < (Bid - Point * TrailingStop)))
            OrderModify(
                        OrderTicket(),
                        OrderOpenPrice(),
                        Bid - Point * TrailingStop,
                        OrderTakeProfit(),
                        0,
                        GreenYellow);
         }
      
      if(OrderType() == OP_SELL)
         {
         if(((OrderOpenPrice() - Ask) > (Point * TrailingStop)) && (OrderStopLoss() > (Ask + Point * TrailingStop)))
            OrderModify(
                        OrderTicket(),
                        OrderOpenPrice(),
                        Ask + Point * TrailingStop,
                        OrderTakeProfit(),
                        0,
                        Red);
         }            
      }
You can use that, but you can't redistribute it. I wrote a different version for the code I'm going to sell (MUCH more complicated).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #8 (permalink)  
Old 11-29-2006, 09:24 AM
Member
 
Join Date: Sep 2006
Posts: 65
sbwent is on a distinguished road
Thanks

Thank you. This is similar to what I have already put together. The part about symbols is what I really need.

Thanks, I'll try it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #9 (permalink)  
Old 11-29-2006, 01:43 PM
Member
 
Join Date: Sep 2006
Posts: 65
sbwent is on a distinguished road
Cool Take Profit Calculation

Another option I was thinking of for this EA is an option to add the total profits and close all trades if target is reached.

Example...

int TargetProfit = 50;

Is there a simple calculation that can collect total profits on the account and then close all trades if target is reached?

I think this would be a nice addition.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #10 (permalink)  
Old 11-29-2006, 09:11 PM
daraknor's Avatar
Senior Member
 
Join Date: Oct 2006
Location: Portland, OR USA
Posts: 996
daraknor is on a distinguished road
I've been working on that very thing in the exit strategy EA. It is easy to do it for a single static value, but hard to manage it well dynamically. Every dynamic way has a flaw.

If you look on the MQL4.com documentation, they show the code to look for a profit >0. Change 0 to some other number.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks

Tags
trailing stop EA, trailing stop, trailing


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
script for trailing stop needed please? igotswansons Metatrader 4 35 11-02-2009 01:20 PM
EA trailing stop JoZo Metatrader 4 6 11-10-2006 02:34 PM


All times are GMT. The time now is 08:35 PM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.