Bid Ask Spread Visualizer For ThinkOrSwim - useThinkScript Community (2023)

C

CuiJinFu

New member
  • Aug 23, 2021
  • #1

Bid Ask Spread Visualizer For ThinkOrSwim

I've learned the hard way recently that successful daytrading requires careful consideration of the bid/ask spread. Attempting to daytrade or scalp symbols that tend to have large spreads relative to your profit target is a surefire way to lose money. So I pulled together two simple studies that allow visualization of the current and historical spread. The current spread can help inform where to place any tight limit or stop orders, and the historical spread can tell you whether you should even consider trading that particular symbol.

The first study simply plots arrows on the price plot corresponding to the current bid and ask prices. The second generates a lower plot showing the bid/ask spread history at the open for each bar. It's worth noting that the bid and ask prices are sometimes undefined, which can result in either of these studies briefly yielding NaN values that won't display. That will typically happen for a few seconds after a new bar opens.

Hopefully these will be of some use to other traders. Good luck out there!

http://tos.mx/QLRpbxE

Code:

# Plot current bid/ask arrows on price plot# Author: CuiJinFu# Version: 1 12/23/21def lastBar = !IsNaN(close) && IsNaN(close[-1]);plot lastAsk = if lastBar then close(priceType = "ASK") else Double.NaN;lastAsk.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);lastAsk.SetDefaultColor(Color.YELLOW);plot lastBid = if lastBar then close(priceType = "BID") else Double.NaN;lastBid.SetPaintingStrategy(PaintingStrategy.ARROW_UP);lastBid.SetDefaultColor(Color.YELLOW);

Bid Ask Spread Visualizer For ThinkOrSwim - useThinkScript Community (1)

http://tos.mx/zAzTejH

Code:

# Plot bid/ask history on a lower plot# Use open price to avoid repainting# Author: CuiJinFu# Version: 1 12/23/21declare lower;input yellowval = 0.15;input redval = 0.25;plot spread = 100*(open(priceType = "ASK") - open(priceType = "BID"))/open;spread.SetDefaultColor(Color.CYAN);spread.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);plot zeroline = 0;zeroline.SetDefaultColor(Color.GRAY);zeroline.SetStyle(Curve.LONG_DASH);plot yellowline = yellowval;yellowline.SetDefaultColor(Color.YELLOW);yellowline.SetStyle(Curve.LONG_DASH);plot redline = redval;redline.SetDefaultColor(Color.RED);redline.SetStyle(Curve.LONG_DASH);spread.AssignValueColor(if spread > redval then Color.RED else if spread > yellowval then Color.YELLOW else Color.GREEN);

Bid Ask Spread Visualizer For ThinkOrSwim - useThinkScript Community (2)

Last edited by a moderator:

mashume

Well-known member

VIP

Lifetime

  • Sep 10, 2021
  • #2

Though this isn't exactly what you were looking for, it will show you how to get at the bid and ask prices. This is a kind of MACD using close bid and ask prices. you can also change the spread and guide to be plots rather than defs if you want to see what they look like. I don't know if there is much use in this, but here it is.

Code:

declare lower;def bid = CLOSE(priceType = PriceType.BID);def ask = CLOSE(priceType = PriceType.ASK);def spread = simpleMovingAvg(bid, 3) - simpleMovingAvg(ask, 3);def guide = simpleMovingAvg(spread, 12);plot delta = spread - guide; delta.SetPaintingStrategy(PaintingStrategy.HISTOGRAM); delta.AssignValueColor(if delta > 0 then color.green else color.red); delta.SetLineWeight(5);plot zero = 0;zero.setDefaultColor(color.gray) ;

hope that helps you, happy trading
-mashume

Last edited by a moderator:

mashume

Well-known member

VIP

Lifetime

  • Dec 23, 2021
  • #3

CuiJinFu said:

Bid Ask Spread Visualizer For ThinkOrSwim

I've learned the hard way recently that successful daytrading requires careful consideration of the bid/ask spread. Attempting to daytrade or scalp symbols that tend to have large spreads relative to your profit target is a surefire way to lose money. So I pulled together two simple studies that allow visualization of the current and historical spread. The current spread can help inform where to place any tight limit or stop orders, and the historical spread can tell you whether you should even consider trading that particular symbol.

The first study simply plots arrows on the price plot corresponding to the current bid and ask prices. The second generates a lower plot showing the bid/ask spread history at the open for each bar. It's worth noting that the bid and ask prices are sometimes undefined, which can result in either of these studies briefly yielding NaN values that won't display. That will typically happen for a few seconds after a new bar opens.

Hopefully these will be of some use to other traders. Good luck out there!

Awesome stuff!

Last edited by a moderator:

