automatically close part of position and move stops to BE?
Created at 15 Jan 2014, 14:16
automatically close part of position and move stops to BE?
15 Jan 2014, 14:16
after reaching certain price
Replies
Spotware
17 Jan 2014, 10:35
You can call the ClosePosition method and specify the volume to close:
ClosePosition(position, 50000); // hardcoded volume
var volumeToClose = Symbol.NormalizeVolume(position.Volume * 0.5) // calculated volume ClosePosition(position, volumeToClose);
/api/reference/robot/closeposition-8635
@Spotware
jeex
18 Jan 2014, 13:05
BE
I think after closing half the position you still need to set SL to BE:
private double calcBE(Position p) { double totalCosts = Symbol.Spread + ((position.GrossProfit - position.NetProfit) / position.Volume / Symbol.PipValue); if (p.TradeType == TradeType.Buy) return p.EntryPrice + totalCosts; else return p.EntryPrice - totalCosts; }
and then modify the position with the calculated new SL of calcBE()
@jeex
Spotware
15 Jan 2014, 17:31 ( Updated at: 21 Dec 2023, 09:20 )
RE:
hgorski said:
You can start with the following sample: /forum/calgo-reference-samples/2247
If you like to set it manually, you may click on the security button next to the settings to the left of a position in the positions tab.
@Spotware