I've been unable to get ExitLongStop() to move my stops properly. I'm able to set an initial stop, but sometimes (not all the time) when I call ExitLongStop() to move my initial stop, the ExitLongStop() procedure returns a null. Here's the pertinent code snippet:
private IOrder longOrder = null; // order for long position
private IOrder stopOrder = null; // order for stop
private double stopLoss = 0.0;
protected override void OnBarUpdate()
{
if (Position.MarketPosition == MarketPosition.Long)
{
if (stopLoss < MyStopLogic())
{
stopLoss = MyStopLogic();
SetStopPrice(stopLoss, "MyStop", "Entry1");
}
}
}
protected override void OnOrderUpdate(IOrder order)
{
if (longOrder != null && longOrder.Token == order.Token)
{
if (order.OrderState == OrderState.Filled)
{
stopLoss = MyInitialStop();
if(stopOrder == null)
SetStopPrice(stopLoss, "InitialStop", "Entry1");
}
}
}
private void SetStopPrice(double dStop, string strExit, string strEntry)
{
stopOrder = ExitLongStop(0,true,1,dStop, strExit, strEntry);
}
What conditions would cause the back-tester to return a null from ExitLongStop()? I'm using liveUntilCancelled so do I have to first cancel my Initial stop before setting a new stop? If I use ExitLong(), I do not get null orders for stop orders executed after the initial stop and the back-tester exits the open position immediately and properly.
Thanks,
David
dbw451
Comment