Hi everybody, I would need help for coding an option strategy. I would want to create a strategy that, when a specific condition is satisfied, buy a call with at least 7 day to expiration with a strike price that is x% below the underlying previous close.
I tried using CreateSyntheticOption with poor results...
Thanks
Size:
Color:
Size:
Color:
Thank you Eugene, actually very high quality code example even if not easy for my poor coding skills...
Trying to create a call option with at least 7 days to exp and with a strike price 3% below previos close:
CODE:
Please log in to see this code.
I get the error message CS1502: The best overloaded method match for WealthLab.WealthScript.CreateSyntheticOption(int,int,int,bool) has some invalid arguments
I realized that the third argument (0.97*Close[bar]) is the problem. In addition could you please explain me the meaning of the first argument (DateTime startDate)?
Thank you
Size:
Color:
QUOTE:
I realized that the third argument (0.97*Close[bar]) is the problem.
No, it's more than this argument. As you could see in the QuickRef,
CreateSyntheticOption can be called like this:
CODE:
Please log in to see this code.
You're trying to mix both worlds which won't work out. There is no way to have both
atLeastXDaysTilExpiration and
strikePrice because it's not programmed to be used like that.
For backtesting, the correct way would be to use some extra methods like
DateTimeToBar and
NextOptionExpiryDate and some functions available only in Community Components:
CODE:
Please log in to see this code.
So for backtesting this should suffice:
CODE:
Please log in to see this code.
Problem is, you cannot use this for live trading because
NextOptionExpiryDate returns -1 for dates beyond the right edge. If you're willing to drop the "strike price 3% below previous close" requirement, your task becomes very simple -- just use the overloaded call:
CODE:
Please log in to see this code.
Size:
Color:
Great! Thank you very much Eurgene! I have a lot of test to do now ;)
Size:
Color: