Have been exploring some planed scale in/out techniques and this scale out is NOT working as I am trying to code it do to. Please see the attached screenshot.
What should be happening is that the new open positions should be treated like a stack and subsequent exits are matched with the most recent entries. In the attached example, it should be exiting the 400k position FIRST - instead though MC is exiting the oldest positions first. Can I force it to exit the oldest position first?
Here is the code:
Code: Select all
private IOrderPriced buyOrder;
private IOrderPriced buyTarget;
protected override void Create()
{
buyOrder = OrderCreator.Limit(new SOrderParameters(Contracts.UserSpecified, "GStat_LE", EOrderAction.Buy));
buyTarget = OrderCreator.Limit(new SOrderParameters(Contracts.UserSpecified, "GStat_LX", EOrderAction.Sell, OrderExit.Total));
}
protected override void CalcBar()
{
if (StrategyInfo.MarketPosition > 0)
{
ManageLongs();
}
}
private void ManageLongs()
{
ITradeOrder lastTradeOrder = CurrentPosition.OpenTrades[CurrentPosition.OpenTrades.Count - 1].EntryOrder;
buyOrder.Send(lastTradeOrder.Price - 0.002, CurrentPosition.OpenLots);
if (CurrentPosition.OpenTrades.Count > 1)
{
buyTarget.Send(lastTradeOrder.Price + 0.002, lastTradeOrder.Contracts);
}
else
{
buyTarget.Send(StrategyInfo.AvgEntryPrice + 0.005, lastTradeOrder.Contracts);
}
}