NE
Double a position?
13 Jun 2015, 06:47
In cTrader you are able to double and reverse a position. How can you do that via code? Here's what I've coded so far but I would like to double the position keeping it as one trade at the point I wrote "//double position"
protected override void OnTick()
{
if (Positions.Count < 1)
{
ExecuteMarketOrder(TradeType.Sell, Symbol, 10000);
}
else
{
foreach (var position in Positions)
{
if (position.Pips > 5)
{
ClosePosition(position);
}
else
{
if (position.Pips < -10)
{
//double position
}
}
}
}
}
Thanks in advance for you help ;)

tradermatrix
13 Jun 2015, 20:39
RE:
Neptune said:
you can not build your robot in this way ..
you reduce to 1 order (if Positions.Count <1)" you can not place another reverse order (count = 2)
if takeprofit sell order is executed first:
must cancel order buy X2.
I do not know the code of your robot and what you want to do.
but look if my sample can help.
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NewcBot : Robot { protected override void OnStart() { ordre1(); Positions.Closed += OnPositionsClosed; } private void ordre1() { ExecuteMarketOrder(TradeType.Sell, Symbol, 10000, "robot1", null, 5); var buyOrderTargetPrice = Symbol.Ask + 10 * Symbol.PipSize; PlaceStopOrder(TradeType.Buy, Symbol, 10000 * 2, buyOrderTargetPrice, "robot2", null, 30); } private void OnPositionsClosed(PositionClosedEventArgs args) { { Print("Closed"); var position = args.Position; if (position.Label != "robot1" || position.SymbolCode != Symbol.Code) return; foreach (var pendingOrder in PendingOrders) { CancelPendingOrder(pendingOrder); } } } } }@tradermatrix