using TradeLink.API;
using TradeLink.Common;
using System.ComponentModel;
public class FlatClose : ResponseTemplate
{
PositionTracker _pt = new PositionTracker();
List<string> _syms = new List<string>();
override void GotPosition(Position p)
{
_pt.Adjust(p);
_syms.Add(p.Symbol);
sendbasket(_syms.ToArray());
}
override void GotFill(Trade fill) { _pt.Adjust(fill); }
int SHUTTIME = 155000;
[Description("shut down at this time")]
public int ShutTime { get { return SHUTTIME; } set { SHUTTIME = value; } }
override void GotTick(Tick k)
{
if (!isValid) return;
if (k.time>ShutTime)
{
isValid = false;
foreach (Position p in _pt)
sendorder(new MarketOrderFlat(p));
D("auto shutdown");
}
}
public FlatClose()
{
// prompt user to change shutdown time when response started
ParamPrompt.Popup(this);
}
}
On the Order menu in TWS there is a "Close All Positions" item which I believe should allow you to close everything manually with just a few clicks. Or you could assign it to a hotkey(?). I've never used it however...Quote from CPTrader:
Does IB's TWS have a feature that allows you to go flat at the end of day with one click in all markets (futures, stocks, forex, etc)?
Thx