I am running a strategy in sim mode, openning 2 positions and using SetStopLoss to set stop for both. When the strategy runs live, trades and orders are triggerd fine.
If for some reason a connection is lost or the strategy is dissabled and I try to synchronise and re-enable I have the following problems:
1. The old orders remain in working condition so I need to cancel them manually. Some old orders are even stuck and are shown as cancel pending (see attached image)
2. When new orders are submitted, only one stop loss is set.
What am I doing wrong?
Here is my code
else if (State == State.Realtime)
{
// one time only, as we transition from historical
// convert any old historical order object references
// to the new live order submitted to the real-time account
if (longEntryOrder1 != null)
longEntryOrder1 = GetRealtimeOrder(longEntryOrder1);
if (longEntryOrder2 != null)
longEntryOrder2 = GetRealtimeOrder(longEntryOrder2);
if (shortEntryOrder1 != null)
shortEntryOrder1 = GetRealtimeOrder(shortEntryOrder1);
if (shortEntryOrder2 != null)
shortEntryOrder2 = GetRealtimeOrder(shortEntryOrder2);
}
void Buy()
{
if (TradingFutures)
{
lots = (int) (InitialCapital / 50000);
longEntryOrder1 = EnterLong ( lots , "L1");
longEntryOrder2 = EnterLong ( lots , "L2");
base.SetStopLoss("L1", CalculationMode.Price, stopPrice, false );
base.SetStopLoss("L2", CalculationMode.Price, stopPrice, false );
base.SetProfitTarget("L1", CalculationMode.Price, Ptarget, false);
}
}
Kind regards
Ioannis
Comment