Bid Ask Spread Visualizer For ThinkOrSwim

CuiJinFu

New member
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/21

def 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);

aSG7VWW.jpg



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/21

declare 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);

8rnrEvF.jpg
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

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:
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:
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:
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
 
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:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
398 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top