How to take partial profit  [SOLVED]

Questions about MultiCharts and user contributed studies.
bryan1618
Posts: 12
Joined: Nov 01 2016
Has thanked: 7 times

Dec 29 2016

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

User avatar
JoshM
Posts: 2196
Joined: May 20 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Dec 30 2016

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?

bryan1618
Posts: 12
Joined: Nov 01 2016
Has thanked: 7 times

Dec 30 2016

Hi Josh,

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

Thank you,

Bryan

Erik Pepping
Posts: 74
Joined: Aug 25 2007
Been thanked: 6 times

Dec 30 2016

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;

bryan1618
Posts: 12
Joined: Nov 01 2016
Has thanked: 7 times

Dec 30 2016

Thank you Erik. I will try that.

User avatar
JoshM
Posts: 2196
Joined: May 20 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Jan 01 2017

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;

bryan1618
Posts: 12
Joined: Nov 01 2016
Has thanked: 7 times

Jan 01 2017

Thank you very much JoshM!! This woked. Thank you all for helping.

Happy New Year's

Bryan