Download MetaTrader 5
Customer 2016.11.07 13:50 10 - 50 USD   from 1 to 3 day(s)

Dear all,

I'm new to, but learning, MQL4 coding. I've created a very simple EA that I'm quite happy with. But I'd like to pay for some help with a few more complicated (at least for me) functions. I really want to improve my coding skills so I'd appreciate well-commented code. That way I can learn.

Please note that this EA is only aimed at short positions

What I'm looking for is to extend my EA with the following:

1 - Hedging short positions

  • I wish to prevent margin calls and negative liquidity/ equity fluctuations if a short position temporarily moves against me. 
  • I'd like to profit from the hedge position if my short position gets stopped out and the price keeps moving up. 


  1. I'd like to have an input variable called something like "input double HedgeCost=10.0;"
  2. Every time my EA opens a short position, I'd like a buystop order to be placed at a level of the OpenSell price + HedgeCost. In this example, the buystop order would be triggered when the bid price reaches 10.0 PIP's above the OpenSell price).
  3. When the price moves down, I'd like the hedge position to be closed at OpenSell price - HedgeCost. And again, another BuyStop order should be placed, at OpenSell price + HedgeCost. So if the price moves up again, my short position will be hedged again.
  4. When my short position is closed by Take Profit or any reason except Stop Loss, I want the BuyStop order to be canceled.
  5. If my short position is closed due to a stop loss, the hedge position should be modified and a trailing stop should be placed at the exact level of where my short position got stopped out.

I also would like this hedge function to really attach to the ticket number. Because in the future, my EA may open several positions, and all of these need to be hedged. So it won't work if the hedge order is triggered by looking at the total open orders, it has to really check any open short position that hasn't got a hedge Buystop attached to it. And then hedge those that don't. 


2 - Trailing stop when TP is reached

I think this is relatively simple. Again I'd like to learn how to do this, based on your code.

  1. I'd like an input variable called something like "input int TrailingRange=3"
  2. When my short position almost reaches it's TP level, I'd like an OrderModify to happen so that the TP is removed and a trailing stop loss is put into place at the TP - TrailingRange level.
Thank you in advance and I look forward to your offer/ reply.

Best regards,


Job completed in 4 days. The portfolio of Billy Angdijaya contains 101 finished jobs. This developer received 63 feedbacks with an average rate of 4.89.
Do you want to place a new order for Billy Angdijaya?
: My first time working with a freelancer here, Billy was a pleasure to work with. Very fast and highly skilled. My EA is greatly improved. Will work with him again and I can highly recommend him.
: Happy to work with you Oscar, hope we can do it again next time.
Mohammad Soubra

Mohammad Soubra 2016.11.07 13:51
Published 10 codes in Library
Jobs: 125 (66% personal)
Arbitration: 35 (completed in favor of the developer 22%, canceled in favor of the customer 57%)
Overdue: 33 (26%)
Evgeny Belyaev

Evgeny Belyaev 2016.11.07 17:29
Published 5 codes in Library
Jobs: 118 (43% personal)
Arbitration: 9 (completed in favor of the developer 22%, canceled in favor of the customer 77%)
Overdue: 44 (37%)
email.txt 1 kb
Hamed Dehghani

Hamed Dehghani 2016.11.07 14:06
Jobs: 193 (28% personal)
Arbitration: 39 (completed in favor of the developer 15%, canceled in favor of the customer 51%)
Overdue: 89 (46%)
Sergey Kompaniy

Sergey Kompaniy 2016.11.07 14:24
Jobs: 149 (36% personal)
Arbitration: 29 (completed in favor of the developer 3%, canceled in favor of the customer 55%)
Overdue: 70 (46%)
Mohamed Nabil

Mohamed Nabil 2016.11.07 15:59
Jobs: 110 (21% personal)
Arbitration: 5 (completed in favor of the developer 20%, canceled in favor of the customer 60%)
Overdue: 34 (30%)
Billy Angdijaya

Billy Angdijaya 2016.11.07 19:06
Jobs: 101 (25% personal)
Arbitration: 24 (completed in favor of the developer 8%, canceled in favor of the customer 20%)
Overdue: 55 (54%)
Indra Lukmana

Indra Lukmana 2016.11.07 13:51
Jobs: 47 (23% personal)
Arbitration: 15 (completed in favor of the developer 0%, canceled in favor of the customer 53%)
Overdue: 25 (53%)
Pablo Medina Betancor

Pablo Medina Betancor 2016.11.07 14:05
Jobs: 2 (0% personal)
Overdue: 1 (50%)
To add comments, please log in or register