I have a strategy where I want to get in x ticks away from current price on a range bar chart. But if the next range bar does not get me in, then I want to cancel the order when that range bar closes.
To test this I forced the Limit price on a Long entry to 50 for CL (curr price 46.23) when this is done. I can see the Limit price set to 50 from the OnOrderUpdate print commands. In Bold you can see it change states from Pending, Accepted, Working, Filled and the Execution price is a Buy Limit of 50 even though that is never reached.
I must be doing something wrong. The SIM account should not execute my Buy Limit at a price that is not traded. Which should then let me monitor the IOrder status so if I see the Order as Working then I can execute CancelOrder when CurrentBar > EntryBar+1
Any suggestions?
-----------
In the output Window I get the following:
Time: 11/2/2016 9:29:55 AM PrvADR7: 1.21
SS Green:158 Enter Long 46.23 BB: 46.26 RSI: 66.57 Stop: 46.11 Target: 46.41
Order='NT-00019/Sim101' Name='SS Green:158' State=PendingSubmit Instrument='CL 12-16' Action=Buy Limit price=50 Stop price=0 Quantity=1 Strategy='eTesting' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='a91f5468e3924b8090fe330ddfd1c2b1' Gtd='12/1/2099 12:00:00 AM'
Order='NT-00019/Sim101' Name='SS Green:158' State=Accepted Instrument='CL 12-16' Action=Buy Limit price=50 Stop price=0 Quantity=1 Strategy='eTesting' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='a91f5468e3924b8090fe330ddfd1c2b1' Gtd='12/1/2099 12:00:00 AM'
Order='NT-00019/Sim101' Name='SS Green:158' State=Working Instrument='CL 12-16' Action=Buy Limit price=50 Stop price=0 Quantity=1 Strategy='eTesting' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='a91f5468e3924b8090fe330ddfd1c2b1' Gtd='12/1/2099 12:00:00 AM'
Order='NT-00019/Sim101' Name='SS Green:158' State=Filled Instrument='CL 12-16' Action=Buy Limit price=50 Stop price=0 Quantity=1 Strategy='eTesting' Type=Limit Tif=Gtc Oco='' Filled=1 Fill price=50 Token='a91f5468e3924b8090fe330ddfd1c2b1' Gtd='12/1/2099 12:00:00 AM'
From OnExecution:
Execution='NT-00012' Instrument='CL 12-16' Account='Sim101' Name='SS Green:158' Exchange=Default Price=50 Quantity=1 Market position=Long Commission=0 Order='NT-00019' Time='11/2/2016 9:29:55 AM'
Execution='NT-00013' Instrument='CL 12-16' Account='Sim101' Name='Stop loss' Exchange=Default Price=46.22 Quantity=1 Market position=Short Commission=0 Order='NT-00020' Time='11/2/2016 9:29:55 AM'
Losing Trade! Exit @ 46.22 11/2/2016 9:29:55 AM Max Favor: 46.23
Reset First Leg BB Crossover
protected override void OnOrderUpdate(IOrder order)
{
if (entryOrder != null && entryOrder == order)
{
Print(order.ToString());
if (order.OrderState == OrderState.Filled)
entryOrder = null;
}
// Cancel Order if next bar does not fill (If more than 1 bars has elapsed, cancel the entry order)
if (entryOrder != null)
{
if (EntryBar > 0 && CurrentBar > EntryBar + 1 && order.OrderState == OrderState.Working)
{
Print("here");
CancelOrder(entryOrder);
Print("Order Cancelled: Not Filled on next bar: " + CurrentBar);
}
if (order.OrderState == OrderState.Filled)
entryOrder = null;
} // End Cancel Order check
}
Comment