I was redirected here by the guys at [email protected].
My problem:
As it enters a position, the stop loss should be sent to the broker.
Usually, however, this order stays in the state 'Initialized', and it doesn't appear in TWS at all. Being aware of this I restart the strategy by pressing f5 on the chart, and then my stop loss is sent to the TWS, and in NT it becomes Working. This happens quite frequently with my live IB account, but never with my simulated IB account.
It happened today at 9:30 and 15:00.
I disaggree with that, because as I've mentioned it happens only with my live IB account,
and even with my live account restarting the strategy allows the stoploss to be activated.
Anyway my StopLoss setting code :
I am setting the stoploss whenever there's an execution.
protected override void OnExecution(IExecution execution)
{
IOrder ord=execution.Order;
base.OnExecution(execution);
if(manualStop && Position.MarketPosition != MarketPosition.Flat) return;
if(ord.OrderAction==OrderAction.Buy && ord.OrderType != OrderType.Stop && Position.Quantity>0)
{
SetStopLoss(Name+" EnterLong",CalculationMode.Price,avgPrice+ln/(Position.Quantity),false);
if(!optimizing)
{
stopValue = avgPrice+ln/(Position.Quantity);
uplMinValue = avgPrice+uplmin/Position.Quantity;
if(MyGlobals.OrderWindow != null && !Historical) MyGlobals.OrderWindow.updateStopLoss(this);
drawStopLine();
}
}
else
{
SetStopLoss(Name+" EnterLong",CalculationMode.Price,TickSize,true);
if(!optimizing)
{
stopValue = 0;
uplMinValue = 0;
if(MyGlobals.OrderWindow != null && !Historical) MyGlobals.OrderWindow.updateStopLoss(this);
}
}
}

Comment