Closing order based on %Profit, DTE, and days elapsed


New member
I would like to use a script to create a closing order for an option based on the %P/L relative to the number of days that the trade has been open and the original DTE when the trade was placed. The function would go something like this:

Percent Profit * Initial DTE / Days Elapsed = X
Execute order if condition X >= Y, where Y is some arbitrary value set by the user.

I am an absolute newbie at ThinkScript and have basic knowledge of scripting in general. As I was looking through some of the documentation in the Learning Center, I couldn't figure out which Date and Time functions would allow me to accomplish this. Any suggestions or guidance is greatly appreciated.


@USTSMike I figured. But what I'm asking here is if you're going to use options as part of your backtesting script? If so, that would not be possible because ToS does not support option orders for their backtesting script.


New member
Looks like I won't be backtesting then 😣. However, I am still curious to know if you are able to define a static variable as the number of days until expiration on the day that the trade was placed and another variable that counts upward as time passes from that same date. Any ideas?

Similar threads