Bid Ask Spread in Chart Label


Category:
0
0

Hello Pete,

I wanted to know if you could create or show how to create a chart label called “Spread”, that takes the difference between the ASK and the BID and posts in on the chart as a label. I wonder if the chart timeframe will interfere with this, I hope not.

 

Best

 

Best

Marked as spam
Posted by (Questions: 22, Answers: 63)
Asked on November 19, 2018 4:20 am
2014 views
0

The last condition, if the spread is over 9 cent, show the label as red.

Best

( at November 19, 2018 4:21 am)
0
Private answer

I had to change your question title. The one you entered was too easily mistaken to mean “option spread” rather than “bid ask spread”. We want to make sure folks find what they are looking for.

For those wanting to learn how to figure this stuff out on their own. Two links to the Thinkorswim language reference will explain everything you need.

http://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Fundamentals/close.html

http://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Look—Feel/AddLabel.html

Here is the code. Just remove lines you don’t want to display on the chart.

input limit = 0.09;
def priceB = close(priceType = PriceType.BID);
def priceA = close(priceType = PriceType.ASK);
AddLabel(yes, Concat("Bid: ", priceB), Color.WHITE);
AddLabel(yes, Concat("Ask: ", priceA), Color.WHITE);
AddLabel(yes, Concat("Spread: ", priceA - priceB), if priceA - priceB > limit then Color.RED else Color.WHITE);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on November 19, 2018 9:15 am
0

Works like a charm, thank you.
My only question is does Thinkscript allow you to place the labels in the center of the screen by any chance?

( at November 19, 2018 9:41 am)
0

There is no control over its position. You can hack it though. Just add labels that match your chart background color before the ones you want displayed. The labels display from left to right in the order they appear in the code.

( at November 19, 2018 10:14 am)