| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| Hedging - Close open positions in profit first https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=4657 |
Page 1 of 2 |
| Author: | keydcuk [ Sun Mar 20, 2016 10:07 am ] |
| Post subject: | Hedging - Close open positions in profit first |
Hello, I am not an Empty4 coder but I've got a code related question that I am hoping to resolve. If I've got an EA that hedges, is there a way to program it so that when the EA closes the hedge that it closes the positions in profit first? The reason I ask this is that if a trade is in a massive hedge and the EA decides to close the positions that are in negative pips first, there is a possibility that it could blow and account before realizing that there was an overcoming amount of profit on the positive side of the hedge. Thanks for your attention. Daniel |
|
| Author: | SteveHopwood [ Sun Mar 20, 2016 12:46 pm ] |
| Post subject: | Hedging - Close open positions in profit first |
You can use my FIFO code, assuming that the oldest trades are likely to be the most profitable. Sing out if you need any help. |
|
| Author: | keydcuk [ Sun Mar 20, 2016 12:59 pm ] |
| Post subject: | Hedging - Close open positions in profit first |
Hi Steve, Thanks for your reply. FIFO might solve part of my problem as if it is in a hedge, it might close some sells and some buys in an alternate fashion of some sort rather than choosing to close all the buys first or all the sells first, but ideally I would like the EA to identify that once the basket TP has been hit, that it closes the profitables first before the losers. If there is no solution to this, where might I find your FIFO code? Thanks, Daniel |
|
| Author: | SteveHopwood [ Sun Mar 20, 2016 1:43 pm ] |
| Post subject: | Hedging - Close open positions in profit first |
Yes, you are correct. The biggest losers will also close first, alternating with the biggest winners. There is a solution and I will add it to GW - I am going to reopen that thread later. I will add it now and point you to the correct line numbers so you can adapt it to your code. |
|
| Author: | keydcuk [ Sun Mar 20, 2016 2:02 pm ] |
| Post subject: | Hedging - Close open positions in profit first |
Thanks Steve, I try not to be a pain to you. I do enjoy this forum website and am only trying to contribute in a positive way. It is not my intentions to upset you. I do get you when you talk about the filtering of the posts etc... I will try to be more switched on to what is appropriate to post as well as where to post. Thanks for being so reasonable and forgiving with me. Daniel |
|
| Author: | SteveHopwood [ Sun Mar 20, 2016 2:48 pm ] |
| Post subject: | Hedging - Close open positions in profit first |
This version will not actually work on accounts whose broker demands true FIFO, but those traders are not using the ea anyhow because they cannot hedge. My Fifo stuff works by storing ticket numbers in an array. Here we need two of them as we want the profitable side of the position closing first, so:
Code: Select all |
|
| Author: | keydcuk [ Sun Mar 20, 2016 3:32 pm ] |
| Post subject: | Hedging - Close open positions in profit first |
Brilliant! Thanks for your help Steve. I genuinely appreciate it. Daniel |
|
| Author: | pascalx [ Thu Mar 31, 2016 1:40 pm ] |
| Post subject: | Hedging - Close open positions in profit first |
Managing your buys and sells in a container is paramount. I would advice to reduce calls to ArrayResize() though. I don't know its implementation, but it is very likely that it will allocate memory every time. If you plan on running the EA for long time, I suggest to allocate as much as possible on initialization and reduce allocation on runtime. You definitely want to avoid memory fragmentation. It will also benefit performance. |
|
| Author: | hopfi2k [ Mon Apr 11, 2016 10:22 pm ] |
| Post subject: | Hedging - Close open positions in profit first |
pascalx, while you are right on ArrayResize(). I nevertheless would like to point out to the documentations of recent MQL4 version (>900), that support a third parameter reserved_size preventing most of the in memory allocations and fragmentation: https://docs.mql4.com/array/arrayresize. Cheers, Andy |
|
| Author: | pascalx [ Tue Apr 12, 2016 12:51 pm ] |
| Post subject: | Hedging - Close open positions in profit first |
I know. My container classes make use of that too to reduce allocations. |
|
| All times are UTC | Page 1 of 2 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|