Converting an MQL5 EA designed for Netting to Hedging mode

 

Hi,

I have an EA that I wrote around 5 years ago, that I was using on a real account. I stopped trading when the SNB removed the cap on the Euro and my broker, Alpari, went bust.

That spooked me for a while but I have recently been wanting to give it another go. I have forward tested my EA on a demo MT5 netting account since June last year and it's still profitable. However, I cannot find any broker that allows netting, and I would like to update my EA to run on a hedging account.

My EA works by placing a buy stop and a number of sell limits (or sell stop and buy limits). When price reaches my stop, I open a position and gradually close the position if price continues to moves in my favour at each limit. There is a stop loss that closes the whole position if price does not move in my favour. 

In hedging mode, this method does not work as whenever a limit is reached, a new position is opened.

I place my orders using the methods provided with the CTrade class (BuyStop(), SellLimit() etc)

I have been reading about the best way of going about changing my EA, but I'm a bit stuck. Ideally I'd like to implement the minimum changes possible, to ensure the behavior of my EA is the same as it was. From what I have read on these forums and elsewhere, I think I have 2 options:

  1. Place a pending stop order at my entry price, however do not place the limits, and instead, monitor price using the EA and partially close the position at the prices where my limits were using the PositionClosePartial() method.
    • Advantages - probably not too bigger change to my EA
    • Disadvantages - In the event of an EA crash/VPS reboot/internet outage etc., then the partial close will not happen
    •       - There is no visual indication on the chart in the places where my limits were, unless I manually draw and delete objects on the chart which seems a bit messy to me, and they will also not be visible on the MT5 app on my phone
  2. Place multiple stops a the entry price, and for each one place a take profit where the limit would have been
    • Advantages - Fixes the disadvantages of option 1
    • Disadvantages - Bigger change to the EA
    •       - I'm guessing the execution time of both order entry and stop loss will be longer, given that there are multiple stops/stop losses, even thought they are at the same price.


Neither option above seems like as nice as a solution as it worked using netting.

What I would really like to have is a pending partial close limit to be available in hedging mode, but I assume that no such thing exists? As least I cannot find it.

Any other ideas how I could modify my EA?


Any help would be greatly appreciated.


 
Just ask your broker to change the hedge account to netting. 
 
Enrique Dangeroux:
Just ask your broker to change the hedge account to netting. 

Yes, that would be nice. Unfortunately I have already tried and they do not offer it. If you know of any EU brokers that offer MT5 netting accounts then please share.

 
kingkevbo:

Hi,

I have an EA that I wrote around 5 years ago, that I was using on a real account. I stopped trading when the SNB removed the cap on the Euro and my broker, Alpari, went bust.

That spooked me for a while but I have recently been wanting to give it another go. I have forward tested my EA on a demo MT5 netting account since June last year and it's still profitable. However, I cannot find any broker that allows netting, and I would like to update my EA to run on a hedging account.

My EA works by placing a buy stop and a number of sell limits (or sell stop and buy limits). When price reaches my stop, I open a position and gradually close the position if price continues to moves in my favour at each limit. There is a stop loss that closes the whole position if price does not move in my favour. 

In hedging mode, this method does not work as whenever a limit is reached, a new position is opened.

I place my orders using the methods provided with the CTrade class (BuyStop(), SellLimit() etc)

I have been reading about the best way of going about changing my EA, but I'm a bit stuck. Ideally I'd like to implement the minimum changes possible, to ensure the behavior of my EA is the same as it was. From what I have read on these forums and elsewhere, I think I have 2 options:

  1. Place a pending stop order at my entry price, however do not place the limits, and instead, monitor price using the EA and partially close the position at the prices where my limits were using the PositionClosePartial() method.
    • Advantages - probably not too bigger change to my EA
    • Disadvantages - In the event of an EA crash/VPS reboot/internet outage etc., then the partial close will not happen
    •       - There is no visual indication on the chart in the places where my limits were, unless I manually draw and delete objects on the chart which seems a bit messy to me, and they will also not be visible on the MT5 app on my phone
  2. Place multiple stops a the entry price, and for each one place a take profit where the limit would have been
    • Advantages - Fixes the disadvantages of option 1
    • Disadvantages - Bigger change to the EA
    •       - I'm guessing the execution time of both order entry and stop loss will be longer, given that there are multiple stops/stop losses, even thought they are at the same price.


Neither option above seems like as nice as a solution as it worked using netting.

What I would really like to have is a pending partial close limit to be available in hedging mode, but I assume that no such thing exists? As least I cannot find it.

Any other ideas how I could modify my EA?


Any help would be greatly appreciated.


My Broker is Netting , I trade Turkish exchange market CFD and indexes  can you share with me

Reason: