Options traded at or above ask price


Category:
0
0

Hi Pete,

 

Thank you very much for all the great stuff. Really appreciate it.

 

I want to create a scan for option contracts traded at or above Ask price on TOS, came up with the code like this:

PriceType.LAST is greater than or equals to PriceType.ASK,

but it doesn’t work. Please help.

 

TIA

Attachments:
Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on May 14, 2021 4:44 pm
367 views
0
Private answer

Based on the context of your request, I moved this post out of the "Frequently Asked Questions" topic and into the "Stock Scanners" topic.

Two details I need to clarify:

  1. When writing custom solutions in Thinkscript, the current price (or most recently traded price) is always read using "close" and not by trying to read "PriceType.LAST". In fact for most places on the Thinkorswim platform the call to "Last" as a price will fail. Always use "close".
  2. In practice, it should be 100% impossible for a trade to execute above the Ask price. To understand this, it's best to view the trading D.O.M. in the active trader screen of Thinkorswim. Screenshot below shows why this should be theoretically impossible, given a health and normally functioning market.

Notice that there are several layers of orders in the ASK column. (this is valid for options, futures and stocks as all markets function exactly the same). It is not possible to execute an order above the lowest ASK price in that column. All prices must always execute at the ASK (for buy orders) or at the BID (for sell orders). Trying to scan for any instrument that trades above the ASK or below the BID is not congruent with the way healthy markets function.

From the items you marked on your attached screenshot it seems you are not correctly interpreting the data that is displayed in that table. I suggest you contact the trade desk at TD Ameritrade to gain a clearly understanding of what that table displays. If I have made any statements that were not 100% correct, please report back in the comments section by providing the response you receive from TD Ameritrade.

Edit: Based on further clarification from the author of the post I have additional information to add to my solution.

The request has been clarified to: "the code to scan the trades that happened at ask"

First I must say that this is completely impossible to do on Thinkorswim. This platform does not provide the granularity to run a scan at a "per trade" level. The best we can do is to base the scan on every trade that has occurred in the most recent 1 minute. (which requires the Study Filter of the scan be set to 1 minute). As I understand the true question no, I can say this is absolutely impossible to build on the current version of Thinkorswim.

Now that I have cleared that up. I can offer some troubleshooting advice. The author of the post has been writing various sections of code and is not able to get any results. The first thing we must understand is exactly how does Thinkorswim get the "ASK" price? We use one of the built-in fundamental data arrays, such as "open, high, low or close". Then we apply the PriceType constant of "PriceType.ASK". Details here:

https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/PriceType/PriceType-ASK

Using the example given in the link above, we can test the scan engine of Thinkorswim to be sure it is even able to use this data point when we invoke it in our script. The following are three sets of scripts we can use to run some tests:

def data = open("priceType" = PriceType.ASK);
plot scan = data is less than 0;

def data = open("priceType" = PriceType.ASK);
plot scan = data is greater than 0;

def data = open("priceType" = PriceType.ASK);
plot scan = !IsNaN(data);

The first one runs a scan that checks of the opening ask price of the most recent candle is less than zero. Run this scan and it returns zero results. But we might expect the scan would not find any options with a value below zero, so lets make we check every possible value...

The second one runs the same scan but checks if that opening ask price is greater than zero. Run that scan and you get no results.

The third and final section of code checks if the opening ask of the most recent candle is any number at all. Again we get zero results.

From this, we can confirm it is not possible to write any code for a custom scan that tries to reference the opening ask price of a candle. I'll let the viewers run this test for the other price types. For me this is enough proof that Thinkorswim developers have either intentionally or mistakenly prevented this feature from working in a custom scan of any kind.

Anyone who might feel this is a bug or needs to be corrected should consider submitting this as a feature request or a bug report to TD Ameritrade support.

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4086)
Answered on May 14, 2021 5:15 pm
0
Thanks, will contact them next week. Have a good weekend.
( at May 14, 2021 5:46 pm)
0
I have been digesting what you said, I'm sorry if I misled you. The point is not if an option contract can be traded above ask or not, let's just forget it for now. The question was, what's the code to scan the trades that happened at ask. Tried close equal to PriceType.Ask But didn't work. How to solve this problem? Thanks
( at May 14, 2021 7:01 pm)
0
Interestingly, I wrote this plot scan = close is greater than or equal to high; It works, but not this plot scan = close is greater than or equal to ask; Don't understand why Cheers
( at May 14, 2021 8:16 pm)
0
It is very important that your question title is accurate. The rest of our viewers are counting on that title correctly expressing the context of the request. I may change this in the future but it will break the URL, which is something that really does not provide the best user experience. I have updated my solution to include a complete explanation as to why this is not possible to complete in the current version of Thinkorswim.
( at May 14, 2021 8:59 pm)