I could not find a sample for placing VWAP orders.
I tried the following but get mixed results (i.e. on first click I get an error message in ibc Status, on second click it gets entered as a limit order).
I tried it with and without attributes - to no avail. Attributes were taken from IB's website https://interactivebrokers.github.io/tws-api/ibalgos.html#vwap
Thanks for any help.
function fEntryVWAPtime(ibc, Symbol, shares, Limitprice)
{
fullUntilTimeString = NumToStr(Year(), 4.0, False) + StrFormat("%02.0f", Now(7)) + StrFormat("%02.0f", Now(6)) + " " + "15:54:30 EST";
fullFromTimeString = NumToStr(Year(), 4.0, False) + StrFormat("%02.0f", Now(7)) + StrFormat("%02.0f", Now(6)) + " " + "10:54:30 EST";
VWMaxPctVol = NumToStr(0.2, 1.1);
VWAPAttributes = VWMaxPctVol + ";" +
fullFromTimeString + ";" +
fullUntilTimeString + ";" +
"1" + ";" +
"1" + ";" +
"1" + ";" +
"100000"
;
ibc.placeorder( symbol, "Buy", shares, "VWAP", round(LimitPrice), 0, "Day", true, 100, VWAPAttributes);
}
TriggerOrder= ParamTrigger("Place order","Click");
ibc = GetTradingInterface("IB");
if( TriggerOrder )
{
if( ibc.IsConnected() )
{
Symbol = Name();
shares = 100;
Limitprice = lastvalue(C) - 0.1;
fEntryVWAPTime(ibc, Symbol, shares, Limitprice);
}
}
Please read PlaceOrder documentation carefully and the details to 10th argument "Attributes" of that function:
Attributes - is a string that allows to specify additional order attributes (comma separated list).
Supported attributes:
-
outsideRTH - if specified means that order will trigger not only during Regular Trading Hours (RTH), but also in extended trading (pre/after market); this applies to stop orders, conditional orders, and alerts; it is used by the triggering logic. If not specified (false) orders will trigger ONLY during RTH.
-
allOrNone - fill all or nothing at all
-
eTradeOnly - trade with electronic quotes only
-
firmQuoteOnly - trade with firm quotes only
Version 1.1 ignoreRth / rthOnly flags are OBSOLETE now and not supported as TWS API dropped support for those.
By default all those flags are INACTIVE (OFF)
Example:
ibc.PlaceOrder("MSFT", "BUY", 1000, "LMT", 27, 0, "GTD 20051215 19:00:00 GMT", True, 100, "allOrNone" );
(Note that optional parameter TickSize MUST be specified if you want to use Attributes)
Please pay special attention to specially marked key words "Comma separated" and "Supported attributes" (-> those four ones). So by strictly following help your custom attribute is not supported.
Futher note: IBcontroller is provided "as is" since it is free one.
Another note: IBcontroller source code can be found here.
3 Likes
Unfortunately, the AT documentation does not provide a VWAP order example but states that they are possible. The attributes mentioned are not applicable to VWAP orders according to IB. So, if anyone has a working example, that would be great. Thanks.