Profile Picture

IB and time in force

Posted By NNNKT 6 Years Ago
Message
Posted Friday January 07 2011
Hi,

It seems like RE always sends order with "time in force" = GTC to IB.
The problem with this is that certain order types (Market on Close) requires TIF = DAY !!

Is there some way I can control which TIF are used then orders are send with the IB TWS plugin???
I've tried to orderSetting. BarsValid = 1 etc., but always GTC...

I'm running RE 2010 build 32
Christian

phg
Supreme Being (48,273 reputation)Supreme Being (48,273 reputation)Supreme Being (48,273 reputation)Supreme Being (48,273 reputation)Supreme Being (48,273 reputation)Supreme Being (48,273 reputation)Supreme Being (48,273 reputation)Supreme Being (48,273 reputation)Supreme Being (48,273 reputation)
Posted Friday January 07 2011
I'm just a bit curious: AFAIK, RE does not support the (IB) MOC/MOO order types, so I'm not clear how that applies here? (But note: I would like to see support added for more IB oder types, but that's just me.)

Is the order not being canceled after one bar when BarsValid=1, whether or not the order has been submitted to the broker? (I can see how that might be a problem when that is inclusive of the last bar of the day?)

-Pete

See also Yahoo group about applying RE.

Posted Saturday January 08 2011
Seems like the latest builds do support MOC.

PositionSettings settings = new PositionSettings();
settings.PositionType = PositionType.Long;
settings.OrderType = OrderType.MarketOnClose;
settings.BarsValid = 2;
OpenPosition(settings);

The MOC order is sent to IB (and it is displayed in the TWS for a short while), but is cancelled by IB with the message: MOC order rejected because of wrong time in force.

The MOC order requires TIF = DAY to be accepted.
phg
Supreme Being (48,273 reputation)Supreme Being (48,273 reputation)Supreme Being (48,273 reputation)Supreme Being (48,273 reputation)Supreme Being (48,273 reputation)Supreme Being (48,273 reputation)Supreme Being (48,273 reputation)Supreme Being (48,273 reputation)Supreme Being (48,273 reputation)
Posted Sunday January 09 2011
You are right; I am running behind the times again. The TIF mismatch certainly seems like a problem.

-Pete

See also Yahoo group about applying RE.

Posted Monday January 10 2011
This code will allow you to successfully send a MoC order to Interactive Brokers.


PositionSettings posSettings = new PositionSettings();
posSettings.OrderType = OrderType.MarketOnClose;
posSettings.OpenOrder.GoodTillCanceled = false;
OpenPosition(posSettings);
Posted Monday January 10 2011
If I want to use MoC to close a position, how can I do that?
I have been using this code to send MoC for closing positions before:

foreach (Position pos in OpenPositions){
      OrderSettings os = new OrderSettings();
      os.OrderType = OrderType.MarketOnClose;
      os.BarsValid = 5;
      os.Size = pos.CurrentSize;
      if (pos.Type.Equals(PositionType.Long)){
         os.TransactionType = TransactionType.Sell;
      }else{
         os.TransactionType = TransactionType.Cover;
      }
         
      PositionManager.SubmitOrder(pos.ID, os);   
}

Is there any way I can set the GoodTillCanceled flag then using PositionManager.SubmitOrder? Or maybe there is an better way to send MoC orders when you want to Sell/Cover you positions?
Posted Tuesday January 11 2011
When calling SubmitOrder, try setting OrderSettings.BarsValid to something greater than 0. If you're running a daily frequency, you can probably set this to 1. Anything 0 or less will get flagged as GTC.

NNNKT (1/10/2011)
If I want to use MoC to close a position, how can I do that?
I have been using this code to send MoC for closing positions before:

foreach (Position pos in OpenPositions){
      OrderSettings os = new OrderSettings();
      os.OrderType = OrderType.MarketOnClose;
      os.BarsValid = 5;
      os.Size = pos.CurrentSize;
      if (pos.Type.Equals(PositionType.Long)){
         os.TransactionType = TransactionType.Sell;
      }else{
         os.TransactionType = TransactionType.Cover;
      }
         
      PositionManager.SubmitOrder(pos.ID, os);   
}

Is there any way I can set the GoodTillCanceled flag then using PositionManager.SubmitOrder? Or maybe there is an better way to send MoC orders when you want to Sell/Cover you positions?
Posted Tuesday January 11 2011
I'm running my system on 5min bars.
It seems to send GTC order regardless of OrderSettings.BarsValid when using SubmitOrder.
Posted Monday March 30 2015
Hi Daniel,

In my case (on ARCA) it is not valid to use GTC with MOC. So I'll set BarsValid to a small positive number and hope that TIF will be DAY. 

Could you please say what TIF is sent with MOC orders when BarsValid > 0?

thanks



Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems