How to get a correct ExpiryDate out of Bars range
Author: DamV
Creation Date: 3/6/2017 3:45 AM
profile picture

DamV

#1
I tried to use NextOptionExpiryDate but this function is not able to provide the correct expiry date if you are over the last bar. It will only provide the next expiry date after the last bar but not later.

For example, I need the expiry date 2 months after the last bar

CODE:
Please log in to see this code.


Thx.


profile picture

Eugene

#2
Sounds like good defensive programming in NextOptionExpiryDate. Bars.Count+59 is garbage input that can only lead to an IndexOutOfRange exception. With NextOptionExpiryDate you cannot go beyond Bars.Count-1. However, NextOptionExpiryDate accepts arbitrary dates (which isn't currently documented in the QuickRef - I'll fix this):

CODE:
Please log in to see this code.


What do you think you need it for?
profile picture

DamV

#3
It works. You rock the boat! Exactly what I need.
profile picture

Eugene

#4
Glad to help!