Page 1 of 1

How to take partial profit

Posted: Dec 29 2016
by bryan1618
Hi All,

Just wanted to know if any of you can help me or point me in the direction to find out how to code the following:

I want to take 50% of my profit as soon as my position has gone 20 pips in my favor after my breakeven has been activated.

I am currently using the stops and targets study provided by MC and its working great, I use a stop loss and a break even once my position has reached the determined amount of pips (in my case 20 pips). What I cannot do and hopefully I can get some help or guidance is how to take 50% of my profit once I my breakeven has been activated.

Thank you,

Bryan

Re: How to take partial profit

Posted: Dec 30 2016
by JoshM
I want to take 50% of my profit as soon as my position has gone 20 pips in my favor after my breakeven has been activated.
To clarify before discussing code: if you say, "take 50% of my profit (...)", do you mean:

close half of my position after reaching the +20 pips profit point,
or
at the +20 profit point, close as much as my position as needed to achieve 50% of my profit target?

Re: How to take partial profit

Posted: Dec 30 2016
by bryan1618
Hi Josh,

That would be the first one close half of my position after reaching the +20 pip profit point.

Thank you,

Bryan

Re: How to take partial profit

Posted: Dec 30 2016
by Erik Pepping
for currencies if you have bought for 0.2 lot with
buy ("buy") 20000 contracts this bar at market;

You can sell half

Sell ("sell") 10000 contracts this bar at market;

Re: How to take partial profit

Posted: Dec 30 2016
by bryan1618
Thank you Erik. I will try that.

Re: How to take partial profit

Posted: Jan 01 2017
by JoshM
That would be the first one close half of my position after reaching the +20 pip profit point.
You can try something like this for that (untested):

Code: Select all

// Manage long position
if (MarketPosition(0) > 0) then begin

if (Close >= EntryPrice(0) + 0.0020) then

Sell ("Partial TP XL") (CurrentContracts / 2) Contracts next bar at market;

end;

// Manage shorts
if (MarkPosition(0) < 0) then begin

if (Close <= EntryPrice(0) - 0.0020) then

BuyToCover ("Partial TP XS") (CurrentContracts * 0.5) Contracts next bar at market;


end;
Edit: it's probably more convenient to use limit orders instead of the market orders of my above example. In that case (and in the case of the above example), you'll need to figure out some way in which you can determine whether your strategy has already sold half of the position or not. (Otherwise, the strategy keeps submitting orders for half of the position size.)

One example you can build off is:

Code: Select all

Variables:
originalPositionSize(0);

originalPositionSize = ...

if (MarketPosition(0) > 0) then begin

if (CurrentContracts = originalPositionSize) then

Sell ("XL Partial TP") (CurrentContracts / 2) Contracts at EntryPrice(0) + 0.0020 limit;

end;

Re: How to take partial profit  [SOLVED]

Posted: Jan 01 2017
by bryan1618
Thank you very much JoshM!! This woked. Thank you all for helping.

Happy New Year's

Bryan