Help needed to write an EA

 

hi all,

I have no idea whether this is the right forum to post this. Admin, please move it to right forum if you think its inappropriate here.

Can I please indulge a kind developer to write me a small EA for MT4?

Objective: To open and manage hedge orders to orders created manually

Description: I open trades manually in either buy or sell direction. I could open multiple trades at any point of time in either direction for a particular pair (e.g. 3 buys and 2 sells). What I am trying to achieve is to create an EA that would open a hedge when things go bad while I am away from the comp.

Input parameter:

1) TriggerPips: Number of pips from the open price of the original trade at which the hedge should be opened (e.g. if I opened buy trade at 1.55 then value of this parameter as 30 means that the hedge would open at 1.25; can have value of 0)

2) HedgeClosurePips: Number of pips at which hedge would be closed. (e.g. in the above case if this value is 5 pips and price rises to 1.30 then the hedge order should be closed, note that hedge should be reopened if price again falls down to 1.25 and no hedge is currently open; can have value as 0)

3) HedgeProfitClosurePips: Number of pips for which the hedge should remain open even after original trade is closed (typically hedge should be closed along with the original trade. But this parameter keeps it open for few pips more. e.g. if the original trade was closed out at 1.10 then a value of 5 means that the hedge trade would close at 1.05 with SL as 1.10; can have value as 0)

4) HedgeLotMult: Multiplier for the lot calculation of the hedge order (e.g. original order with 2 lot then a value of 0.5 means that the hedge is opened with 1 lot)

Requirements:

1. It should work with both 4 or 5 digit brokers.

2. Hedge order should consider the spread at that point of time (along with Ask and Bid price) and have a slippage allowance of 2 pips.

3. Each hedge orders should be tightly coupled with its corresponding original trade. If there are two buy orders and one sell orders created by me then there should be 2 sell hedge and 1 buy hedge. If one of the original buy gets closed then the corresponding sell hedge should get closed. Others should remain untouched.

4. There should be only one hedge order per original order at any point of time does not matter how many times a hedge was opened for that original order.

5. EA should not confuse between original orders and hedge orders and should not create an endless cycle of trades. Order->hedge->hedge etc.

6. Lot size of hedge should be as mentioned in parameter section

7. No TP should be put for the hedge

8. No SL should be put on the hedge but dynamically calculated based on HedgeClosurePips. When price hits hedge open price+/-HedgeClosurePips then the hedge should be closed automatically i.e. at loss.

9. If the original order is closed by me then EA should find out at what price it was closed (not sure how to find that out). Then add/subtract (based on buy/sell) HedgeProfitClosurePips to the price, set that as TP, set closure price of original price as SL.

a. If current price is <= calculated SL then the hedge should be closed immediately.

b. If current price is >= calculated TP then the hedge should be closed immediately

10. If the original trade was closed between the hedge open price and HedgeClosurePips (i.e. hedge is in loss currently but have not hit the SL) then the hedge should be closed immediately irrespective of HedgeProfitClosurePips and HedgeClosurePips.

11. There can be some way visually to know on MT platform whether an order is original or hedge (again not sure how, comment may be)

12. There is no need to monitor across pairs. I will attach this EA individually to right pair.

Please let me know if something similar is available elsewhere.

Thanks a bunch in advance.

 

It can be done pretty easily.

I have had the experience programming it myself in the past.

To sum it up:

3 buys - 2 sells = 1 buy.

Thats it.

If you lose while away from the computer you should not be trading such volume that you would find yourself in the need to hedge.

It is also the same as getting in and out of your trade 2 - 3 times rather than paying the spread 6+ times over.

It just does not give the results, contrary to what one initially thinks.

 

Thanks, but what I am hoping to do is to reduce the drawdown using hedge after a certain point if I am confident about the trade to recover. But I do understand your point.

 

Think about that draw down for a second, your real worried about it.

What about the opposite side of a draw down, a profit, right?

If you hedge you take neither, you neither win nor do you lose.

Even though you have two positions out, your net flat.

But now you must get out of two positions instead of your initial one. Now you pay spread on both when exiting.

You ripped yourself off.

This road leads right down the track to a martingale strategy.

 

Thanks for your concern but if you see the logic that I have put above around hedging its all about protecting my account from a bad trade. I am not going to hedge each and every trade that I am making. Only if it goes down by a certain number of pips then only I open the hedge trade.

I will give you an example. Lets say I have opened a buy trade at 100.80 which I ofcourse think would make profit by going up based on my analysis. But unfortunately things were not right and it goes down to 100.50. At that moment only I open the hedge trade so that it does not drag my account down but also leaves a glimmer of hope of retracement.

Now, price goes up again and as per my logic hedge would close at 100.65 and I let the buy trade run. Its quite possible that buy trade hits TP (say, 101.00) or again it goes back to 100.50. At that point I open hedge trade again and after some time may close out the hopeless original buy trade and in turn the hedge trade. At least I have minimised my loss against a big move that way and live for another day. And I am not sure where did you see martingale in this strategy!

 

Ok now I got a much clearer picture of what you are trying to do.

I know I probably wont convince you until you try it yourself, that is the same thing I would do anyway.

But now you have statistics against you. There is nothing that you are actually basing trades off of at this point expect pure differences in where you entered and exited.

And on top of that doing it kind of randomly.

The market does not work this way. And I am positive an EA like this will actually do the following most of the time.

Enter at 1.50 buy. Price goes down to 1.30 enter a sell hedge. (Btw again net flat here) continue and price goes up to 1.45 where you decide to exit the sell. Of course you just took a loss but hey the profit should go up now because the trade looks right.

This is where the killer comes. Im betting that the price will pretty much always drop again to 1.30.

You have absolutely no discretion as to your trade besides how much you made or lost in relation to your initial entry.

That does not make a winner.

Winners don't care if they win or lose because in the long run they know they win.

Winners care about the risk/probability when they enter/exit the trade.

This is not at all probability if the numbers to hedge at are fixed.

Im almost certain that this is just a MM strategy rather than your underlying enter exit strategy. It would be advisable to rather than consider hedging, maybe you go in 3 lots initially and close 1 out as it goes against you.

NEVER OPEN ANY MORE.

Reason: