I finally had a day where I could see this happening more than once, and in one instance it was very obvious (ie many bars order not filled), so I thought it would be good to review/fix. MBTrading, SIM with automated strategy, NT7R1, Wint7 32bit. No other data feed. This happened about 6 hours into todays session. I do not use OnOrderUpdate
The following code is in the OnBarUpdate to place an order (cut down as much as possible):
//
protected override void OnBarUpdate()
{
if (CurrentBars[0] < 100 || CurrentBars[1] < 100)
return;
{
if (BarsInProgress == 0)
{ if ( (Position.MarketPosition == MarketPosition.Flat) && (timeSeries[0] >= 1) )
// Try to go LONG
{ if ( // all conditions code is here )
//
{ // if there is open order then cancel it and try again
if(iOrderL1 != null)
CancelOrder(iOrderL1);
iOrderL1 = null;
//
SetStopLoss(CalculationMode.Ticks, tVars.cStopLossTicks * vTickMult);
// Enter Long
if ((iOrderL1 == null || Historical) && iQuantity1 != 0)iOrderL1 = EnterLongLimit(0, true, iQuantity1, Closes[0][0], sENTRY1L);
//
MyEntryBar = CurrentBar;
return;
}
}
}
The 'MyEntryBar' is used to track #of bars since order was placed. The following code is in the OnExecution part of the strategy:
protected override void OnExecution(IExecution execution)
{ if (iOrderL1 != null)
{
if (iOrderL1.Token == execution.Order.Token)
{// PENDING ORDERS (PendingSubmit / Working / Accepted)
if (
execution.Order.OrderState == OrderState.PendingSubmit ||
execution.Order.OrderState == OrderState.Working ||
execution.Order.OrderState == OrderState.Accepted
)
// ------------ other order code is installed here ---------- //
// Not Filled Order Response on 1st bar after orderbar ?
if (execution.Order.OrderState != OrderState.Filled && CurrentBar == MyEntryBar+1 )
{
if(iOrderL1 != null)
Print("Failed to fill L1 order. Time of bar="+Time[0]+", CurrentBar#="+CurrentBar);
}
// Not Filled Order Response after 1 bars ?
//----------------------------
if (execution.Order.OrderState != OrderState.Filled && CurrentBar > MyEntryBar+1 )
{
if(iOrderL1 != null)
CancelOrder(iOrderL1);
Print("Failed to fill L1 CANCEL #1 Time of bar="+Time[0]");
//clear the order variable
iOrderL1 = null;
}
// ------------ other order code is installed here ---------- //
The following code is in the structures:
//_______________________
public struct TradeStruct_EnterLongLimitV07F
{ public int enterLong;
public double cStopLossTicks;
}
//
private const string sENTRY1L = "e1L";
private const string sTARGET1 = "eT1";
//
private const string sSTOPLOSS = "eSL";
// ** STRATEGY CALC VARIABLES
private TradeStruct_EnterLongV07F tVars;
double vLosses, vWins;
double cAsk, cBid, cSpread;
private bool strategyInitialized = false;
// ** INDIE CALC VARIABLES
private Font vFont;
private bool init = false;
//
private int MyEntryBar = 0;
private DataSeries timeSeries;
// -----and so on ------------- //
There is no print output in the output box to show that the code is in use for the monitoring of the #of bars since unfilled order was placed, and the order stays outstanding until filled. Not exactly what I enjoy seeing!!!
Do I have code in the wrong section? Should ' MyEntryBar ' be a double ? (if so, how to increment a double each bar?) Should there be another entry of some kind in the OnInitialize ??
Other than this the code runs fine: no compile issues.
Help is appreciated!
Jon
ps attach snippets from the 830am time period showing that the order print statements are there but not the prints from the OnExecution
Comment