Order Closing or SL/TP in EA

 

Hi,


I'm just starting out in Forex trading and MQL4 (started a few days ago!). Currently, I'm writing a first EA for detecting and trading on breakouts.

The algorithm detects entry positions relatively well, however to find a good exit point is difficult.
Which leads to my question: is it always necessary to close trades or could the strategy also be to rely on T/P and S/L ?


Also, generally it seems that EA are better for short time frame trading, e.g. <= M30. Is this correct?


Thanks

 

Yes, it is very possible to have a strategy rely solely on TP/SL for exit points. It could be taken one step further with a break even and trailing stop.

.

For the timeframe, it all depends on the EA. EA's can do anything you program it to. While they are more popular on smaller timeframes, it is not due to performing better but rather because people like to see high automatic trading frequency. I've seen some EA's work wonders on H1 and some even on D1. But those are probably extremely solid strategies that won't even be released to the public.

.

Jon

 

Thanks Archael. I'll try to introduce trailing stops.

 

oracle

Further to Archael's comment, remember that if your EA is the only way a position will exit then nothing happens if your EA isn't running (in a power cut or computer failure, for example). The stop loss on an order is managed by the trade server not your PC, so as a matter of safety for your capital you should always have a protective SL, even if it never gets hit while the EA is in control. If you trail the stop loss for an exit, it serves both purposes.

Cheers

Jellybean

 

I don't think oracle1 intended to have only his EA close out trades but Jellybean is correct.

.

Imagine this scenario.. You start a BUY trade that you *know* is gonna go up, you can feel it! The only thing is that you don't know how much more it's gonna go down before going up to your takeprofit level, so you put no stoploss for breathing room. Big storm arrives and blows out the power at your house, you are blacked out for several hours. The power comes back on and you check your charts.. Turns out you were wrong in the beginning AND there was a big news event that hurt you immensely! Having a stoploss could have limited those damages even if your power was out.

.

You should definitely always use a stoploss in every case unless you are using a grid system that will keep your equity above 0 with no stops (enter into a profit trade while another one is losing) or some similar mathematics. If you need to, just make it very far to let your trade breathe and turn around but still, always use one.

.

Jon

 
On another note, if this were to happen, there are mobile platforms that you could use in case of a blackout like the example above. I never tried it but I know that some people love having their platform on their cell phone wherever they go ;)
 

Hi guys,


thanks for your answers. Jellybean, yes, I see the necessity of always putting a SL. Also, I didn't really mean to not use stop losses but rather not specifically closing orders. Just now I thought of another way of looking at closing orders: It could be used as an additional backup to a SL:

- You put a conservative S/L depending on your setup

- You also code the closing of orders gone wrong given some indicators (e.g. Close[0] crosses EMA10)


Then, if the S/L did not hit already when Close[0] < EMA10, then you close the order with OrderClose because it seems to go downwards anyway, so you don't need to wait for the S/L...


My first EA did not work well with closing orders, because I couldn't find the right time to exit, so I didn't implement them. It's an agent which is waiting for strong break out criterias, tuned towards EURCHF at M30.

The problem right now is that the signals it is waiting for are too strict, thus it makes way too few trades and does not capitalise enough on them. Initially, I wanted it to be an EA which works at M15 and does many trades. Oh well, not a bad start though (for starting with MT 3 days ago) :)



SymbolEURCHF (Euro vs Swiss Franc)
Period30 Minutes (M30) 2008.11.11 22:00 - 2009.08.14 22:30
ModelEvery tick (the most precise method based on all available least timeframes)
ParametersBBsqueeze=0.0023; BBbreakthrough=0.0007; StopLoss=75; TakeProfit=40; Lots=0.1; Prots=0.07;

Bars in test9389Ticks modelled1816461Modelling quality44.18%
Mismatched charts errors32




Initial deposit10000.00



Total net profit139.20Gross profit139.20Gross loss0.00
Profit factor
Expected payoff34.80

Absolute drawdown48.46Maximal drawdown91.34 (0.91%)Relative drawdown0.91% (91.34)

Total trades4Short positions (won %)0 (0.00%)Long positions (won %)4 (100.00%)

Profit trades (% of total)4 (100.00%)Loss trades (% of total)0 (0.00%)
Largestprofit trade35.44loss trade0.00
Averageprofit trade34.80loss trade0.00
Maximumconsecutive wins (profit in money)4 (139.20)consecutive losses (loss in money)0 (0.00)
Maximalconsecutive profit (count of wins)139.20 (4)consecutive loss (count of losses)0.00 (0)
Averageconsecutive wins4consecutive losses0
 

If (understandably) you are concerned about your order exits, then I'd advise the following:

- Set two SLs - one at the optimized level that your EA tracks and another wider SL, which is set in the OrderSend(). The second SL acts as a "decoy" for the broker if you're worried about his knowledge of your SL, and also works as a safety net should your EA fail.

- Implement your EA on a high-availability platform if it is responsible for order closure (as it is in the above example). Consider a hosting solution to deliver this.

- Monitor your EA and account (using email, remote access and anything else which helps); EAs are for automation - not 24*7 unattended automation. That said, it is entirely possible to build a solution where the only operational issues which normally arise tend to be broker-induced and at the application layer. But you can never get away from monitoring.

- Consider engaging a broker who will provide a guaranteed SL facility, although this may cost you too much in spread to remain profitable. The reason to do this is that, SL or not, in extreme cases the market can gap instantaneously causing the SL not to be honoured. Check your broker's small print on this issue.


CB

Reason: