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
How to take partial profit [SOLVED]
- JoshM
- Posts: 2196
- Joined: May 20 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
To clarify before discussing code: if you say, "take 50% of my profit (...)", do you mean: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.
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?
-
- Posts: 74
- Joined: Aug 25 2007
- Been thanked: 6 times
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;
buy ("buy") 20000 contracts this bar at market;
You can sell half
Sell ("sell") 10000 contracts this bar at market;
- JoshM
- Posts: 2196
- Joined: May 20 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
You can try something like this for that (untested):That would be the first one close half of my position after reaching the +20 pip profit point.
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;
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;