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.
I was working on this, but nobody seemed interested.
https://www.mql5.com/en/forum/175481 is what I posted.
To modify all trades, do the standard bit of code:
if (OrderSelect(count, SELECT_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.
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.
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?
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:
{
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).
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
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.
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.
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.
I'm still looking for a EA that can open a pending order at a different specific price when the price has reached a certain level. E.G: Open a pending order at 1.9100 when the price has reached 1.9890
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.