Download MetaTrader 5
48
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. 

Specifically: 

  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,

Oscar. 

Job completed in 4 days. The portfolio of Billy Angdijaya contains 62 finished jobs. This developer received 35 feedbacks with an average rate of 4.91.
Do you want to place a new order for Billy Angdijaya?
2016.12.21
: 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.
2016.12.21
: Happy to work with you Oscar, hope we can do it again next time.
Mohammad Soubra

Mohammad Soubra 2016.11.07 13:51
Published 9 codes in Library
Jobs: 95 (60% personal)
Arbitration: 32 (completed in favor of the developer 25%, canceled in favor of the customer 53%)
Overdue: 24 (25%)
Evgeny Belyaev

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

Hamed Dehghani 2016.11.07 14:06
Jobs: 161 (27% personal)
Arbitration: 35 (completed in favor of the developer 17%, canceled in favor of the customer 45%)
Overdue: 77 (47%)
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: 73 (23% personal)
Arbitration: 4 (completed in favor of the developer 0%, canceled in favor of the customer 75%)
Overdue: 24 (32%)
Billy Angdijaya

Billy Angdijaya 2016.11.07 19:06
Jobs: 62 (30% personal)
Arbitration: 13 (completed in favor of the developer 7%, canceled in favor of the customer 15%)
Overdue: 39 (62%)
Indra Lukmana

Indra Lukmana 2016.11.07 13:51
Jobs: 15 (6% personal)
Arbitration: 7 (completed in favor of the developer 0%, canceled in favor of the customer 57%)
Overdue: 5 (33%)
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