Strategy Sending ! prefix for the option contract. and getting "Could not find contract for symbol" error from IBKR. Contract - !QQQ250221C525
Manual order no issues using QQQ250221C525(Without ! prefix).
How Can I get rid of the prefix(!) . Thanks in advance.
Manual order no issues using QQQ250221C525(Without ! prefix).
How Can I get rid of the prefix(!) . Thanks in advance.
Rename
1. Use IBHistorical.Instance.GetOptionsSymbol() to get the symbol from the option chain instead of OptionSynthetic.GetOptionsSymbol().
2. If you can't use the option chain because you're backtesting with expired contracts (not the case here), you can turn the expired synthetic contract symbol into the IB-formatted symbol like this -
2. If you can't use the option chain because you're backtesting with expired contracts (not the case here), you can turn the expired synthetic contract symbol into the IB-formatted symbol like this -
CODE:
string synSymbol = OptionSynthetic.GetOptionsSymbol(bars, OptionType.Call, bars.LastValue, DateTime.Now); WriteToDebugLog(synSymbol); // return a string after the first character string osym = synSymbol.Substring(1); WriteToDebugLog(osym); //or with OptionsHelper. The "1" in ConvertSymbol is for IB format string osym2 = OptionsHelper.ConvertSymbol(synSymbol, 1); WriteToDebugLog(osym2);
Thanks Cone,
using IBHistorical.Instance.GetOptionsSymbol getting correct symbol(QQQ250221C525).
Next step, to get the option bars.
_obars are returning !QQQ250221C525
using IBHistorical.Instance.GetOptionsSymbol getting correct symbol(QQQ250221C525).
Next step, to get the option bars.
CODE:
//get the option bars _obars = OptionSynthetic.GetHistory(bars, osym, 0.4);
_obars are returning !QQQ250221C525
Sure, you're calling OptionSynthetic. For live option data, use GetHistory like for any other symbol.
See the User Guide (F1) > Extensions > Interactive Brokers > Options. There's a TON of information with examples.
Also see the Options blog for even more information with examples for IBHistorical -
https://www.wealth-lab.com/blog/backtest-auto-trade-options
The thing I'll stress here is that IB returns INTRADAY bars only for options. If you need Daily bars, then you need to compress it. Here's another example.
See the User Guide (F1) > Extensions > Interactive Brokers > Options. There's a TON of information with examples.
Also see the Options blog for even more information with examples for IBHistorical -
https://www.wealth-lab.com/blog/backtest-auto-trade-options
The thing I'll stress here is that IB returns INTRADAY bars only for options. If you need Daily bars, then you need to compress it. Here's another example.
CODE:
using System; using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; using WealthLab.InteractiveBrokers; namespace WealthScript21 { public class MyStrategy : UserStrategyBase { BarHistory _obars; public override void Initialize(BarHistory bars) { string osym = IBHistorical.Instance.GetOptionsSymbol(bars, OptionType.Call, bars.LastValue, bars.EndDate, 5); if (bars.Scale.IsIntraday) { _obars = GetHistory(bars, osym); } else { // Daily+ , get all the 30min option data from IB _obars = GetHistoryUnsynched(osym, HistoryScale.Minute30); if (_obars != null) { // compress and sync to scale _obars = BarHistoryCompressor.ToDaily(_obars); _obars = BarHistorySynchronizer.Synchronize(_obars, bars); } } PlotBarHistory(_obars, osym, WLColor.NeonFuschia); } public override void Execute(BarHistory bars, int idx) { // use _obars } } }
Your Response
Post
Edit Post
Login is required