• Get $30 off VIP with code SUMMER30. Ends July 27. Happy trading!

Bid-Ask Spread Lines Indicator for ThinkorSwim


New member
This thread has been updated. You can find the code for ThinkorSwim's Bid-Ask Spread Lines down below (post #4)

I tried the above code hoping that it would work on standard stocks in TOS but unfortunately this does not work. I then decided to try my hand at creating my own script (shown below) but can seem to get it to work please can you take a look and advise what Im doing wrong (go easy on my I have just got TOS this month and have been scripting for all of 5 hours :geek:)

What Im trying to do is have the Bid Price (Red) & Ask Price (Blue) on the chart with the area in between grey if possible. Similar to what you see on MT4 when trading Forex.

#Plots Bid/Ask Line with spreads shadow that shows the current value on given Ticker

input pricea = priceType.ASK;
input priceb = priceType.BID;
input offset = 0;
input length = 300;

Plot askp = close(Pricea);
Plot BidP = close(Priceb);


AddCloud(AskP, BidP, color.blue, color.red);

P.S I have Implemented you ORB Script and love it! Cant wait to try it out. Thanks
Last edited by a moderator:


@DojiDude Glad you're getting your hands dirty. There is already an existing bid/ask spreads for stocks. Take a look and see if this is what you're looking for.

declare hide_on_daily;
def spread = close(priceType = PriceType.ASK) - close(priceType = PriceType.BID);
AddLabel(1, "Spread: " + spread );


New member
@BenTen Trying to:cry:. Thanks for the reply. The script only seems to put the Spread in the top left I wanted to add line to the chart like below




@DojiDude Try this:

# Bid / Ask Dynamic Line
# Mobius
# Chatroom 09.20.2013

Input LineLimit = 200;
Input SizeLabels = yes;

