1) Computer Windows started updating while Strategy was running
2) My Broker system never "accepted" a stop order after opening the position - it was accepted in the demo at the same time but not in Live account
In both scenarios my strategy could not manage any manual intervention after the fact or just update properly on the next bar update.
- Scenario 1 - I wanted to add a manual position and then have the Strategy take over but it cannot take over on manual order positions.
- Scenario 2 - On the next Bar Update it should have recognized the Short Stop conditions were present and added the Short stop. I added a Short Stop myself but since strategy was still running when a new long order conditions came in I ended up with double long position - one to close the order I already closed with manual Short stop and one to for the new position - a long overfill.
The main problem I believe is this code:
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
StartBehavior = StartBehavior.WaitUntilFlat;
}
}
It should be this I believe (please confirm):
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
IsAdoptAccountPositionAware = true;
StartBehavior =StartBehavior.AdoptAccountPosition
}
}
I do believe I need more than just this. I have 10 Unique Order entries per side and is not just one type.
- Scenario 1 - If I enter a manual order since the initial entry was missed....I believe I need code to manually match it to one of my 10 Unique orders (or create a new "Long11ManualOrder" to match it to)
- Scenario 2 - Since the system added the initial entry and identified it, I would think it the Strategy would know which of the Unique Orders was used. BUT I am not sure if the change above in green alone will be enough for this Scenario for the Strategy to match it to the order type and take over.
Please advise how best to handle each scenario?
-------------------------------------------------------------------------------
A Sample snippet of my unique Order names - this is just for context so it makes it easier to understand:
protected override void OnBarUpdate()
{
if (High[0] > Position.AveragePrice * 1.0014)
{
ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice - MaxLongStopPoints * 4 * TickSize, "LongStops1", "Long1");
ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice - MaxLongStopPoints * 4 * TickSize, "LongStops2", "Long2Reverse");
}
//8 more Stops not being shown (Long3, Long4, Long 5, etc)
}
protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string nativeError)
{
//Assign Stop Orders
if (order.Name == "LongStops1" && order != StopLongOrder1)
{
StopLongOrder1 = order;
}
if (order.Name == "LongStops2" && order != StopLongOrder2)
{
StopLongOrder2 = order;
}
if (order.Name == "LongStops3" && order != StopLongOrder3)
{
StopLongOrder3 = order;
}
if (order.Name == "LongStops4" && order != StopLongOrder4)
{
StopLongOrder4 = order;
}
//6 more not being shown
}
protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity, Cbi.MarketPosition marketPosition, string orderId, DateTime time)
{
//Long Targets and Initial Stops
if (execution.Order.Name == "Long1" && execution.Order.OrderState == OrderState.Filled)
{
ExitLongStopMarket(0, true, QuantitySize, BigT_Auto_Equilibrium_V21.PriorS1[0], "LongStops1", "Long1");
ExitLongMIT(0, true, QuantitySize, BigT_Auto_Equilibrium_V21.PriorR3[0] + TargetBoost * 4 * TickSize, "LongTarget", "Long1");
}
if (execution.Order.Name == "Long2Reverse" && execution.Order.OrderState == OrderState.Filled)
{
ExitLongStopMarket(0, true, QuantitySize, BigT_Auto_Equilibrium_V21.PriorS1[0], "LongStops2", "Long2Reverse");
ExitLongMIT(0, true, QuantitySize, BigT_Auto_Equilibrium_V21.PriorR3[0] + TargetBoost * 4 * TickSize, "LongTarget", "Long2Reverse");
}
//8 more not being shown
}

Comment