MerryDay

Administrative

Staff member

Staff

VIP

Lifetime

  • Dec 23, 2021
  • #4

CuiJinFu said:

Bid Ask Spread Visualizer For ThinkOrSwim

I've learned the hard way recently that successful daytrading requires careful consideration of the bid/ask spread. Attempting to daytrade or scalp symbols that tend to have large spreads relative to your profit target is a surefire way to lose money. So I pulled together two simple studies that allow visualization of the current and historical spread. The current spread can help inform where to place any tight limit or stop orders, and the historical spread can tell you whether you should even consider trading that particular symbol.

The first study simply plots arrows on the price plot corresponding to the current bid and ask prices. The second generates a lower plot showing the bid/ask spread history at the open for each bar. It's worth noting that the bid and ask prices are sometimes undefined, which can result in either of these studies briefly yielding NaN values that won't display. That will typically happen for a few seconds after a new bar opens.

Hopefully these will be of some use to other traders. Good luck out there!

@CuiJinFu study gives an at-the-glance method to review the Bid-Ask Spread. As such is deserving of its own thread.
To see what other members have done:
https://usethinkscript.com/threads/bid-ask-spread-lines-indicator-for-thinkorswim.1140/

Last edited:

M

MagicQuotes

Member
  • Jul 9, 2022
  • #5

mashume said:

Though this isn't exactly what you were looking for, it will show you how to get at the bid and ask prices. This is a kind of MACD using close bid and ask prices. you can also change the spread and guide to be plots rather than defs if you want to see what they look like. I don't know if there is much use in this, but here it is.

Code:

declare lower;def bid = CLOSE(priceType = PriceType.BID);def ask = CLOSE(priceType = PriceType.ASK);def spread = simpleMovingAvg(bid, 3) - simpleMovingAvg(ask, 3);def guide = simpleMovingAvg(spread, 12);plot delta = spread - guide; delta.SetPaintingStrategy(PaintingStrategy.HISTOGRAM); delta.AssignValueColor(if delta > 0 then color.green else color.red); delta.SetLineWeight(5);plot zero = 0;zero.setDefaultColor(color.gray) ;

hope that helps you, happy trading
-mashume

Great idea, however. FYI, I inverted the color set up. Green should be Red and reversed.
My take is as follows : When a spread is close to zero is indicates either indifference on the part of intraday scalpers, especially with highly volatile index options. As the spread widens between bid and ask, the reality is that the asks hold or elevate asks, while the bids chase. This widens the spread. Anything under accumulation will be starting out near equilibrium in the market flow until the fear of missing out subsides, and which point the buyers are played out and the sellers are then anxious to dump. Playing the extreme spikes from low to high spreads on an intraday chart will show you this. This is the whole basis for noting the number of crosses on the bid/vs ask at different delta levels on the Options Daily Statistics readout page. Best wishes. MagicQuotes.com

M

MagicQuotes

Member
  • Jul 4, 2023
  • #6

Ruby:

#Ask-Bid Spread#altered byMagicQuotes , an occasional visitor that enjoys the nuances and brain scratchers on the GUI's..declare lower;def bid = CLOSE(priceType = PriceType.BID);def ask = CLOSE(priceType = PriceType.ASK);def spread = simpleMovingAvg(ask,3) - simpleMovingAvg(bid, 3);def guide = simpleMovingAvg(spread, 12);plot delta = spread - guide; delta.SetPaintingStrategy(PaintingStrategy.HISTOGRAM); delta.AssignValueColor(if delta > 0 then color.green else color.red); delta.SetLineWeight(5);plot zero = 0; zero.setDefaultColor(color.gray) ;

for what it's worth I have found real time that the following script does synchronize with the Cumulative Tick Delta studies and the actual real time Ticks including the $TIKND available on TOS. Shouts out to
@mashume, @CuiJinFu, and one of my favorite staff member @MerryDay
fyi, I altered the Script by inverting and calling it the Ask-BidSpread Study for my own use. Best to all.

Last edited by a moderator:

You must log in or register to reply here.

Top Articles
Latest Posts
Article information

Author: Duncan Muller

Last Updated: 15/10/2023

Views: 5953

Rating: 4.9 / 5 (59 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Duncan Muller

Birthday: 1997-01-13

Address: Apt. 505 914 Phillip Crossroad, O'Konborough, NV 62411

Phone: +8555305800947

Job: Construction Agent

Hobby: Shopping, Table tennis, Snowboarding, Rafting, Motor sports, Homebrewing, Taxidermy

Introduction: My name is Duncan Muller, I am a enchanting, good, gentle, modern, tasty, nice, elegant person who loves writing and wants to share my knowledge and understanding with you.