I am using the Managed Approach in to build my strategy and Strategy Builder. However Strategy Builder does not have CancelOrder setup, so i have unlock and code my self.
I am using the Managed Approach from the wizard with the following in NT8.
EnterLongLimit() (isLiveUntilCancelled is set to true)
EnterShortLimit() (isLiveUntilCancelled is set to true)
SetStopLoss()
SetProfitTarget()
Problem
1. I would like to Cancel the EnterLongLimit if 28 ticks from limit order and a fill has not been occurred. How can i accomplish this?
Solution
Here is my approach:
private Order myEntryLongOrder = null; // tracking the order number
private int MyEntryPrice; // tracking pending entry limit price to fill
if ((EMA1[0] > EMA2[0])
{
EnterLongLimit(Convert.ToInt32(DefaultQuantity), (GetCurrentBid(0) + (-8 * TickSize)) , @"Long"); // submit limit order
myEntryLongOrder = EnterLongLimit(Convert.ToInt32(DefaultQuantity), (GetCurrentBid(0) + (-8* TickSize)) , @"Long"); // assign order id to track status of order
MyEntryOrder = Convert.ToInt32((GetCurrentBid(0) + (-8 * TickSize)) ); // tracking pending entry limit price to fill
}
// CANCEL LONG LIMIT PENDING ORDER if 30 amount of ticks above the LIMIT LONG price has occured AND order still pending to be filled
if (myEntryLongOrder != null && Close[0] >= MyEntryOrder + 30* TickSize) // if ORDER NUMBER is NOT blank, that means the order is PENDING
{
CancelOrder (myEntryLongOrder);
}
Questions
1. Is my approach correct? It seems to work in back test, but I am concerned "myEntryLongOrder != null " is not really tracking the state of the order on the broker side.
2. When I cancel the long order will the Stop and profit target order automatically cancel as well?
Thank you kindly.
Comment