def bid = close(priceType = "Bid");
def ask = close(priceType = "Ask");
def barNumber = barNumber();
def Mark = close(priceType = "Mark");
def Last = close(priceType = "Last");
script dynamic{
   Input LineLimit = 200;
   input c = close;
   def bar = if IsNaN(c)
             then bar[1]
             else BarNumber();
   def ThisBar = HighestAll(bar);
   def cLine   = if bar == ThisBar
                 then c
                 else Double.NaN;

  plot P = if ThisBar - LineLimit <= bar
           then HighestAll(cLine)
           else Double.Nan;

plot B = dynamic(linelimit= linelimit,c = bid);
B .SetDefaultColor(Color.green);
B .SetLineWeight(1);

plot A = dynamic(linelimit = linelimit,c = ask);
A .SetDefaultColor(Color.MAGENTA);
A .SetLineWeight(1);
def Dir = if Last == Bid then 1 else 0;
def NotDir = if (Last != Bid) or (Last != Ask) then 1 else 0;
AddCloud(if Dir then A else Double.NaN, if Dir then B else Double.NaN, color.Green, color.Current);
AddCloud(if !Dir then A else Double.NaN,if !Dir then B else Double.NaN, color.Red, color.Current);
AddCloud(if NotDir then A else Double.NaN, B, Color.Gray, Color.Current);
AddLabel(yes, Concat("BID: ", AsDollars(close(priceType = "BID"))), if Dir then Color.GREEN else Color.RED );
AddLabel(yes, Concat("ASK: ", AsDollars(close(priceType = "ASK"))), if Dir then Color.RED else Color.GREEN);
# End Code Bid Ask Lines

Last edited:


New member
Yes that work perfectly! Thanks

Where can I go to learn more about ThinkScript rather than blind guess work? Trying to find the structure rule etc.


New member
Hi BenTen. Can you plot an option debit/credit spread? In other words, how to get bid/ask prices for long leg and short leg?

Brain Monkey

New member
Ok so this is a real simple watch list indicator to help (maybe) give me some idea which strikes get pinned on Options Exp.
  • I start by making a custom watch list with just SPX.
  • Then I run an options scan on my SPX watch list and I filter "Days to Exp" to capture just those options that pertain to the up coming Options Exp.
  • I then add columns for price, volume, open interest and this custom column. (I know this makes A LOT of assumptions about whether the volume is net short or long plus a bazillion other things)
  • Then I click on the columns to get a sense of what is being most heavily traded, what has the most open interest and which delta's the market makers have to hedge in order to remain market neutral.
def Pain = ((bid + ask)/2) *  volume;
plot R = Pain/1000;

My question is: I want to make an "if then" statement that takes all my NaN results and makes them zero, so that when I click on my Custom Pain column, all the highest results go to the top and all the NaN's go to the bottom. I hope this makes sense. Also if anyone else has a better approach, I would love to see. Thank you.
Last edited:


New member
Hi, I am pretty new to the forum and so far really enjoying all the learning, thank you.
I have a question about an indicator but really not sure how to articulate it though...
I am trying to find an indicator (if it even exists)that will paint an arrow in the direction of the live candle on most timeframes.
The metric behind these arrows is something I am struggling with. I imagine it might be based on volume, orders, bid vs ask?
In my mind the arrow appears once a certain "level" has been reached and if that level continues to increase the colour might change accordingly.
The arrow will only appear when there is definite movement in a certain direction.
Thank you in advance for any advice here...


New member
new here
was wondering if the spread lines indicator was working for anyone else?
I cant seem to get it to work on the /ym ?


New member
hi all...…..benten I guess this question would be for you. great job on the indicators man..are you a wizard hahhahhahah
anyways. I cant seem to get the lines to plot on the bid/ask spread that you have come up with...is anyone else having trouble with that or is it just me...… probly . i put it on the /ym 1 min chart that should work right? thanks for the room its great.


New member
Hi there,

New member here. I want to create a study filter based on the bid-ask spread. Do you know why the following study filter returns no stocks ? I have almost all timeframe periods but it does not work.

def b = close( priceType = PriceType.BID);
def a = close( priceType = PriceType.ASK);

plot s = (a-b) > 0;


New member
@BenTen This is exactly what I was looking for. Thank you. Changed first value to 10 so it only extends into the future. Love the values at the top showing Bid/Ask. Do you know what value I can add to show the percentage difference between Bid/Ask and the $ difference? (% = -) ($ + -)


New member
Earlier today I put a question to the thinkScript lounge in TOS and quickly learned that I may not quite have things straight. I got it into my head that thinkScript might have access to Level 2 data, a notion of which I was quickly disabused.

This all began when I noticed that PriceType.ASK could be used as an argument in both the fundamental open() function and close(), e.g.,

plot AskOpen = open(priceType = PriceType.ASK);
plot AskClose = close(priceType = PriceType.ASK);

This led me to the idea that 'within' a candle there are almost certainly many orders occurring, each realized when an ask price was satisfied by a bid price. From this it followed that there must be multiple 'ask' prices inside a candle, and that TS gives us access to the ask at candle open and and candle close.

But according the folks in the lounge, I'm wrong about this. Nonetheless, these two lines are different.

What value, then, does open return when given argument PriceType.ASK and what does close return with the same argument?

Thanks for your help in reducing my confusion!


New member
@DojiDude Glad you're getting your hands dirty. There is already an existing bid/ask spreads for stocks. Take a look and see if this is what you're looking for.

declare hide_on_daily;
def spread = close(priceType = PriceType.ASK) - close(priceType = PriceType.BID);
AddLabel(1, "Spread: " + spread );
Thanks for this BenTen. Very surprised TOS doesn't have a out-of-the-box Spread indicator. Your code puts a block in the upper left corner of a chart and is very usable, but I notice it can not be added as a column in a watchlist which is where I'd really like it. Would be nice to know if a spread is outrageous before I even click on the chart.
How hard would it be to add to the code to make it available as a column in a watchlist. Or maybe be able to change the color of the box that currently displays. It's a bright red as of now. Be nice to tone it down a bit.
Thanks in advance for any help you may be able to provide.


New member
Great work, I have added below code to your script to show spread value at the left corner and its color changes based on spread value.
If Spread is <=.05 then GREEN
If Spread is between .06 and .15 then YELLOW

def spread = close(priceType = PriceType.ASK) - close(priceType = PriceType.BID);
def spread_l1 = 0.05;
def spread_l2 = 0.15;
AddLabel(1, "Spread: " + spread, if spread <= spread_l1 then Color.GREEN else if spread_l1 < spread <= spread_l2 then Color.YELLOW else COLOR.RED);

Similar threads