Hedging Grid Mix Lots @ Boxxocode
-
This is a really interesting one from Boxxocode, strangely it seemed to work first time and then I added a TP in to close the widening gap it creates from the buy/sell.
Since doing that it now seems to be bugged (even though I've rebuilt from new again. Does metatrader store code on the strategy tester?
The fault in this is it works as intended for the first sell and buy close profit and then does the opposite on the 2nd batch and forever, instead of close at £2 profit it closes £2 at loss??
If someone could test it? Or has already coded it to check?
I've watched the video several times and checked my code and all seems to be as instructed.Shared copy is:
https://fxdreema.com/shared/pgt52et4


-
Watching it again it takes the losses when the equity is positive but there is an opposing buy/sell so if the sells are negative and buy is positive it continues to close the sells, so i think the code may be correct and I've not fully understood the logic... so it might be able to be improved when in positive equity. Or it might be not designed to run continuously on strategy tester..
-
Blocks 15 and 21 are redundant. You can remove them.
-
@l-andorrà thank you I will remove them

-
https://fxdreema.com/shared/gCSoXW6ge
This still closes basket trades at a loss, i think the logic only works when it is in negative equity so must be the boxes ObNb and OsNs formula (34 and 40). So when it has a positive balance the trades will close out on trade 3 at the close out money value, it reverses itself... weird but probably a simple fix somewhere?
-
What i thought this should do is:
Buy1
Buy2
Buy 3
Buy4
Buy5
Buy6
Buy7Lets say these are at 10 pip grids when buy7, buy6, buy5, buy4 reach +£ including the oldest Buy1 then it closes 1,7,6,5, leaving 2,3,4 running which then in turn become Buy1, Buy2, Buy3 and so on...
-
Right I think I've identified the problem, it is when it is in positive equity boxes 9 to 18 reverse the constant "Close_newest_at_order" 2. I'm not sure why it does this? Would a Pass or reset Counter make it work? And where would I put it so code resets the current balance/equity to run again.
I've added a close all trades at + unrealized profit but this hasn't worked.
-
I never use 'basket of trades' blocks. I always use 'for each trade' structures instead. They are 100% effective. You should substitute them IMHO.
-
@l-andorrà thanks I'll see if I can figure it out but for each trade block I would need multiples to count the buys and sells?
-
@bigfoot Correct.
-
@l-andorrà Thanks for pointing me in the right direction, I've figured it out now

-
Just one more question if I stop trading and turn my PC off, then the next day turn on again will the old trades still be counted or doI need to input more code? This would be leaving the ea on screen and not on Init?
-
@bigfoot No, once you turn off your PC all information regarding previous trades is lost. The only two ways to do that is by using 'terminal variables' (not the 'normal' variables) or by using a specific 'for each trade' structure in the 'on init' tab with this block:

-
@l-andorrà ah ok I'll have a look at that, thank you.
-
@l-andorrà would you mind having a look at this please? I've added the for each trade as loops and created variables to hold the values however I'm struggling with the formula. Currently it is just closing all trades at once when the oldest comes back into profit?
I want to take the oldest losing trade and close that trade along with the in profit trades when those values reach a value in money. The next oldest trade in loss is left running and becomes the oldest and then it continues in the loop taking in profit trades to close them and the oldest loser.
Boxes 25 to 36 close the buy trades and boxes 37 to 48 close the sell trades.
Feels like I am close to solving this but not quite close enough!
Thanks
Bigfoot.
-
-
Trade information is stored on the terminal, which means even after closing and restarting you can access the data.
-
@jstap thanks jstap good to know. I'll do this after i've sorted the close trades bit out

-
@bigfoot I've now changed boxes 28,29,40 and 41 to the pink loop check profit and check loss. This is better but still closing all trades when profit (all) reaches the TP. Still can't figure out how to only (close the oldest loser) and (all in profit) at the TP, even though my logic seems pretty good...
-
Do you want to check the combined value before closing the oldest least profitable one?