Plotting current price of option straddle

Hi
I want to plot current price of option straddle.
current price is defined as latest close price of call-option + latest close price of put-option (at same-strike and same-expiry date)

I use InteractiveBrokers plugin. The database has base time interval of 1 minute.

The option symbols are of the form
BANKNIFTY-YY-M-DD--CE-NSE-OPT-INR (for call option)
BANKNIFTY-YY-M-DD--PE-NSE-OPT-INR (for put option)

To plot current price of option straddle, I do the following:

  1. determine name of other symbol of the straddle pair. This is done by changing CE to PE (and vice-versa) to current symbol name
  2. Get the close price of other symbol of straddle pair using Foreign function
  3. Add the close-price-foreign-symbol to close price of current symbol.

This works well historical data.

However, for the straddle price for the current minute, I notice the following:
Close price for current symbol is continuously updated, however the close price for the other symbol of pair, is not continuously updated.

Is there some way to get continuously updated close price of Foreign symbol as well? This will get in plotting more accurate current price of straddle.

#include <opt_utils.afl>

_SECTION_BEGIN("Straddle");

sym = Name();
peer_sym = get_pair_name(sym);
peer_close = Foreign(peer_sym, "C");
straddle_price = Close + peer_close;

_N(Title = StrFormat("%s - straddle %g, close %g, peer %g", sym, straddle_price, Close, peer_close));
Plot(straddle_price, "straddle price", ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 

_SECTION_END();

I haven't tried the IB plugin but IB is very closely tied to AB.

For other local vendors, users have reported Foreign() calls not updating.

Follow-up question for Tomasz is if GetQuotesEx() is called for Foreign() calls.
I am referring to your post below in the same topic because for now I assume GetQuotesEx() is called and it could be a plugin issue.

GetQuotesEx is called for all symbols that were accessed in ANY way. I already explained it many times. This includes Foreign(). Everything is updated as data source sends updates. If you want to make sure that chart updates occur immediately go to Tools->Preferences, "Intraday" and make sure that "Realtime chart refresh interval" is set to 0. (requires professional license)

1 Like

In AB, we trust :smiley:

@abisht
You can add the symbol to RT quote window and see if it's ticking there.

I wasn't able to check in the morning but there is no problem with Foreign(), ensure that settings mentioned above are properly set.

Hi Tomasz
Thanks for the quick response. I will update the setting and verify it tomorrow (when the market opens).

Hi @nsm51
the ticks were coming properly / continuously when the two symbols were added to RT quote window. It is only in charts that I was having the issue.

If everything is right, the ib plugin should update all data irrespective of foreign call or other chart requesting that data or not (provided the symbol is there in the master)

But I am not sure if the ib data plugin will pass this test.

Like from my first post, IMHO, IB plugin is developed by AB instead of the vendor.
Thats why it should be the gold standard.

As I wrote - symbols referenced by Foreign as updated as well.

Hi Tomasz
I changed the "Realtime chart refresh interval" to 0 . It was set to 1 earlier.
I am still facing the same issue.

Please find a screen recording for the same.
The realtime window shows the realtime data coming for both PE and CE.
In the chart however, only CE value is changing continuously. The PE value is not changing. It changed only once (in the recording), when the minute changed.

Here is link to youtube recording

peer_close is visible in Title string, but while debugging(generally), why don't you plot all 3 separately?
that way, its easier for viewing, isn't it?
plots of sym, pair and foreign_symbol

You need to understand how charting works. The formula that chart uses is executed WHEN currently selected symbol data changes. Changes on symbol referenced by Foreign DO NOT cause formula execution UNLESS selected symbol data changes too.
The SELECTED SYMBOL is the only driver for chart refreshes.
If you want refreshes that happen EVEN IF current symbol does NOT receive any new data, you have to request timed refreshes AFL Function Reference - REQUESTTIMEDREFRESH

Hi Tomasz
The Close for the selected symbol (CE in the video) is changing every second (or so). This updated value can be seen in the title (and it can be confirmed in the RT window as well).

The close value of the foreign symbol is also changing (as seen in the RT window). The value for foreign symbol is however not updated in chart (as seen the chart title).
During the recording, the value for foreign symbol changed only once when the minute changed.

Something is not right, but why don't you record like this and show along with RT Quote window

Plot( straddle_price, "straddle price", ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
Plot( C, "C", colorYellow, styleLine ); 
Plot( peer_close, "peer", colorBlue, styleLine ); 

_N(Title = StrFormat("%s - straddle %g, close %g, peer %g", sym, straddle_price, Close, peer_close) );

Additionally, as much info as you can which is missing in your opening post. IB plugin version, AB version etc. It helps the others who cant see your machine

Hi @nsm51, @Tomasz
Here is another video where the other two plots are added to the chart.

In the video, the minute changed after ~6 seconds. One can see the change in the foreign symbol value at that time. Also, the value does match value in RT window at that time.

Other details are:

  1. Amibroker - Version: 6.40.4 - Professional Edition (64-bit)
  2. IB data plugin - Version: 2.11.0 (API: 2)

Just try other symbols like active US stocks like SPY

Hi @Tomasz
Changed to testing procedure to use MSFT as selected symbol and AAPL as foreign symbol.
I am still facing the same issue.

Here is the link to video

here is the code

_SECTION_BEGIN("Foreign Test");

sym = Name();
peer_sym = "AAPL";
peer_close = Foreign(peer_sym, "C");

_N(Title = StrFormat("%s : %s - close %g : peer %g", sym, peer_sym, Close, peer_close));

Plot(C, "Close", colorYellow, styleLine);
Plot(peer_close, "Peer Close", colorRed, styleLine); 

_SECTION_END();

So, I finally updated to windows11 and with that I also did a new install of Amibroker in user/home directory.

I am happy to share that the real-time update of Foreign symbol is working in this setup. I am not sure what was the issue in older setup. Here is a video of the real-time update of symbol and its peer (foreign symbol)..