I am working on a backtest strategy on sugar no.11 using the backtesting tool and I am entering a long order using the unmanaged approach and can't seem to adjust the stoplimit value after the order has been filled.
Is this normal?
I have a reference the previous order (its set as a private member variable in the strategy and then I call
private IOrder oldO;
... in my main method()....
if(tightenStop ){
ChangeOrder(oldO, oldO.limitPrice, oldO.quantity, newStopLimitVal);
}
When I look at the order directly afterwards the stopLimit is unchanged. I have set the unmanaged = true as well in my initialize block and have followed all the examples. I have 12 years programming experience so I can't see anything wrong with the code or API calls its just seems something configuration wise isn't right.
Thanks in advance...
private IOrder prevLongTrade = null;
private IOrder prevShortTrade = null;
private double originalOrderAtr = 0;
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
Unmanaged = true;
AccountSize = 100000;
EntriesPerDirection = 6;
ClearOutputWindow();
.....................
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
/*
* Long Part
*/
//place the order
if(prevLongTrade == null)
{
//create a new one
Print("Creating new order...");
prevLongTrade = SubmitOrder(0, OrderAction.Buy, OrderType.StopLimit, orderAmt, earlyLongPrice, earlyLongStop, "", "longMid" );
Print(String.Format("NewLongTrade: {0} LimitPrice: {1} StopPrice: {2} Filled: {3}", prevLongTrade.OrderState, prevLongTrade.LimitPrice, prevLongTrade.StopPrice, prevLongTrade.Filled));
}else{
//use the old one and modify it...
Print(String.Format("PrevLongTrade: {0} LimitPrice: {1} StopPrice: {2} Filled: {3}", prevLongTrade.OrderState, prevLongTrade.LimitPrice, prevLongTrade.StopPrice, prevLongTrade.Filled));
if(prevLongTrade.OrderState == OrderState.Working){
Print("modifying/cancelling open working order...");
Print(String.Format("adjusting price orig[{0}] new[{1}] & Stop loss orig[{2}] new[{3}] ", prevLongTrade.LimitPrice, earlyLongPrice, prevLongTrade.StopPrice, earlyLongStop));
ChangeOrder(prevLongTrade, prevLongTrade.Quantity, earlyLongPrice, earlyLongStop);
Print(String.Format("NewLongTrade: {0} LimitPrice: {1} StopPrice: {2} Filled: {3}", prevLongTrade.OrderState, prevLongTrade.LimitPrice, prevLongTrade.StopPrice, prevLongTrade.Filled));
}else if(prevLongTrade.OrderState == OrderState.Filled){
Print("adjusting Stop loss...");
if(diffGreaterThanX){
....
if(newStop > prevLongTrade.StopPrice){
ChangeOrder(prevLongTrade, prevLongTrade.Quantity, prevLongTrade.LimitPrice, 0);
Print(String.Format("NewTightenedLongTrade: {0} LimitPrice: {1} StopPrice: {2} Filled: {3} : qty: {4}", prevLongTrade.OrderState, prevLongTrade.LimitPrice, prevLongTrade.StopPrice, prevLongTrade.Filled, prevLongTrade.Quantity)); }
}
}
}
}

Comment