| Overall Statistics |
|
Total Trades 2 Average Win 0% Average Loss 0% Compounding Annual Return 1.674% Drawdown 0.500% Expectancy 0 Net Profit 1.557% Sharpe Ratio 1.406 Probabilistic Sharpe Ratio 67.414% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0.008 Annual Variance 0 Information Ratio 1.406 Tracking Error 0.008 Treynor Ratio 0 Total Fees $2.00 Estimated Strategy Capacity $2600000.00 Lowest Capacity Asset SPY R735QTJ8XC9X |
namespace QuantConnect.Algorithm.CSharp
{
public class InteractiveBrokersBrokerageExampleAlgorithm : QCAlgorithm
{
private Symbol _symbol;
public override void Initialize()
{
SetStartDate(2021, 1, 1);
SetCash(100000);
SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin);
_symbol = AddEquity("SPY", Resolution.Minute, extendedMarketHours: true).Symbol;
// Set default order properties
DefaultOrderProperties = new InteractiveBrokersOrderProperties
{
Account = "TestAccount1", // Only for FA accounts
FaProfile = "TestProfile1", // Only for FA accounts
FaGroup = "TestGroup1", // Only for FA accounts
FaMethod = "EqualQuantity", // Only for FA accounts
TimeInForce = TimeInForce.GoodTilCanceled,
OutsideRegularTradingHours = false
};
}
public override void OnData(Slice data)
{
if (Portfolio.Invested)
{
return;
}
// Place an order with the default order properties
LimitOrder(_symbol, 10, data[_symbol].Price + 10);
// Place an order and with new order properties
var orderProperties = new InteractiveBrokersOrderProperties
{
Account = "TestAccount2", // Only for FA accounts
FaProfile = "TestProfile2", // Only for FA accounts
FaGroup = "TestGroup2", // Only for FA accounts
FaMethod = "NetLiq", // Only for FA accounts
OutsideRegularTradingHours = true
};
var ticket = LimitOrder(_symbol, 10, Math.Round(data[_symbol].Price * 0.9m, 2), orderProperties: orderProperties);
// Update the order
var updateFields = new UpdateOrderFields {
Quantity = 8,
LimitPrice = Math.Round(data[_symbol].Price + 10, 2),
Tag = "Informative order tag"
};
var response = ticket.Update(updateFields);
if (!LiveMode && response.IsSuccess)
{
Debug("Order updated successfully");
}
}
}
}