In thinkScript, PriceType is a constant that displays selections of price quotations.
Use it with fundamental functions like volume, implied volatility (IV), and open interest.
There are 4 different values that PriceType can retrieve:
- Bid
- Ask
- Last
- Mark
In this post, we’ll go through each PriceType option and show you how to apply them in your thinkScript code.
Bid
The bid defines the highest price someone is willing to pay for the stock.
You can display the bid price of a stock using the following snippet.
plot BidPrice = close(priceType = "BID");
Ask
The ask indicates the lowest price an investor is willing to sell their stock for.
You can display the ask price in thinkScript using this snippet.
plot AskPrice = close(priceType = "ASK");
Last
PriceType.LAST
is the price of the last trade. It’s the equivalent of the current stock price.
Similar to how thinkScript returns the Bid and Ask price, the same can be used to show the stock’s last price.
plot LastPrice = close(priceType = "LAST");
Mark
Think of the Mark price as the estimated fair value based on the bid and ask.
This figure is helpful in futures trading and any other highly volatile market.
plot MarkPrice = close(priceType = "MARK");
PriceType Code Examples in thinkScript
Using any of the code below on the Day or Week aggregation period will not return any value.
Bid-Ask Spread
The bid-ask spread is the difference between the bid and ask prices.
declare lower;
plot spread = close(priceType = PriceType.ASK) - close(priceType = PriceType.BID);
Display Bid/Ask Price as Label
You can display the bid and ask on your chart as two separate labels.
def AskPrice = close(priceType = PriceType.ASK);
def BidPrice = close(priceType = PriceType.BID);
AddLabel(yes, "Ask: " + AskPrice);
AddLabel(yes, "Bid: " + BidPrice);
PriceType Switcher
You can add a user input to PriceType.
input priceType = PriceType.ASK;
plot Data = close(priceType = priceType);
This method lets you quickly switch between Bid, Ask, Last, and Mark without editing the source code.
By default, the script plots the Ask price. However, the “price type” can be changed right from the indicator’s settings.
Happy coding!