protected override void OnBarUpdate()
{
if (ToTime(Time[0])<opentime)
exittime=0;
if (ToTime(Time[0])>opentime && ToTime(Time[0])<stoptime)
{
if (mysignal && !init && Positions[0].MarketPosition==MarketPosition.Flat && ToTime(DateTime.Now)>=exittime)
{
LE= EnterLong(tradesize,"LE");
init = true;
}
}
}
protected override void OnExecution(IExecution execution)
{
// check for fill on long entry order
if (LE != null && LE.Token == execution.Order.Token)
{
// place long profit GTC
LETarget=ExitLongLimit(0,true,LE.Quantity,Position s[0].AvgPrice+pt,"LPTX","LE");
init=false
}
else
{
if (LETarget!=null && LETarget.Token==execution.Order.Token)
exittime=ToTime(DateTime.Now.AddSeconds(delaysecon ds));
}
}
So basically what I am doing is setting my exittime variable to 0 when we are outside of trading hours, and setting it to the time my exit order was filled + 'x' number of seconds during the trading day. I then check that the current DateTime>my exittime, which would hold a value of 0 at the beginning of the session, or my exittime + 'x' number of seconds if I have been filled on a profit target order. This code is working probably about 80% of the time, and everything seems correct when I debug with visual studio. Anyone else have any ideas on this?
Comment