My Broker doesn't support OrderCloseBy()

 

My Broker doesn't support OrderCloseBy() and my current strategy adjusts its position size each bar. For example at 10am it may be +3 lots, at 11am it may be +4 lots and at 12noon it may be +2 lots.

My problem is how to implement this as cleanly and cost effectively as possible.

Based on the example above I would need to go long 3 at 10am then at 11am go long 1 then at 12noon I would have to close the 1 and go short 1. This leaves me with long 3 and short 1 as two trades with a net a net +2 position. This is costly in terms of paying double on spread and looks untidy.

Can anyone think of a better way to handle this with MT4?

 
stewart:

Can anyone think of a better way to handle this with MT4?

Yes, you want totals of 3 lots, 4 lots then 2 lots all LONG (assumed).

Buy 3 lots = 3

Buy another lot = 4

close 2 = 2.

Job done. Why go short when you can just close part of an existing long.

 

Thanks Dabbler,

I'm not sure I can close part of an open live position though? If you have a position open in MT4, can you close part of it?

 
stewart:

Thanks Dabbler,

I'm not sure I can close part of an open live position though? If you have a position open in MT4, can you close part of it?

Why else would OrderClose() take a parameter for the trade size ? double lots
 

Raptor,

You are awesome. Yours is one of those simple answers that has saved the day for me. I was trying to come up with a complicated solution for something so simple.

Interestingly it changes the order number when I close part of a trade. This is ok, but worth me knowing.

Stewart

Reason: